Skip to content

Commit

Permalink
Refactor NUnit test Bazel rule to use common copy_files macro
Browse files Browse the repository at this point in the history
  • Loading branch information
jimevans committed Nov 12, 2020
1 parent a67b28b commit 4f10075
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 63 deletions.
2 changes: 1 addition & 1 deletion dotnet/private/copy_files.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ def _copy_cmd(ctx, file_list, target_dir):
return dest_list

shell_content = ""
batch_file_name = "%s-staging.bat" % (target_dir)
batch_file_name = "%s-copy-files.bat" % (ctx.label.name)
bat = ctx.actions.declare_file(batch_file_name)
src_file_list = []
for (src_file, relative_dest_file) in file_list:
Expand Down
64 changes: 5 additions & 59 deletions dotnet/private/executable_assembly.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ load(
"is_debug",
"is_standard_framework",
)
load("//dotnet/private:copy_files.bzl", "copy_files")

def _generate_execution_script_file(ctx, target):
tfm = target.actual_tfm
Expand Down Expand Up @@ -46,69 +47,14 @@ def _generate_execution_script_file(ctx, target):

return shell_file

def _copy_cmd(ctx, file_list, target_dir):
dest_list = []

if file_list == None or len(file_list) == 0:
return dest_list

shell_content = ""
batch_file_name = "%s/%s-copydeps.bat" % (target_dir, ctx.attr.out)
bat = ctx.actions.declare_file(batch_file_name)
for src_file in file_list:
dest_file = ctx.actions.declare_file(target_dir + src_file.basename)
dest_list.append(dest_file)
shell_content += "@copy /Y \"%s\" \"%s\" >NUL\n" % (
src_file.path.replace("/", "\\"),
dest_file.path.replace("/", "\\"),
)

ctx.actions.write(
output = bat,
content = shell_content,
is_executable = True,
)
ctx.actions.run(
inputs = file_list,
tools = [bat],
outputs = dest_list,
executable = "cmd.exe",
arguments = ["/C", bat.path.replace("/", "\\")],
mnemonic = "CopyFile",
progress_message = "Copying files",
use_default_shell_env = True,
)

return dest_list

def _copy_bash(ctx, src_list, target_dir):
dest_list = []
for src_file in src_list:
dest_file = ctx.actions.declare_file(target_dir + src_file.basename)
dest_list.append(dest_file)

ctx.actions.run_shell(
tools = [src_file],
outputs = [dest_file],
command = "cp -f \"$1\" \"$2\"",
arguments = [src_file.path, dest_file.path],
mnemonic = "CopyFile",
progress_message = "Copying files",
use_default_shell_env = True,
)

return dest_list

def _copy_dependency_files(ctx, provider_value):
src_list = provider_value.transitive_runfiles.to_list()
target_dir = "bazelout/%s/" % (provider_value.actual_tfm)
dest_list = []
if ctx.attr.is_windows:
dest_list = _copy_cmd(ctx, src_list, target_dir)
else:
dest_list = _copy_bash(ctx, src_list, target_dir)
file_list = []
for src_file in src_list:
file_list.append((src_file, src_file.basename))

return dest_list
return copy_files(ctx, file_list, target_dir, ctx.attr.is_windows)

def create_executable_assembly(ctx, extra_srcs, extra_deps):
stdrefs = [ctx.attr._stdrefs] if ctx.attr.include_stdrefs else []
Expand Down
6 changes: 3 additions & 3 deletions dotnet/test/common/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -65,19 +65,19 @@ config_setting(
visibility = ["//visibility:public"],
deps = select({
":netframework": [
"//dotnet/src/webdriver:net47assembly",
"//dotnet/src/webdriver:net47",
"@json.net//:Newtonsoft.Json",
"@benderproxy//:BenderProxy",
"@moq//:Moq",
],
":netcore": [
"//dotnet/src/webdriver:netstandard2.0assembly",
"//dotnet/src/webdriver:netstandard2.0",
"@json.net//:Newtonsoft.Json",
"@benderproxy//:BenderProxy",
"@moq//:Moq",
],
"//conditions:default": [
"//dotnet/src/webdriver:netstandard2.0assembly",
"//dotnet/src/webdriver:netstandard2.0",
"@json.net//:Newtonsoft.Json",
"@benderproxy//:BenderProxy",
"@moq//:Moq",
Expand Down

0 comments on commit 4f10075

Please sign in to comment.