Added support for Java protobuf targets to depend on other targets.
Added import_dirs, and deps now pass through to the generated
android_library target. This brings Java proto_java_library closer to
its C++ counterpart.
Bug: 1039010
Change-Id: I9b8bf8995d8cfa17c9eb624e2a1a8a46f7cfacf7
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1986955
Reviewed-by: Albert J. Wong <[email protected]>
Reviewed-by: Andrew Grieve <[email protected]>
Reviewed-by: Ramin Halavati <[email protected]>
Commit-Queue: Sky Malice <[email protected]>
Cr-Commit-Position: refs/heads/master@{#729045}
diff --git a/build/protoc_java.py b/build/protoc_java.py
index 4eb8eae..a56128d 100755
--- a/build/protoc_java.py
+++ b/build/protoc_java.py
@@ -39,6 +39,8 @@
help="Use to generate nano protos.", action='store_true')
parser.add_option("--protoc-javalite-plugin-dir",
help="Path to protoc java lite plugin directory.")
+ parser.add_option("--import-dir", action="append", default=[],
+ help="Extra import directory for protos, can be repeated.")
options, args = parser.parse_args(argv)
build_utils.CheckOptions(options, parser, ['protoc', 'proto_path'])
@@ -50,6 +52,10 @@
print('One of --nano or --protoc-javalite-plugin-dir must be specified.')
return 1
+ proto_path_args = ['--proto_path', options.proto_path]
+ for path in options.import_dir:
+ proto_path_args += ["--proto_path", path]
+
with build_utils.TempDir() as temp_dir:
if options.nano:
# Specify arguments to the generator.
@@ -61,14 +67,16 @@
custom_env = os.environ.copy()
if options.protoc_javalite_plugin_dir:
- # if we are generating lite protos, then the lite plugin needs to be in the path when protoc
- # is called. See https://github.com/protocolbuffers/protobuf/blob/master/java/lite.md
+ # If we are generating lite protos, then the lite plugin needs to be in
+ # the path when protoc is called. See
+ # https://github.com/protocolbuffers/protobuf/blob/master/java/lite.md
custom_env['PATH'] = '{}:{}'.format(
- os.path.abspath(options.protoc_javalite_plugin_dir), custom_env['PATH'])
+ os.path.abspath(options.protoc_javalite_plugin_dir),
+ custom_env['PATH'])
# Generate Java files using protoc.
build_utils.CheckOutput(
- [options.protoc, '--proto_path', options.proto_path, out_arg]
+ [options.protoc] + proto_path_args + [out_arg]
+ args, env=custom_env)
if options.java_out_dir: