Skip to content

Commit

Permalink
Merge pull request #18 from hans-brgs/fix_windows_batfile_conflict_S1
Browse files Browse the repository at this point in the history
Resolve .bat file conflict using direct command execution
  • Loading branch information
cmaf5 committed Sep 29, 2023
2 parents 17fde6c + 9bf0f23 commit e47f6a1
Showing 1 changed file with 4 additions and 9 deletions.
13 changes: 4 additions & 9 deletions magritte/magritte_graph.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -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,
)

Expand Down

0 comments on commit e47f6a1

Please sign in to comment.