New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
A flag to add the buildroot to protoc's import path. #4122
Conversation
This allows use of Pants in repos adhering to the protobuf documentation's recommendation of importing from the buildroot, rather than from the proto source root (e.g., src/proto).
Note that this is separate from the source roots change. That change was occasioned by my noticing, in the course of poking at this proto import problem, that we don't support the buildroot being a source root. However that is merely an aesthetic/completeness fix. It doesn't actually solve this problem: the buildroot is likely not the "source root" (whatever that means for .proto files), but we still need to be able to import relative to it. Hence this change. |
['gen.protoc', '--import-from-root', | ||
'testprojects/src/protobuf/org/pantsbuild/testproject/import_from_buildroot/bar']) | ||
self.assert_success(pants_run) | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Could you add a test that asserts that if there's a import for a proto file that is not owned by one of a target's dependencies that it fails? I didn't see one of those when I looked.
Maybe we can't ensure that right now, because of how source_roots work with targets.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It wouldn't fail in that case, as far as I can tell. And even before, you were free to import any proto file in any source root that was in your other dependencies' bases
(or your own), even if you didn't depend on it.
This is true in all codegen, I think, and in many other tasks. But I'd rather we put energy into moving in the other direction - namely implying dependencies when we can instead of requiring them to be explicit... :)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I see what you mean. We've run into the source root import 'feature' a few times too. Another approach to resolving it is working towards isolation based on the build graph. That also won't require specific per task error handling, which is good.
I just get a bit nervous when I see a test suite that doesn't have any tests for failure / error cases.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Agreed, the isolation should come from the engine. Does the new engine admit anything like it easily?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think it could. The snapshot execution work was a proof of concept for this.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks good to me.
register('--import-from-root', type=bool, advanced=True, | ||
help='If set, add the buildroot to the path protoc searches for imports. ' | ||
'This facilitates import paths in .proto files that are relative to the ' | ||
'build root, as recommended by the protoc documentation.') |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The second sentence feels a little awkward, maybe something like
This enables using import paths relative to the build root in .proto files, as recommended by the protoc documentation.
would be better
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That does scan better. Changed.
Thanks for the review! |
A flag to add the buildroot to protoc's import path.
This allows use of Pants in repos adhering to the protobuf
documentation's recommendation of importing relative to the buildroot,
rather than relative to the .proto file's source root (e.g., src/proto).