From 75ab443512c37761091e210da81bdf381bbaaefa Mon Sep 17 00:00:00 2001 From: yuyawk <46620009+yuyawk@users.noreply.github.com> Date: Sat, 21 Dec 2024 17:54:19 +0900 Subject: [PATCH] refactor: do not dynamically generate dummy test (#101) --- lang/cc/build_error.bzl | 26 ++++++---------------- lang/private/script/BUILD.bazel | 8 +++++++ lang/private/script/dummy_test.bash | 2 ++ lang/private/script/dummy_test_windows.bat | 1 + 4 files changed, 18 insertions(+), 19 deletions(-) create mode 100755 lang/private/script/dummy_test.bash create mode 100755 lang/private/script/dummy_test_windows.bat diff --git a/lang/cc/build_error.bzl b/lang/cc/build_error.bzl index a905f8c..f331f9a 100644 --- a/lang/cc/build_error.bzl +++ b/lang/cc/build_error.bzl @@ -674,21 +674,14 @@ def _create_test_impl(ctx): A list of providers. """ cc_build_error_info = ctx.attr.cc_build_error[CcBuildErrorInfo] - extension = ".bat" if ctx.attr.is_windows else ".sh" - content = "exit 0" if ctx.attr.is_windows else "#!/usr/bin/env bash\nexit 0" - executable_template = ctx.actions.declare_file(ctx.label.name + "/exe_tpl") - executable = ctx.actions.declare_file(ctx.label.name + extension) - ctx.actions.write( - output = executable_template, - is_executable = True, - content = content, - ) + dummy_test = get_executable_file(ctx.attr._dummy_test) + executable = ctx.actions.declare_file(ctx.label.name + "/" + dummy_test.basename) ctx.actions.run_shell( outputs = [executable], - inputs = cc_build_error_info.markers + [executable_template], + inputs = cc_build_error_info.markers + [dummy_test], command = 'cp "$1" "$2"', arguments = [ - executable_template.path, + dummy_test.path, executable.path, ], ) @@ -707,10 +700,9 @@ _create_test = rule( mandatory = True, providers = [CcBuildErrorInfo], ), - "is_windows": attr.bool( - doc = "Whether the runtime environment is windows or not. " + - "This attribute is not user-facing.", - mandatory = True, + "_dummy_test": attr.label( + default = Label("//lang/private/script:dummy_test"), + doc = "Dummy test script which always succeeds.", ), }, test = True, @@ -742,10 +734,6 @@ def cc_build_error_test(*, name, **kwargs): _create_test( name = name, cc_build_error = ":" + build_target_name, - is_windows = select({ - "@bazel_tools//src/conditions:host_windows": True, - "//conditions:default": False, - }), tags = tags, visibility = visibility, timeout = "short", diff --git a/lang/private/script/BUILD.bazel b/lang/private/script/BUILD.bazel index b2f7ea5..826a255 100644 --- a/lang/private/script/BUILD.bazel +++ b/lang/private/script/BUILD.bazel @@ -19,3 +19,11 @@ filegroup( name = "try_build", srcs = ["try_build.bash"], ) + +filegroup( + name = "dummy_test", + srcs = select({ + "@bazel_tools//src/conditions:host_windows": ["dummy_test_windows.bat"], + "//conditions:default": ["dummy_test.bash"], + }), +) diff --git a/lang/private/script/dummy_test.bash b/lang/private/script/dummy_test.bash new file mode 100755 index 0000000..742e13d --- /dev/null +++ b/lang/private/script/dummy_test.bash @@ -0,0 +1,2 @@ +#!/usr/bin/env bash +exit 0 diff --git a/lang/private/script/dummy_test_windows.bat b/lang/private/script/dummy_test_windows.bat new file mode 100755 index 0000000..ca916d0 --- /dev/null +++ b/lang/private/script/dummy_test_windows.bat @@ -0,0 +1 @@ +exit 0