Skip to content
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

Merged
merged 3 commits into from Dec 7, 2016

Conversation

benjyw
Copy link
Sponsor Contributor

@benjyw benjyw commented Dec 6, 2016

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).

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).
@benjyw
Copy link
Sponsor Contributor Author

benjyw commented Dec 6, 2016

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)

Copy link
Contributor

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.

Copy link
Sponsor Contributor Author

@benjyw benjyw Dec 6, 2016

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... :)

Copy link
Contributor

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.

Copy link
Sponsor Contributor Author

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?

Copy link
Contributor

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.

@benjyw benjyw changed the title [wip] A flag to add the buildroot to protoc's import path. A flag to add the buildroot to protoc's import path. Dec 6, 2016
Copy link
Contributor

@baroquebobcat baroquebobcat left a 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.')
Copy link
Contributor

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

Copy link
Sponsor Contributor Author

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.

@benjyw benjyw merged commit 06918be into pantsbuild:master Dec 7, 2016
@benjyw benjyw deleted the import_proto_from_root branch December 7, 2016 22:31
@benjyw
Copy link
Sponsor Contributor Author

benjyw commented Dec 7, 2016

Thanks for the review!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants