aboutsummaryrefslogtreecommitdiff
path: root/protobuf.bzl
diff options
context:
space:
mode:
authorFahrzin Hemmati <fahhem@appliedintuition.com>2018-03-16 13:23:34 -0700
committerFahrzin Hemmati <fahhem@appliedintuition.com>2018-05-07 15:40:31 -0700
commitd1403e58d82ff3a1024316ec2067fb98126e0659 (patch)
tree3e07cc8bd77fe345bd02d4724b6c1b40ce9de055 /protobuf.bzl
parentae638966e544f5108d566e48cb8edd67d5953f13 (diff)
downloadprotobuf-d1403e58d82ff3a1024316ec2067fb98126e0659.tar.gz
protobuf-d1403e58d82ff3a1024316ec2067fb98126e0659.tar.bz2
protobuf-d1403e58d82ff3a1024316ec2067fb98126e0659.zip
Only use realpath when in gendir, and use the original ctx.action if not in gendir
Diffstat (limited to 'protobuf.bzl')
-rw-r--r--protobuf.bzl44
1 files changed, 24 insertions, 20 deletions
diff --git a/protobuf.bzl b/protobuf.bzl
index ac3e862e..2b9d65fb 100644
--- a/protobuf.bzl
+++ b/protobuf.bzl
@@ -102,12 +102,13 @@ def _proto_gen_impl(ctx):
import_flags_real.append('-I$(realpath -s %s)' % path)
outs = []
- use_grpc_plugin = (ctx.attr.plugin_language == "grpc")
+ use_grpc_plugin = (ctx.attr.plugin_language == "grpc" and ctx.attr.plugin)
+ path_tpl = "$(realpath %s)" if in_gen_dir else "%s"
if ctx.attr.gen_cc:
- args += ["--cpp_out=$(realpath %s)" % gen_dir]
+ args += [("--cpp_out=" + path_tpl) % gen_dir]
outs.extend(_CcOuts([src.basename], use_grpc_plugin=use_grpc_plugin))
if ctx.attr.gen_py:
- args += ["--python_out=$(realpath %s)" % gen_dir]
+ args += [("--python_out=" + path_tpl) % gen_dir]
outs.extend(_PyOuts([src.basename], use_grpc_plugin=use_grpc_plugin))
outs = [ctx.actions.declare_file(out, sibling=src) for out in outs]
@@ -120,19 +121,25 @@ def _proto_gen_impl(ctx):
if not lang:
fail("cannot infer the target language of plugin", "plugin_language")
- if in_gen_dir:
- outdir = "."
- else:
- outdir = gen_dir
+ outdir = "." if in_gen_dir else gen_dir
if ctx.attr.plugin_options:
outdir = ",".join(ctx.attr.plugin_options) + ":" + outdir
- args += ["--plugin=protoc-gen-%s=$(realpath %s)" % (lang, plugin.path)]
+ args += [("--plugin=protoc-gen-%s=" + path_tpl) % (lang, plugin.path)]
args += ["--%s_out=%s" % (lang, outdir)]
inputs += [plugin]
- for out in outs:
- if in_gen_dir:
+ if not in_gen_dir:
+ ctx.action(
+ inputs=inputs,
+ outputs=outs,
+ arguments=args + import_flags + [src.path],
+ executable=ctx.executable.protoc,
+ mnemonic="ProtoCompile",
+ use_default_shell_env=True,
+ )
+ else:
+ for out in outs:
orig_command = " ".join(
["$(realpath %s)" % ctx.executable.protoc.path] + args +
import_flags_real + ["-I.", src.basename])
@@ -143,16 +150,13 @@ def _proto_gen_impl(ctx):
"cd -",
"mv %s/%s %s" % (gen_dir, out.basename, out.path)
])
- else:
- command = " ".join(
- [ctx.executable.protoc.path] + args + import_flags + [src.path])
- ctx.action(
- inputs=inputs + [ctx.executable.protoc],
- outputs=[out],
- command=command,
- mnemonic="ProtoCompile",
- use_default_shell_env=True,
- )
+ ctx.action(
+ inputs=inputs + [ctx.executable.protoc],
+ outputs=[out],
+ command=command,
+ mnemonic="ProtoCompile",
+ use_default_shell_env=True,
+ )
return struct(
proto=struct(