Skip to content

Commit

Permalink
fix: windows typecheck_test .sh vs .bat error (#732)
Browse files Browse the repository at this point in the history
  • Loading branch information
jbedard authored Nov 5, 2024
1 parent e852fc0 commit 1547510
Showing 1 changed file with 17 additions and 3 deletions.
20 changes: 17 additions & 3 deletions ts/private/build_test.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,15 @@ It is used to force Bazel to build some of its dependencies, in the case where
"""

def _build_test_impl(ctx):
executable = ctx.actions.declare_file(ctx.label.name + ".sh")
# See https://github.com/bazelbuild/bazel-skylib/blob/1.7.1/rules/build_test.bzl#L19-L33

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 = ctx.actions.declare_file(ctx.label.name + extension)
ctx.actions.write(
output = executable,
is_executable = True,
content = "#!/usr/bin/env bash\nexit 0",
content = content,
)

return DefaultInfo(
Expand All @@ -26,11 +29,22 @@ def _build_test_impl(ctx):
runfiles = ctx.runfiles(files = ctx.files.targets),
)

build_test = rule(
_build_test = rule(
doc = _DOC,
implementation = _build_test_impl,
attrs = {
"targets": attr.label_list(allow_files = True),
"is_windows": attr.bool(mandatory = True),
},
test = True,
)

def build_test(name, **kwargs):
_build_test(
name = name,
is_windows = select({
"@bazel_tools//src/conditions:host_windows": True,
"//conditions:default": False,
}),
**kwargs
)

0 comments on commit 1547510

Please sign in to comment.