Skip to content

Commit

Permalink
refactor: do not dynamically generate dummy test (#101)
Browse files Browse the repository at this point in the history
  • Loading branch information
yuyawk authored Dec 21, 2024
1 parent c1e0952 commit 75ab443
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 19 deletions.
26 changes: 7 additions & 19 deletions lang/cc/build_error.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -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,
],
)
Expand All @@ -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,
Expand Down Expand Up @@ -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",
Expand Down
8 changes: 8 additions & 0 deletions lang/private/script/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -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"],
}),
)
2 changes: 2 additions & 0 deletions lang/private/script/dummy_test.bash
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
#!/usr/bin/env bash
exit 0
1 change: 1 addition & 0 deletions lang/private/script/dummy_test_windows.bat
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
exit 0

0 comments on commit 75ab443

Please sign in to comment.