Fix moving generated files onto themselves

pull/3981/head
Fahrzin Hemmati 7 years ago
parent 0d68b29ac4
commit 2cfa7612b2
  1. 8
      protobuf.bzl

@ -72,7 +72,7 @@ def _proto_gen_impl(ctx):
deps = [] deps = []
deps += ctx.files.srcs deps += ctx.files.srcs
source_dir = _SourceDir(ctx) source_dir = _SourceDir(ctx)
gen_dir = _GenDir(ctx) gen_dir = _GenDir(ctx).rstrip('/')
if source_dir: if source_dir:
import_flags = ["-I" + source_dir, "-I" + gen_dir] import_flags = ["-I" + source_dir, "-I" + gen_dir]
else: else:
@ -94,7 +94,7 @@ def _proto_gen_impl(ctx):
for src in srcs: for src in srcs:
args = [] args = []
in_gen_dir = src.root.path == gen_dir.rstrip('/') in_gen_dir = src.root.path == gen_dir
if in_gen_dir: if in_gen_dir:
import_flags_real = [] import_flags_real = []
for f in depset(import_flags): for f in depset(import_flags):
@ -148,8 +148,10 @@ def _proto_gen_impl(ctx):
"cd %s" % src.dirname, "cd %s" % src.dirname,
"${CMD}", "${CMD}",
"cd -", "cd -",
"mv %s/%s %s" % (gen_dir, out.basename, out.path)
]) ])
generated_out = '/'.join([gen_dir, out.basename])
if generated_out != out.path:
command += ";mv %s %s" % (generated_out, out.path)
ctx.action( ctx.action(
inputs=inputs + [ctx.executable.protoc], inputs=inputs + [ctx.executable.protoc],
outputs=[out], outputs=[out],

Loading…
Cancel
Save