Skip to content

Commit 0bcec88

Browse files
authored
Add shellcheck tests for generated build scripts (#1390)
1 parent f096e7d commit 0bcec88

17 files changed

+185
-36
lines changed

.bazelci/config.yaml

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,24 +6,32 @@ tasks:
66
- "//..."
77
test_targets:
88
- "//..."
9+
test_flags:
10+
- "--@aspect_rules_lint//lint:fail_on_violation"
911
rbe_ubuntu2004:
1012
platform: rbe_ubuntu2004
1113
build_targets:
1214
- "//..."
1315
test_targets:
1416
- "//..."
17+
test_flags:
18+
- "--@aspect_rules_lint//lint:fail_on_violation"
1519
macos:
1620
platform: macos
1721
build_targets:
1822
- "//..."
1923
test_targets:
2024
- "//..."
25+
test_flags:
26+
- "--@aspect_rules_lint//lint:fail_on_violation"
2127
macos_arm64:
2228
platform: macos_arm64
2329
build_targets:
2430
- "//..."
2531
test_targets:
2632
- "//..."
33+
test_flags:
34+
- "--@aspect_rules_lint//lint:fail_on_violation"
2735
windows:
2836
platform: windows
2937
build_targets:
@@ -39,6 +47,7 @@ tasks:
3947
test_flags:
4048
- "--noenable_bzlmod"
4149
- "--enable_workspace"
50+
- "--@aspect_rules_lint//lint:fail_on_violation"
4251
ubuntu1804_examples_standalone:
4352
name: Examples (spawn_strategy=standalone)
4453
platform: ubuntu1804

.shellcheckrc

Whitespace-only changes.

BUILD.bazel

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,11 @@
11
load("@bazel_gazelle//:def.bzl", "DEFAULT_LANGUAGES", "gazelle", "gazelle_binary")
22
load("@bazel_skylib//:bzl_library.bzl", "bzl_library")
33

4+
exports_files(
5+
[".shellcheckrc"],
6+
visibility = ["//visibility:public"],
7+
)
8+
49
gazelle(
510
name = "gazelle",
611
gazelle = ":gazelle_bin",

MODULE.bazel

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ bazel_dep(name = "rules_shell", version = "0.3.0")
1717
bazel_dep(name = "gazelle", version = "0.41.0", dev_dependency = True, repo_name = "bazel_gazelle")
1818
bazel_dep(name = "bazel_skylib_gazelle_plugin", version = "1.7.1", dev_dependency = True)
1919
bazel_dep(name = "bazel_ci_rules", version = "1.0.0", dev_dependency = True)
20+
bazel_dep(name = "aspect_rules_lint", version = "1.2.2", dev_dependency = True)
2021

2122
python = use_extension("@rules_python//python/extensions:python.bzl", "python")
2223
python.toolchain(python_version = "3.12")

WORKSPACE.bazel

Lines changed: 70 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -84,3 +84,73 @@ load("@bazel_skylib_gazelle_plugin//:setup.bzl", "bazel_skylib_gazelle_plugin_se
8484
bazel_skylib_gazelle_plugin_setup()
8585

8686
gazelle_dependencies(go_repository_default_config = "//:WORKSPACE.bazel")
87+
88+
http_archive(
89+
name = "aspect_rules_lint",
90+
sha256 = "c90501db2548f4af27ed873e40adc6524fcd8472c25ff9946ba13aa77c767249",
91+
strip_prefix = "rules_lint-1.2.2",
92+
url = "https://github.com/aspect-build/rules_lint/releases/download/v1.2.2/rules_lint-v1.2.2.tar.gz",
93+
)
94+
95+
# aspect_rules_lint depends on aspect_bazel_lib.
96+
http_archive(
97+
name = "aspect_bazel_lib",
98+
sha256 = "6d758a8f646ecee7a3e294fbe4386daafbe0e5966723009c290d493f227c390b",
99+
strip_prefix = "bazel-lib-2.7.7",
100+
url = "https://github.com/aspect-build/bazel-lib/releases/download/v2.7.7/bazel-lib-v2.7.7.tar.gz",
101+
)
102+
103+
load("@aspect_bazel_lib//lib:repositories.bzl", "aspect_bazel_lib_dependencies")
104+
105+
# aspect_bazel_lib depends on bazel_skylib
106+
aspect_bazel_lib_dependencies()
107+
108+
load(
109+
"@aspect_rules_lint//format:repositories.bzl",
110+
# Fetch additional formatter binaries you need:
111+
"fetch_java_format",
112+
"fetch_ktfmt",
113+
"fetch_swiftformat",
114+
"rules_lint_dependencies",
115+
)
116+
117+
rules_lint_dependencies()
118+
119+
fetch_java_format()
120+
121+
fetch_ktfmt()
122+
123+
fetch_swiftformat()
124+
125+
load("@aspect_rules_lint//lint:checkstyle.bzl", "fetch_checkstyle")
126+
127+
fetch_checkstyle()
128+
129+
load("@aspect_rules_lint//lint:pmd.bzl", "fetch_pmd")
130+
131+
fetch_pmd()
132+
133+
load("@aspect_rules_lint//lint:vale.bzl", "fetch_vale")
134+
135+
fetch_vale()
136+
137+
load("@aspect_rules_lint//lint:ktlint.bzl", "fetch_ktlint")
138+
139+
fetch_ktlint()
140+
141+
load("@aspect_rules_lint//lint:spotbugs.bzl", "fetch_spotbugs")
142+
143+
fetch_spotbugs()
144+
145+
########################
146+
# Optional: multitool provides defaults for some tools such as yamlfmt
147+
# If you do not set up multitool, you must provide these tools yourself
148+
load("@rules_multitool//multitool:multitool.bzl", "multitool")
149+
150+
multitool(
151+
name = "multitool",
152+
lockfiles = [
153+
"@aspect_rules_lint//format:multitool.lock.json",
154+
"@aspect_rules_lint//lint:multitool.lock.json",
155+
],
156+
)

foreign_cc/built_tools/make_build.bzl

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,10 @@ load(
1818
"get_tools_info",
1919
)
2020
load("//foreign_cc/private:detect_xcompile.bzl", "detect_xcompile")
21+
load(
22+
"//foreign_cc/private/framework:helpers.bzl",
23+
"escape_dquote_bash",
24+
)
2125
load("//foreign_cc/private/framework:platform.bzl", "os_name")
2226

2327
def _make_tool_impl(ctx):
@@ -35,8 +39,8 @@ def _make_tool_impl(ctx):
3539

3640
script = [
3741
build_str,
38-
"mkdir -p $$INSTALLDIR$$/bin",
39-
"cp -p ./{}/gnumake.exe $$INSTALLDIR$$/bin/make.exe".format(dist_dir),
42+
"mkdir -p \"$$INSTALLDIR$$/bin\"",
43+
"cp -p ./{}/gnumake.exe \"$$INSTALLDIR$$/bin/make.exe\"".format(dist_dir),
4044
]
4145
else:
4246
env = get_env_vars(ctx)
@@ -81,7 +85,7 @@ def _make_tool_impl(ctx):
8185
"--without-guile",
8286
"--with-guile=no",
8387
"--disable-dependency-tracking",
84-
"--prefix=$$INSTALLDIR$$",
88+
"--prefix=\"$$INSTALLDIR$$\"",
8589
]
8690

8791
install_cmd = ["./make install"]
@@ -92,8 +96,8 @@ def _make_tool_impl(ctx):
9296

9397
# We can't use make to install make when cross-compiling
9498
install_cmd = [
95-
"mkdir -p $$INSTALLDIR$$/bin",
96-
"cp -p make $$INSTALLDIR$$/bin/make",
99+
"mkdir -p \"$$INSTALLDIR$$/bin\"",
100+
"cp -p make \"$$INSTALLDIR$$/bin/make\"",
97101
]
98102

99103
env.update({
@@ -133,4 +137,4 @@ make_tool = rule(
133137
)
134138

135139
def _join_flags_list(workspace_name, flags):
136-
return " ".join([absolutize(workspace_name, flag) for flag in flags])
140+
return " ".join([escape_dquote_bash(absolutize(workspace_name, flag)) for flag in flags])

foreign_cc/built_tools/ninja_build.bzl

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,9 +21,9 @@ def _ninja_tool_impl(ctx):
2121
absolute_py_interpreter_path = absolutize(ctx.workspace_name, py_toolchain.py3_runtime.interpreter.path, True)
2222

2323
script = [
24-
"{} ./configure.py --bootstrap".format(absolute_py_interpreter_path),
25-
"mkdir $$INSTALLDIR$$/bin",
26-
"cp -p ./ninja{} $$INSTALLDIR$$/bin/".format(
24+
"\"{}\" ./configure.py --bootstrap".format(absolute_py_interpreter_path),
25+
"mkdir \"$$INSTALLDIR$$/bin\"",
26+
"cp -p ./ninja{} \"$$INSTALLDIR$$/bin/\"".format(
2727
".exe" if "win" in os_name(ctx) else "",
2828
),
2929
]

foreign_cc/built_tools/pkgconfig_build.bzl

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,10 @@ load(
1818
"get_tools_info",
1919
)
2020
load("//foreign_cc/private:detect_xcompile.bzl", "detect_xcompile")
21+
load(
22+
"//foreign_cc/private/framework:helpers.bzl",
23+
"escape_dquote_bash",
24+
)
2125
load("//foreign_cc/private/framework:platform.bzl", "os_name")
2226
load("//toolchains/native_tools:tool_access.bzl", "get_make_data")
2327

@@ -66,7 +70,7 @@ def _pkgconfig_tool_impl(ctx):
6670

6771
configure_options = [
6872
"--with-internal-glib",
69-
"--prefix=$$INSTALLDIR$$",
73+
"--prefix=\"$$INSTALLDIR$$\"",
7074
]
7175

7276
xcompile_options = detect_xcompile(ctx)
@@ -86,8 +90,8 @@ def _pkgconfig_tool_impl(ctx):
8690
configure_env = " ".join(["%s=\"%s\"" % (key, value) for key, value in env.items()])
8791
script = [
8892
"%s ./configure %s" % (configure_env, " ".join(configure_options)),
89-
"%s" % make_data.path,
90-
"%s install" % make_data.path,
93+
"\"%s\"" % make_data.path,
94+
"\"%s\" install" % make_data.path,
9195
]
9296

9397
if make_data.target:
@@ -186,4 +190,4 @@ def pkgconfig_tool(name, srcs, **kwargs):
186190
)
187191

188192
def _join_flags_list(workspace_name, flags):
189-
return " ".join([absolutize(workspace_name, flag) for flag in flags])
193+
return " ".join([escape_dquote_bash(absolutize(workspace_name, flag)) for flag in flags])

foreign_cc/built_tools/private/built_tools_framework.bzl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -124,7 +124,7 @@ def built_tool_rule_impl(ctx, script_lines, out_dir, mnemonic, additional_tools
124124
"##mkdirs## $$INSTALLDIR$$",
125125
"##mkdirs## $$BUILD_TMPDIR$$",
126126
"##copy_dir_contents_to_dir## ./{} $$BUILD_TMPDIR$$".format(root),
127-
"cd $$BUILD_TMPDIR$$",
127+
"cd \"$$BUILD_TMPDIR$$\"",
128128
]
129129

130130
script.append("##enable_tracing##")

foreign_cc/private/framework.bzl

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -629,7 +629,10 @@ def wrap_outputs(ctx, lib_name, configure_name, script_text, env_prelude, build_
629629
cleanup_on_success_function = create_function(
630630
ctx,
631631
"cleanup_on_success",
632-
"rm -rf $$BUILD_TMPDIR$$ $$EXT_BUILD_DEPS$$",
632+
"\n".join([
633+
"##rm_rf## $$BUILD_TMPDIR$$",
634+
"##rm_rf## $$EXT_BUILD_DEPS$$",
635+
]),
633636
)
634637
cleanup_on_failure_function = create_function(
635638
ctx,
@@ -665,8 +668,8 @@ def wrap_outputs(ctx, lib_name, configure_name, script_text, env_prelude, build_
665668
"export BUILD_SCRIPT=\"{}\"".format(build_script_file.path),
666669
"export BUILD_LOG=\"{}\"".format(build_log_file.path),
667670
# sometimes the log file is not created, we do not want our script to fail because of this
668-
"##touch## $$BUILD_LOG$$",
669-
"##redirect_out_err## $$BUILD_SCRIPT$$ $$BUILD_LOG$$",
671+
"##touch## \"$$BUILD_LOG$$\"",
672+
"##redirect_out_err## \"$$BUILD_SCRIPT$$\" \"$$BUILD_LOG$$\"",
670673
]
671674
build_command = "\n".join([
672675
shebang(ctx),
@@ -730,7 +733,7 @@ def _correct_path_variable(toolchain, env):
730733
# INCLUDE) needs windows path (for passing as arguments to compiler).
731734
prefix = "${EXT_BUILD_ROOT/$(printf '\072')/}/"
732735
else:
733-
prefix = "$EXT_BUILD_ROOT/"
736+
prefix = "\"$EXT_BUILD_ROOT\"/"
734737

735738
# external/path becomes $EXT_BUILD_ROOT/external/path
736739
path_paths = [prefix + path if path and path[1] != ":" else path for path in value.split(";")]

0 commit comments

Comments
 (0)