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, )