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

hack for proto in case of many-repo with relative package #628

Closed
wants to merge 7 commits into from

Conversation

natansil
Copy link
Contributor

@natansil natansil commented Oct 16, 2018

This hack solves an issue with proto_library target depending on proto_library from external repo.
scalapb_proto_library failed to find the proto from the external repo.

This hack can be reverted when bazelbuild/bazel#4665 is resolved.

@natansil natansil changed the title hack for proto in case of many-repo with relative package [WIP] hack for proto in case of many-repo with relative package Oct 16, 2018
@@ -331,14 +331,28 @@ def scala_proto_repositories(
name = 'io_bazel_rules_scala/dependency/proto/netty_handler_proxy',
actual = '@scala_proto_rules_netty_handler_proxy//jar')

def _root_path(f):
def _root_path(f, transitive_proto_paths):
# print("f.is_source is {}".format(f.is_source))
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please remove all prints

package_len = 0
for package_set in transitive_proto_paths:
for package in package_set.to_list():
if str(package) in f.path:
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is it in instead of starts_with so that the external/<REPO> part at the beginning is ignored? If that's the case, prefer explicitly checking for that prefix because otherwise you'll run into all sorts of problems where package is randomly in the middle of the path of the .proto file.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ok, I'll do something like:

Suggested change
if str(package) in f.path:
if f.path.startswith(f.owner.workspace_root + "/" + str(package)):

val file = if (root.isEmpty) {
parsed(1)
} else {
parsed(1).substring(root.length + 1)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is literally the first time I'm reading Scala, but doesn't this assume that root is at the beginning of parsed(1), that is, the path to the .proto file? If so, how can this work with files under external/ ?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Note this line is under condition where there is no external in root...

return ':'.join([
"{root},{path}".format(root = _root_path(f), path = f.path)
"{root},{path}".format(root = _root_path(f, transitive_proto_paths), path = f.path)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In general, it's kind of odd that the code is separated between Starlark and Scala. Can you make it so that the whole thing is in one place (preferably, Starlark?)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In rules_scala this pattern of mixed scala and Starlark is quite common...

parsed(1)
} else {
parsed(1).substring(root.length + 1)
if (parsed(1).contains("external")) {
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@ittaiz, I've found the bug manifested in OriP's branch. This line had the error.
changing it to startsWith:

Suggested change
if (parsed(1).contains("external")) {
if (parsed(1).startsWith("external")) {

fixed it.

next step is to add E2E test.
should we do this in Wix's fork or on bazelbuild?

@natansil natansil changed the title [WIP] hack for proto in case of many-repo with relative package hack for proto in case of many-repo with relative package Nov 14, 2018
@natansil
Copy link
Contributor Author

@ittaiz please review

@ittaiz
Copy link
Member

ittaiz commented Jan 26, 2019

@natansil can we close this?

@natansil natansil closed this Jan 26, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants