Skip to content

Commit 4bd578d

Browse files
committed
Added windows to CI
1 parent b47411a commit 4bd578d

6 files changed

Lines changed: 86 additions & 23 deletions

File tree

.bazelrc

Lines changed: 31 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,18 @@
1+
###############################################################################
2+
## Bazel Configuration Flags
3+
##
4+
## `.bazelrc` is a Bazel configuration file.
5+
## https://bazel.build/docs/best-practices#bazelrc-file
6+
###############################################################################
7+
18
test --test_output=errors
9+
test --verbose_failures
210

311
# Fix the excessive rebuilding when using anything that depends on protobuf rules
412
# See https://github.com/bazelbuild/buildtools/issues/744
513
common --incompatible_strict_action_env
614
common --enable_bzlmod
715

8-
try-import user.bazelrc
9-
1016
# To update these lines, execute
1117
# `bazel run @rules_bazel_integration_test//tools:update_deleted_packages`
1218
build --deleted_packages=examples/check_glob,examples/optional_attributes
@@ -15,3 +21,26 @@ query --deleted_packages=examples/check_glob,examples/optional_attributes
1521
# Enable the aspect
1622
build --aspects=//shellcheck:shellcheck_aspect.bzl%shellcheck_aspect
1723
build --output_groups=+shellcheck_checks
24+
25+
###############################################################################
26+
## Incompatibility flags
27+
###############################################################################
28+
29+
# https://github.com/bazelbuild/bazel/issues/8195
30+
build --incompatible_disallow_empty_glob=true
31+
32+
# https://github.com/bazelbuild/bazel/issues/12821
33+
build --nolegacy_external_runfiles
34+
35+
# https://github.com/bazelbuild/bazel/issues/23043.
36+
build --incompatible_autoload_externally=
37+
38+
###############################################################################
39+
## Custom user flags
40+
##
41+
## This should always be the last thing in the `.bazelrc` file to ensure
42+
## consistent behavior when setting flags in that file as `.bazelrc` files are
43+
## evaluated top to bottom.
44+
###############################################################################
45+
46+
try-import user.bazelrc

.bcr/presubmit.yml

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,12 @@
22
bcr_test_module:
33
module_path: "examples/check_glob"
44
matrix:
5-
platform: ["debian10", "macos", "ubuntu2004"]
5+
platform:
6+
- "debian10"
7+
- "macos"
8+
- "macos_arm64"
9+
- "ubuntu2004"
10+
- "ubuntu2004_arm64"
611
bazel: [7.*, 8.*, 9.*]
712
tasks:
813
run_tests:

.github/workflows/workflow.yml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,17 +19,17 @@ jobs:
1919
include:
2020
- os: macos-latest
2121
- os: ubuntu-latest
22+
- os: ubuntu-24.04-arm
23+
- os: windows-latest
2224

2325
steps:
2426
- uses: actions/checkout@v6
2527

26-
- name: Test fetch
27-
run: bazel fetch //...
28-
2928
- name: Test
3029
run: bazel test //...
3130

3231
- name: Create release archive and notes
32+
if: startswith(runner.os, 'Windows') != true
3333
# Set by GH actions, see
3434
# https://docs.github.com/en/actions/learn-github-actions/environment-variables#default-environment-variables
3535
run: ./ci/package.sh "${{ github.ref_name }}"
Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
1-
#!/bin/sh
1+
@ECHO OFF
22

3-
set -eu
4-
5-
echo "" > "${SHELLCHECK_ASPECT_OUTPUT}"
6-
exec $@
3+
echo "" > "%SHELLCHECK_ASPECT_OUTPUT%"
4+
call %*
5+
exit /b %ERRORLEVEL%

shellcheck/internal/aspect_runner.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,4 +3,4 @@
33
set -eu
44

55
echo "" > "${SHELLCHECK_ASPECT_OUTPUT}"
6-
exec $@
6+
exec "$@"

shellcheck/internal/rules.bzl

Lines changed: 41 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -9,15 +9,21 @@ _SHELL_CONTENT = """\
99
1010
set -eu
1111
12-
{shellcheck} {args}
12+
"{shellcheck}" {args}{post}
1313
"""
1414

1515
_BATCH_CONTENT = """\
1616
@ECHO OFF
1717
18-
{shellcheck} {args}
18+
"{shellcheck}" {args}{post}
1919
"""
2020

