Preserve is_import for imports whose path matches a path filter#4501
Preserve is_import for imports whose path matches a path filter#4501CGA1123 wants to merge 2 commits intobufbuild:mainfrom
is_import for imports whose path matches a path filter#4501Conversation
ImageWithOnlyPaths and ImageWithOnlyPathsAllowNotExist were clobbering a file's is_import=true flag whenever its path happened to match one of the filter entries, reclassifying it as a target in the output. Transitive imports of actual targets are still pulled in by addFileWithImports via FileDescriptorProto.GetDependency(), so files that are imports of matched targets continue to appear in the filtered image (flagged as imports), and --include-imports behaviour is unchanged.
"google/protobuf/*" files are imports from the googleapis module, not sourced from it, update the tests to reflect this.
doriable
left a comment
There was a problem hiding this comment.
So, I believe the current code path is intended behaviour, in that it specifically clobbers that flag for inputs that did not come from a workspace, in order to treat all paths from the --path flag as targets.
That being said, I understand the reasoning behind this PR, in that now there's a gap between the module's understanding of "what is an import" vs. the image compiled. And I think to address this gap, we would need to do a broader clean-up.
If you don't mind sharing, is there a specific problem you are targeting with this PR?
Of course! I noticed a diff when generating some protos across We generally use |
|
thank you for providing such quick feedback! sorry, just a couple of follow-up/clarifying questions, since i want to make sure i have the correct full picture the ascertain where the bug is coming from ^^" the workflow makes sense to me, using a cached image instead of the i wanted to double check the config being used. stepping back slightly, the premise of all of this is basically, for each path that is passed either through the so it sounds like the cached image includes module dependencies that may have an overlap in the path filter, and so this happens, whereas in the case of building the workspace, the dependencies would be resolved after the workspace build, and so they are excluded by the same path filter... but this is the point i want to verify. and the issue lies with the fact that the semantics of the image input are inherently different from the semantics of the workspace input when it comes to target paths:
so i think, unfortunately, the solution here is actually that when using the |
Yes. I would agree with this (at least from my brief understanding of the underlying logic around images & resolution).
Yeah, I can see that both interpretations can be seen as the path of least-surprise, dependent on what someone is trying to achieve with this combination of option -- not quite straight forward 😄
If it's useful, I've pushed up https://github.com/CGA1123/buf-gen-paths with a The same can be seen via $ buf --version
1.68.4
$ git clone https://github.com/CGA1123/buf-gen-paths && cd buf-gen-paths
$ buf ls-files . --path google/protobuf
google/protobuf/local.proto
$ buf build -o image.binpb
$ buf ls-files image.binpb --path google/protobuf
google/protobuf/local.proto
google/protobuf/timestamp.proto |
|
the repro is definitely helpful (lol, i get that it's a little bit contrived to use the WKTs path, but as long as this is representative of your setup, that's fine), and i think it validates my understanding of what is going on.
and unfortunately, to my point on the different semantics of image + workspace, this does result in a change like this being a breaking change against these semantics. and so i think, to address your use-case, i would do one of the following:
i tried both out in your repro and they both yielded the desired result:
|
|
That makes sense! Appreciate the clarification 🙇♂️ |
ImageWithOnlyPathsandImageWithOnlyPathsAllowNotExistwere clobbering a file'sis_import=trueflag whenever its path happened to match one of the filter entries, reclassifying it as a target in the output.Transitive imports of actual targets are still pulled in by addFileWithImports via FileDescriptorProto.GetDependency(), so files that are imports of matched targets continue to appear in the filtered image (flagged as imports), and --include-imports behaviour is unchanged.