-
-
Notifications
You must be signed in to change notification settings - Fork 287
Make sure that scala proto files are generated correctly for external proto dependencies #294
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
Make sure that scala proto files are generated correctly for external proto dependencies #294
Conversation
Can one of the admins verify this patch? |
scala_proto/scala_proto.bzl
Outdated
@@ -414,7 +414,7 @@ Example: | |||
|
|||
Args: | |||
name: A unique name for this rule | |||
deps: Proto library targets that this rule depends on (must be of type proto_library) | |||
deps: Proto library targets or jvm targets that this rule depends on |
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.
this can't be any jvm target, right? You are expecting java_proto_library?
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.
Well, any jvm targets that you pass here are going to be passed through as deps to the final output scala_library. Does that seem unreasonable?
} | ||
(file, Paths.get(root, file).toString) | ||
} | ||
val imports = parsedProtoFiles.map { case (relPath, absolutePath) => |
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.
can you comment what these are doing?
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.
Will do
scala_proto/scala_proto.bzl
Outdated
@@ -414,7 +414,7 @@ Example: | |||
|
|||
Args: | |||
name: A unique name for this rule | |||
deps: Proto library targets that this rule depends on (must be of type proto_library) | |||
deps: Proto library targets or jvm targets that this rule depends on | |||
with_grpc: Enables generation of grpc service bindings for services defined in deps | |||
with_java: Enables generation of converters to and from java protobuf bindings |
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.
to do this you must also depend on the java_proto_library
? Is that right? Should we update this comment?
README.md
Outdated
@@ -498,7 +498,7 @@ generated by the [ScalaPB compiler](https://github.com/scalapb/ScalaPB). | |||
<td><code>deps</code></td> | |||
<td> | |||
<p><code>List of labels, required</code></p> | |||
<p>List of proto dependencies that this target depends on. Must be of type <code>proto_library</code></p> | |||
<p>List of dependencies for this target. All targets of type <code>proto_library</code> are passed to <code>scalapb</code> for compilation. All other targets are used to compile the final output scala library</p> |
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.
can these really be any generic target if not proto?
Is it anything that you might need to do the with_java
, is that it?
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.
Well the reason I changed this is for with_java
but you could potentially use this to pass other dependencies to the output scala_library (though not sure why one would want that).
scala_proto/scala_proto.bzl
Outdated
visibility = visibility, | ||
) | ||
external_deps.append(java_proto_lib) | ||
scala_lib_deps = external_deps + deps |
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.
do you not need the transitive compile time dependencies of any of the jvm code?
Also, I think we want to filter this so that we only include the non-proto deps. Otherwise, casual formatting changes to the proto that don't change the compile output will cause a recompilation.
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.
Two questions:
- How can I get the transitive compile time deps for a jvm dep?
- What is the best way to do this in a macro? Remember that this is not within a rule implementation so
deps
is just a list of strings. Should I usenative.existing_rule
? https://docs.bazel.build/versions/master/skylark/lib/native.html#existing_rule
@@ -308,12 +308,13 @@ def scala_proto_repositories(): | |||
) | |||
|
|||
def _colon_paths(data): | |||
return ':'.join([f.path for f in data]) | |||
return ':'.join(["{root},{path}".format(root=f.owner.workspace_root, path=f.path) for f in data]) |
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.
this is making me nervous, but maybe that's the only way to go here.
There was an old doc about fixing these kinds of issues about cross workspace dependencies like 1.5 years ago or so, but I don't think they actually ever did anything about it, unless I'm mistaken:
cc @damienmg I recall there was a plan to put all the paths rooted with the project name. That never shipped right?
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.
If there's a better way to deal with this, I would be happy to do that instead. Frankly I just cribbed this from what the java_proto_library
tool is doing
Right Kristina was working on it but that's a hard work. It still has to
ship in the following months hopefully.
…On Tue, Oct 3, 2017, 7:17 PM P. Oscar Boykin ***@***.***> wrote:
***@***.**** commented on this pull request.
------------------------------
In scala_proto/scala_proto.bzl
<#294 (comment)>
:
> @@ -414,7 +414,7 @@ Example:
Args:
name: A unique name for this rule
- deps: Proto library targets that this rule depends on (must be of type proto_library)
+ deps: Proto library targets or jvm targets that this rule depends on
this can't be any jvm target, right? You are expecting java_proto_library?
------------------------------
In src/scala/scripts/ScalaPBGenerator.scala
<#294 (comment)>
:
> @@ -39,7 +39,20 @@ class ScalaPBGenerator extends Processor {
def processRequest(args: java.util.List[String]) {
val jarOutput = args.get(0)
- val protoFiles = args.get(1).split(':').toList
+ val parsedProtoFiles = args.get(1).split(':').toList.map { rootAndFile =>
+ val parsed = rootAndFile.split(',')
+ val root = parsed(0)
+ val file = if (root.isEmpty) {
+ parsed(1)
+ } else {
+ parsed(1).substring(root.length + 1)
+ }
+ (file, Paths.get(root, file).toString)
+ }
+ val imports = parsedProtoFiles.map { case (relPath, absolutePath) =>
can you comment what these are doing?
------------------------------
In scala_proto/scala_proto.bzl
<#294 (comment)>
:
> @@ -414,7 +414,7 @@ Example:
Args:
name: A unique name for this rule
- deps: Proto library targets that this rule depends on (must be of type proto_library)
+ deps: Proto library targets or jvm targets that this rule depends on
with_grpc: Enables generation of grpc service bindings for services defined in deps
with_java: Enables generation of converters to and from java protobuf bindings
to do this you must also depend on the java_proto_library? Is that right?
Should we update this comment?
------------------------------
In README.md
<#294 (comment)>
:
> @@ -498,7 +498,7 @@ generated by the [ScalaPB compiler](https://github.com/scalapb/ScalaPB).
<td><code>deps</code></td>
<td>
<p><code>List of labels, required</code></p>
- <p>List of proto dependencies that this target depends on. Must be of type <code>proto_library</code></p>
+ <p>List of dependencies for this target. All targets of type <code>proto_library</code> are passed to <code>scalapb</code> for compilation. All other targets are used to compile the final output scala library</p>
can these really be any generic target if not proto?
Is it anything that you might need to do the with_java, is that it?
------------------------------
In scala_proto/scala_proto.bzl
<#294 (comment)>
:
> @@ -445,20 +445,12 @@ def scalapb_proto_library(
)
external_deps = list(SCALAPB_DEPS + GRPC_DEPS if (with_grpc) else SCALAPB_DEPS)
-
- if with_java:
- java_proto_lib = name + "_java_lib"
- native.java_proto_library(
- name = java_proto_lib,
- deps = deps,
- visibility = visibility,
- )
- external_deps.append(java_proto_lib)
+ scala_lib_deps = external_deps + deps
do you not need the transitive compile time dependencies of any of the jvm
code?
Also, I think we want to filter this so that we only include the non-proto
deps. Otherwise, casual formatting changes to the proto that don't change
the compile output will cause a recompilation.
------------------------------
In scala_proto/scala_proto.bzl
<#294 (comment)>
:
> @@ -308,12 +308,13 @@ def scala_proto_repositories():
)
def _colon_paths(data):
- return ':'.join([f.path for f in data])
+ return ':'.join(["{root},{path}".format(root=f.owner.workspace_root, path=f.path) for f in data])
this is making me nervous, but maybe that's the only way to go here.
There was an old doc about fixing these kinds of issues about cross
workspace dependencies like 1.5 years ago or so, but I don't think they
actually ever did anything about it, unless I'm mistaken:
cc @damienmg <https://github.com/damienmg> I recall there was a plan to
put all the paths rooted with the project name. That never shipped right?
—
You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub
<#294 (review)>,
or mute the thread
<https://github.com/notifications/unsubscribe-auth/ADjHfxugl0YBjLtjdgtdwE-KNy8ZtY0Nks5sosBrgaJpZM4PsouD>
.
|
@johnynek ok I think this is better: I changed it only accept Note: I had to modify a couple of |
Haven't had a chance to take a look unfortunately but turning private
scala.bzl methods to public sounds like a really bad idea.
It turns it to public API which will be hard to change.
Can we extract them out to a separate bzl and have it have limited
visibility so only internal rules_scala targets can use it?
We need to do this refactoring at some point since scala.bzl is a god file
…On Wed, Oct 4, 2017 at 11:35 PM Argyris Zymnis ***@***.***> wrote:
@johnynek <https://github.com/johnynek> ok I think this is better: I
changed it only accept proto_library and java_proto_library deps and
pushed the logic of figuring out jar dependencies into the rule
implementation.
Note: I had to modify a couple of scala.bzl methods to be public instead
of private (and also deleted a method that could be removed in scrooge).
Let me know if that looks ok.
—
You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub
<#294 (comment)>,
or mute the thread
<https://github.com/notifications/unsubscribe-auth/ABUIFw_polJS2_zPP7_qNjHGNvz5g9Ugks5so-wjgaJpZM4PsouD>
.
|
@ittaiz happy to do this refactor. How can I limit a |
I think this is good. We already had duplication about collection of jars and many scala/java related code want this. The alternative is copy-paste. I'm +1 on this PR. |
Argyris,
The full docs are here
https://docs.bazel.build/versions/master/be/common-definitions.html but
essentially __subpackages__ should be your friend.
Oscar,
Not sure I understand what you mean. Did you mean you're good without the
refactoring? To leave this code duplication in?
…On Thu, 5 Oct 2017 at 0:52 P. Oscar Boykin ***@***.***> wrote:
I think this is good.
We already had duplication about collection of jars and many scala/java
related code want this.
The alternative is copy-paste.
I'm +1 on this PR.
—
You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub
<#294 (comment)>,
or mute the thread
<https://github.com/notifications/unsubscribe-auth/ABUIF2B3iy1DmbzffwtzuLymWqztjroBks5so_4XgaJpZM4PsouD>
.
|
@ittaiz how do you apply visibility to .bzl files? I thought that was for rules. Can you give a concrete example? I am fine with the refactoring he has done as it stands now. If it is easy to mark bazel functions or files with visibility then great, but I didn’t know we could. |
Right... my bad. I mixed up the two.
I actually saw an issue around this recently but it's obviously unsolved.
…On Thu, 5 Oct 2017 at 10:32 P. Oscar Boykin ***@***.***> wrote:
@ittaiz <https://github.com/ittaiz> how do you apply visibility to .bzl
files? I thought that was for rules. Can you give a concrete example?
I am fine with the refactoring he has done as it stands now. If it is easy
to mark bazel functions or files with visibility then great, but I didn’t
know we could.
—
You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub
<#294 (comment)>,
or mute the thread
<https://github.com/notifications/unsubscribe-auth/ABUIF05DPkBx4yrUz7npYVJGfp9BwI9tks5spIYbgaJpZM4PsouD>
.
|
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.
So I skimmed the PR and it looks good in general but if I'm not mistaken there's no test for the external repo problem right? Can we add one for it?
Btw, sorry for having sparse time for the proto area. I hope to free up some time to dive into it so i can share the review load
@ittaiz yup tests would be good but I think that would require adding an external repo dependency in |
@azymnis you can have a nested WORKSPACE I think and use that in tests. But this is a bit of a yak shave if you ask me. With a nested WORKSPACE I think you have to set up |
personally I'm happy to merge and add an issue. When we don't have good examples of how to do a test, I'm -1 on asking contributors to shave a new yak to fix a bug they can observe. If we can test it with existing or simple patterns I would say okay, but having used a nested workspace internally it is a pain, and I don't want to rush to it. |
@johnynek seems like travis-ci had another transient download issue |
sorry for the latency. |
Problem
scalapb_proto_library
will not work withproto_library_targets
that are imported from an external repo. The reason is that bazel'sproto_library
expects proto files to import external files while omitting theexternal/<repo name>/
bit from the file name. In addition to this java conversions will not work for the final scala library because of the fact thatjava_proto_library
generates a separate external jar for external dependencies thatscala_library
cannot pull in transitively.Solution
Two steps:
repo_root
as well as the proto path for each proto file to be compiled and use a-I
flag inprotoc
to map the actual location of proto files to the one that omits the repo root prefix.java_proto_library
dependency ifwith_java
is true, but expect it to be passed as part ofdeps
.@johnynek @ittaiz let me know what you think