21+
def _quote_for_shell(value):
22+
return "\"{}\"".format(value.replace("\"", "\\\""))
23+
24+
def _quote_for_batch(value):
25+
return "\"{}\"".format(value.replace("\"", "\"\""))
26+
2127
def shellcheck_test_impl(ctx, expect_fail = False):
2228
"""The implementation of the `shellcheck_test` rule.
2329
@@ -48,21 +54,27 @@ def shellcheck_test_impl(ctx, expect_fail = False):
4854
shellcheck_rc = toolchain.shellcheckrc.short_path
4955
srcs = [f.short_path for f in ctx.files.data]
5056
if is_windows:
51-
shellcheck_path.replace("/", "\\")
52-
shellcheck_rc.replace("/", "\\")
57+
shellcheck_path = shellcheck_path.replace("/", "\\")
58+
shellcheck_rc = shellcheck_rc.replace("/", "\\")
5359
srcs = [src.replace("/", "\\") for src in srcs]
5460

55-
cmd.append("--rcfile={}".format(shellcheck_rc))
56-
cmd.extend(srcs)
61+
if is_windows:
62+
cmd.append("--rcfile={}".format(_quote_for_batch(shellcheck_rc)))
63+
cmd.extend([_quote_for_batch(src) for src in srcs])
64+
else:
65+
cmd.append("--rcfile={}".format(_quote_for_shell(shellcheck_rc)))
66+
cmd.extend([_quote_for_shell(src) for src in srcs])
5767

68+
post = ""
5869
if expect_fail:
59-
cmd.append("|| exit 0; exit 1")
70+
post = " && exit /b 1 || exit /b 0" if is_windows else " || exit 0\nexit 1"
6071

6172
ctx.actions.write(
6273
output = executable,
6374
content = (_BATCH_CONTENT if is_windows else _SHELL_CONTENT).format(
6475
shellcheck = shellcheck_path,
6576
args = " ".join(cmd),
77+
post = post,
6678
),
6779
is_executable = True,
6880
)
@@ -148,6 +160,12 @@ _shellcheck_srcs_aspect = aspect(
148160
implementation = _shellcheck_srcs_aspect_impl,
149161
)
150162

163+
def _unix_path_arg(value):
164+
return value.path
165+
166+
def _windows_path_arg(value):
167+
return value.path.replace("/", "\\")
168+
151169
def _shellcheck_aspect_impl(target, ctx):
152170
if target.label.workspace_root.startswith("external"):
153171
return []
@@ -177,6 +195,9 @@ def _shellcheck_aspect_impl(target, ctx):
177195
return []
178196

179197
toolchain = ctx.toolchains[TOOLCHAIN_TYPE]
198+
is_windows = ctx.target_platform_has_constraint(
199+
ctx.attr._windows_constraint[platform_common.ConstraintValueInfo],
200+
)
180201

181202
inputs_direct = [toolchain.shellcheckrc] + getattr(ctx.rule.files, "data", [])
182203
inputs_transitive = [src_info.srcs, src_info.transitive_srcs]
@@ -188,15 +209,21 @@ def _shellcheck_aspect_impl(target, ctx):
188209
])
189210

190211
format = ctx.attr._format[BuildSettingInfo].value
191-
severity = ctx.attr._format[BuildSettingInfo].value
212+
severity = ctx.attr._severity[BuildSettingInfo].value
192213

193214
output = ctx.actions.declare_file("{}.shellcheck.ok".format(target.label.name))
194215

195216
tools = depset([toolchain.shellcheck], transitive = [toolchain.all_files])
196217

218+
shellcheck_path = toolchain.shellcheck.path
219+
shellcheck_rc_path = toolchain.shellcheckrc.path
220+
if is_windows:
221+
shellcheck_path = shellcheck_path.replace("/", "\\")
222+
shellcheck_rc_path = shellcheck_rc_path.replace("/", "\\")
223+
197224
args = ctx.actions.args()
198-
args.add(toolchain.shellcheck)
199-
args.add(toolchain.shellcheckrc, format = "--rcfile=%s")
225+
args.add(shellcheck_path)
226+
args.add(shellcheck_rc_path, format = "--rcfile=%s")
200227
args.add_all(src_info.source_paths, format_each = "--source-path=%s")
201228

202229
if format:
@@ -205,7 +232,7 @@ def _shellcheck_aspect_impl(target, ctx):
205232
if severity:
206233
args.add(severity, format = "--severity=%s")
207234

208-
args.add_all(srcs)
235+
args.add_all(srcs, map_each = _windows_path_arg if is_windows else _unix_path_arg)
209236

210237
ctx.actions.run(
211238
mnemonic = "Shellcheck",
@@ -240,6 +267,9 @@ shellcheck_aspect = aspect(
240267
"_severity": attr.label(
241268
default = Label("//shellcheck/settings:severity"),
242269
),
270+
"_windows_constraint": attr.label(
271+
default = Label("@platforms//os:windows"),
272+
),
243273
},
244274
toolchains = [TOOLCHAIN_TYPE],
245275
requires = [_shellcheck_srcs_aspect],

0 commit comments

Comments
 (0)