From 2cfa7612b2e8226c66977b7f91b5b65d874276bb Mon Sep 17 00:00:00 2001 From: Fahrzin Hemmati Date: Mon, 26 Mar 2018 19:09:08 -0700 Subject: [PATCH] Fix moving generated files onto themselves --- protobuf.bzl | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/protobuf.bzl b/protobuf.bzl index 2b9d65fb59..511df772c7 100644 --- a/protobuf.bzl +++ b/protobuf.bzl @@ -72,7 +72,7 @@ def _proto_gen_impl(ctx): deps = [] deps += ctx.files.srcs source_dir = _SourceDir(ctx) - gen_dir = _GenDir(ctx) + gen_dir = _GenDir(ctx).rstrip('/') if source_dir: import_flags = ["-I" + source_dir, "-I" + gen_dir] else: @@ -94,7 +94,7 @@ def _proto_gen_impl(ctx): for src in srcs: args = [] - in_gen_dir = src.root.path == gen_dir.rstrip('/') + in_gen_dir = src.root.path == gen_dir if in_gen_dir: import_flags_real = [] for f in depset(import_flags): @@ -148,8 +148,10 @@ def _proto_gen_impl(ctx): "cd %s" % src.dirname, "${CMD}", "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( inputs=inputs + [ctx.executable.protoc], outputs=[out],