buf icon indicating copy to clipboard operation
buf copied to clipboard

Split imports for directory strategy in buf generate

Open oliversun9 opened this issue 1 year ago • 2 comments

This is still WIP, but it seems to work with the base case.

Fixes https://github.com/bufbuild/buf/issues/3056, the problem where only non-imports are split by directory in buf generate. The original issue has a great description and repro.

Note, this cannot be achieved by simply removing the import check here, because the split images will conflate IsImport with whether we want to generate a file if permitted by include-imports. The latter is introduced to a new type ImageFileForGeneration.

TODOs:

  • [ ] add more detailed tests
  • [x] cleanup the code
  • [ ] there are still places (*_test.go and .../alpha/protoc/plugin.go) that call ImageByDir, they should stop calling it.
  • [ ] Now their are functions that call ImageByDir (the current implementation) and those that call ImageByDirSplitImports, perhaps we can completely get rid of ImageByDir.
  • [ ] Perhaps move bufimagegenerate into bufgen

This also refactors some generation-specific functions/types into a new bufimagegnerate package, lots of moving around. I will add comments indicating which changes are new code and which ones are relocation.

oliversun9 avatar Aug 01 '24 00:08 oliversun9

The latest Buf updates on your PR. Results from workflow Buf CI / buf (pull_request).

BuildFormatLintBreakingUpdated (UTC)
✅ passed✅ passed✅ passed✅ passedAug 21, 2024, 5:54 PM

github-actions[bot] avatar Aug 01 '24 00:08 github-actions[bot]

@doriable didn't I have a partial PR for this? Is this using that?

bufdev avatar Aug 01 '24 20:08 bufdev

Should we close this now?

bufdev avatar Sep 23 '25 21:09 bufdev

Yes, chatted with @doriable, we can close this one now.

oliversun9 avatar Oct 09 '25 17:10 oliversun9