Skip to content

Commit

Permalink
fix bug of misidentifying external proto files
Browse files Browse the repository at this point in the history
  • Loading branch information
natansil committed Nov 13, 2018
1 parent f93b6e6 commit 77f9525
Show file tree
Hide file tree
Showing 5 changed files with 20 additions and 9 deletions.
9 changes: 5 additions & 4 deletions scala_proto/scala_proto.bzl
Expand Up @@ -336,19 +336,20 @@ def _root_path(f, transitive_proto_paths):
if f.is_source:
print("f.path: " + f.path + ". f.owner.workspace_root: "+ f.owner.workspace_root + ". f.root.path: " + f.root.path)
if (f.owner.workspace_root):
start = len(f.owner.workspace_root)+1
start_of_relative_path = len(f.owner.workspace_root)+1
# print("start index: {}".format(start))
package_len = 0
for package_set in transitive_proto_paths:
for package in package_set.to_list():
if str(package) in f.path:
if f.path.startswith(f.owner.workspace_root + "/" + str(package)):
package_len = len(package)+1
relative_path=f.path[start+package_len:]
relative_path=f.path[start_of_relative_path+package_len:]
print("relative_path: " + relative_path)
return relative_path
else:
return f.owner.workspace_root
return '/'.join([f.root.path, f.owner.workspace_root])
path = '/'.join([f.root.path, f.owner.workspace_root])
return path

def _colon_paths(data, transitive_proto_paths):
return ':'.join([
Expand Down
2 changes: 1 addition & 1 deletion src/scala/scripts/PBGenerateRequest.scala
Expand Up @@ -10,7 +10,7 @@ object PBGenerateRequest {
val jarOutput = args.get(0)
val parsedProtoFiles = args.get(1).split(':').toList.map { rootAndFile =>
val parsed = rootAndFile.split(',')
if (parsed(1).contains("external")) {
if (parsed(1).startsWith("external")) {
println("parsed(0) is " + parsed(0))
println("parsed(1) is " + parsed(1))
(parsed(0), parsed(1))
Expand Down
3 changes: 2 additions & 1 deletion test/proto/cross_repo/repo_a/src/a_pkg/BUILD.bazel
Expand Up @@ -3,7 +3,8 @@ load("@io_bazel_rules_scala//scala_proto:scala_proto.bzl", "scala_proto_srcjar",
proto_library(
name = "a_proto",
srcs = ["some_package/a.proto"],
deps = ["@b_for_proto_test//src/b_pkg:b_proto"],
deps = ["@b_for_proto_test//src/b_pkg:b_proto",
"@com_google_protobuf//:descriptor_proto"],
proto_source_root = PACKAGE_NAME,
)

Expand Down
13 changes: 11 additions & 2 deletions test/proto/cross_repo/repo_a/src/a_pkg/some_package/a.proto
Expand Up @@ -2,6 +2,15 @@ syntax = "proto3";

import "some_package2/b.proto";

message Baz {
Foo foo3 = 1;
// use dependency with external in the middle of the file path
// (e.g. - 'external' in generated output: bazel-out/darwin-fastbuild/genfiles/external/com_google_protobuf/google/protobuf/descriptor.proto)
import "google/protobuf/descriptor.proto";


message Bar {
Foo foo = 1;
}

extend google.protobuf.MethodOptions {
Foo foo = 50301;
}
@@ -1,5 +1,5 @@
syntax = "proto3";

message Foo {
string bar = 1;
string foo = 1;
}

0 comments on commit 77f9525

Please sign in to comment.