From 1763ce3b1d3c3d42f9148621c22568e4aa505601 Mon Sep 17 00:00:00 2001 From: "Daniel P. Purkhus" Date: Sat, 13 Feb 2021 23:50:32 +0000 Subject: [PATCH] Fix remote execution for empty aspects See: https://github.com/bazelbuild/bazel/issues/6393 --- aspect.bzl | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/aspect.bzl b/aspect.bzl index 55f1d820b..dfceb809b 100644 --- a/aspect.bzl +++ b/aspect.bzl @@ -107,7 +107,10 @@ def proto_compile_impl(ctx): # Build copy command for directory outputs # Use cp {}/. rather than {}/* to allow for empty output directories from a plugin (e.g when no service exists, # so no files generated) - command_parts = ["cp -r {} '{}'".format( + # We need to `mkdir` the new dir for the action work with remote execution when + # because the folder could possibly be empty: https://github.com/bazelbuild/bazel/issues/6393 + command_parts = ["mkdir -p {} && cp -r {} '{}'".format( + new_dir.path, " ".join(["'" + d.path + "/.'" for d in output_dirs.to_list()]), new_dir.path, )] @@ -423,7 +426,10 @@ def proto_compile_aspect_impl(target, ctx): ### mnemonic = "ProtoCompile" - command = ("mkdir -p '{}' && ".format(output_root)) + protoc.path + " $@" # $@ is replaced with args list + command = "mkdir -p '{}' && ".format(output_root) + if plugin.output_directory: + command = "mkdir -p '{}' && ".format(out_file) # Needed in case the folder is empty, see: https://github.com/bazelbuild/bazel/issues/6393 + command = command + protoc.path + " $@" # $@ is replaced with args list inputs = proto_info.transitive_descriptor_sets.to_list() + plugin_runfiles # Proto files are not inputs, as they come via the descriptor sets tools = [protoc] + ([plugin_tool] if plugin_tool else [])