From 9bf0f23545e3958ce0e09c4e5ed67ee19bb84d19 Mon Sep 17 00:00:00 2001 From: Bourgeois Date: Wed, 9 Aug 2023 22:41:21 +0200 Subject: [PATCH 1/2] Resolve .bat file conflict using direct command execution --- magritte/magritte_graph.bzl | 13 ++++--------- 1 file changed, 4 insertions(+), 9 deletions(-) diff --git a/magritte/magritte_graph.bzl b/magritte/magritte_graph.bzl index 1ee9561..9675408 100644 --- a/magritte/magritte_graph.bzl +++ b/magritte/magritte_graph.bzl @@ -161,21 +161,16 @@ def _copy_action_bash(ctx, input_file, output_file): # Copies a file to another file. If the destination directory does not exist # it will be created. (Windows version) def _copy_action_windows(ctx, input_file, output_file): - bat = ctx.actions.declare_file(ctx.label.name + "_cmd.bat") file_to_copy = input_file.path.replace("/", "\\") destination_folder = output_file.dirname.replace("/", "\\") - ctx.actions.write( - output = bat, - content = "@mkdir \"%s\"\n@copy /Y \"%s\" \"%s\"" % - (destination_folder, file_to_copy, destination_folder), - is_executable = True, - ) + cmd_part1 = "(if not exist \"%s\" mkdir \"%s\")" % (destination_folder, destination_folder) + cmd_part2 = " && @copy /Y \"%s\" \"%s\"" % (file_to_copy, destination_folder) + cmd = cmd_part1 + cmd_part2 ctx.actions.run( inputs = [input_file], - tools = [bat], outputs = [output_file], executable = "cmd.exe", - arguments = ["/C", bat.path.replace("/", "\\")], + arguments = ["/C", cmd], use_default_shell_env = True, ) From e1ca649f927cef29dea76c78e3c53a432ff5f159 Mon Sep 17 00:00:00 2001 From: Bourgeois Date: Wed, 9 Aug 2023 22:51:15 +0200 Subject: [PATCH 2/2] Resolve .bat file conflict by using unique hash in filename --- magritte/magritte_graph.bzl | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/magritte/magritte_graph.bzl b/magritte/magritte_graph.bzl index 9675408..59dad08 100644 --- a/magritte/magritte_graph.bzl +++ b/magritte/magritte_graph.bzl @@ -161,16 +161,21 @@ def _copy_action_bash(ctx, input_file, output_file): # Copies a file to another file. If the destination directory does not exist # it will be created. (Windows version) def _copy_action_windows(ctx, input_file, output_file): + bat = ctx.actions.declare_file("%s-%s-cmd.bat" % (ctx.label.name, hash(src.path))) file_to_copy = input_file.path.replace("/", "\\") destination_folder = output_file.dirname.replace("/", "\\") - cmd_part1 = "(if not exist \"%s\" mkdir \"%s\")" % (destination_folder, destination_folder) - cmd_part2 = " && @copy /Y \"%s\" \"%s\"" % (file_to_copy, destination_folder) - cmd = cmd_part1 + cmd_part2 + ctx.actions.write( + output = bat, + content = "@mkdir \"%s\"\n@copy /Y \"%s\" \"%s\"" % + (destination_folder, file_to_copy, destination_folder), + is_executable = True, + ) ctx.actions.run( inputs = [input_file], + tools = [bat], outputs = [output_file], executable = "cmd.exe", - arguments = ["/C", cmd], + arguments = ["/C", bat.path.replace("/", "\\")], use_default_shell_env = True, )