Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor: do not dynamically generate dummy test #101

Merged
merged 6 commits into from
Dec 21, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading