Skip to content

Commit 87b25ed

Browse files
authored
Fix all lint warnings (#214)
As per `trunk check --all`.
1 parent c196bc1 commit 87b25ed

16 files changed

+69
-57
lines changed

README.md

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@ llvm_register_toolchains()
7171

7272
And add the following section to your .bazelrc file:
7373

74-
```
74+
```sh
7575
# Not needed after https://github.com/bazelbuild/bazel/issues/7260 is closed
7676
build --incompatible_enable_cc_toolchain_resolution
7777

@@ -91,7 +91,7 @@ attributes to `llvm_toolchain`.
9191

9292
## Advanced Usage
9393

94-
#### Per host architecture LLVM version
94+
### Per host architecture LLVM version
9595

9696
LLVM does not come with distributions for all host architectures in each
9797
version. In particular patch versions often come with few prebuilt packages.
@@ -104,7 +104,7 @@ specified explicitly. This is like providing `llvm_version = "15.0.6"`, just
104104
like in the example on the top. However, here we provide two more entries that
105105
map their respective target to a distinct version:
106106

107-
```
107+
```starlark
108108
llvm_toolchain(
109109
name = "llvm_toolchain",
110110
llvm_versions = {
@@ -115,7 +115,7 @@ llvm_toolchain(
115115
)
116116
```
117117

118-
#### Customizations
118+
### Customizations
119119

120120
We currently offer limited customizability through attributes of the
121121
[llvm_toolchain\_\* rules](toolchain/rules.bzl). You can send us a PR to add
@@ -127,7 +127,7 @@ new compiler features, etc., my advice would be to look at the toolchain
127127
configurations generated by this repo, and copy-paste/edit to make your own in
128128
any package in your own workspace.
129129

130-
```
130+
```sh
131131
bazel query --output=build @llvm_toolchain//:all | grep -v -e '^#' -e '^ generator'
132132
```
133133

@@ -140,7 +140,7 @@ directory, and also create a wrapper script for clang such that the actual
140140
clang invocation is not through the symlinked path. See the files in the
141141
`@llvm_toolchain//:` package as a reference.
142142

143-
```
143+
```sh
144144
# See generated files for reference.
145145
ls -lR "$(bazel info output_base)/external/llvm_toolchain"
146146

@@ -158,7 +158,7 @@ See [bazel
158158
tutorial](https://docs.bazel.build/versions/main/tutorial/cc-toolchain-config.html)
159159
for how CC toolchains work in general.
160160

161-
#### Selecting Toolchains
161+
### Selecting Toolchains
162162

163163
If toolchains are registered (see Quickstart section above), you do not need to
164164
do anything special for bazel to find the toolchain. You may want to check once
@@ -172,7 +172,7 @@ For specifying unregistered toolchains on the command line, please use the
172172
We no longer support the `--crosstool_top=@llvm_toolchain//:toolchain` flag,
173173
and instead rely on the `--incompatible_enable_cc_toolchain_resolution` flag.
174174

175-
#### Bring Your Own LLVM
175+
### Bring Your Own LLVM
176176

177177
The following mechanisms are available for using an LLVM toolchain:
178178

@@ -204,7 +204,7 @@ The following mechanisms are available for using an LLVM toolchain:
204204
a toolchain root specified through the `toolchain_roots` attribute with an
205205
empty key.
206206

207-
#### Sysroots
207+
### Sysroots
208208

209209
A sysroot can be specified through the `sysroot` attribute. This can be either
210210
a path on the user's system, or a bazel `filegroup` like label. One way to
@@ -213,7 +213,7 @@ entire filesystem for the image you want. Another way is to use the build
213213
scripts provided by the [Chromium
214214
project](https://chromium.googlesource.com/chromium/src/+/HEAD/docs/linux/sysroot.md).
215215

216-
#### Cross-compilation
216+
### Cross-compilation
217217

218218
The toolchain supports cross-compilation if you bring your own sysroot. When
219219
cross-compiling, we link against the libstdc++ from the sysroot
@@ -231,14 +231,14 @@ Then, when cross-compiling, explicitly specify the toolchain with the sysroot
231231
and the target platform. For example, see the [WORKSPACE](tests/WORKSPACE) file and
232232
the [test script](tests/scripts/run_xcompile_tests.sh) for cross-compilation.
233233

234-
```
234+
```sh
235235
bazel build \
236236
--platforms=@com_grail_bazel_toolchain//platforms:linux-x86_64 \
237237
--extra_toolchains=@llvm_toolchain_with_sysroot//:cc-toolchain-x86_64-linux \
238238
//...
239239
```
240240

241-
#### Supporting New Target Platforms
241+
### Supporting New Target Platforms
242242

243243
The following is a rough (untested) list of steps:
244244

@@ -256,7 +256,7 @@ The following is a rough (untested) list of steps:
256256
`toolchain_roots` or `urls` attribute.
257257
6. Test your build.
258258

259-
#### Sandbox
259+
### Sandbox
260260

261261
Sandboxing the toolchain introduces a significant overhead (100ms per action,
262262
as of mid 2018). To overcome this, one can use
@@ -267,12 +267,12 @@ substitute templated paths to the toolchain as absolute paths. When running
267267
bazel actions, these paths will be available from inside the sandbox as part of
268268
the / read-only mount. Note that this will make your builds non-hermetic.
269269

270-
#### Compatibility
270+
### Compatibility
271271

272272
The toolchain is tested to work with `rules_go`, `rules_rust`, and
273273
`rules_foreign_cc`.
274274

275-
#### Accessing tools
275+
### Accessing tools
276276

277277
The LLVM distribution also provides several tools like `clang-format`. You can
278278
depend on these tools directly in the bin directory of the distribution. When

tests/scripts/bazel.sh

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,12 @@
1212
# See the License for the specific language governing permissions and
1313
# limitations under the License.
1414

15-
os="$(uname -s | tr "[:upper:]" "[:lower:]")"
15+
# shellcheck shell=bash
16+
17+
short_uname="$(uname -s)"
18+
readonly short_uname
19+
20+
os="$(echo "${short_uname}" | tr "[:upper:]" "[:lower:]")"
1621
readonly os
1722

1823
arch="$(uname -m)"
@@ -47,7 +52,7 @@ common_test_args=(
4752

4853
# TODO: Remove this once we no longer support bazel 6.x.
4954
# This feature isn't intentionally supported on macOS.
50-
if [[ $(uname -s) == 'Darwin' ]]; then
55+
if [[ ${short_uname} == 'Darwin' ]]; then
5156
common_test_args+=(--features=-supports_dynamic_linker)
5257
fi
5358

tests/scripts/centos_test.sh

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,9 @@
1313
# See the License for the specific language governing permissions and
1414
# limitations under the License.
1515

16+
# Disable the unreachable code warning because the test is disabled.
17+
# shellcheck disable=SC2317
18+
1619
echo "This test is disabled because our supported versions of LLVM do not work with CentOS."
1720
exit 1
1821

tests/scripts/run_external_tests.sh

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -23,13 +23,12 @@ cd "${scripts_dir}"
2323

2424
# Generate some files needed for the tests.
2525
"${bazel}" query "${common_args[@]}" @io_bazel_rules_go//tests/core/cgo:dylib_test >/dev/null
26-
if [[ $USE_BZLMOD == "true" ]]; then
26+
if [[ ${USE_BZLMOD} == "true" ]]; then
2727
"$("${bazel}" info output_base)/external/rules_go~0.41.0/tests/core/cgo/generate_imported_dylib.sh"
2828
else
2929
"$("${bazel}" info output_base)/external/io_bazel_rules_go/tests/core/cgo/generate_imported_dylib.sh"
3030
fi
3131

32-
set -x
3332
test_args=(
3433
"${common_test_args[@]}"
3534
# Fix LLVM version to be 14.0.0 because that's the last known version with
@@ -50,12 +49,14 @@ test_args=(
5049
# @rules_rust//test/unit/{native_deps,linkstamps,interleaved_cc_info}:all
5150
# but under bzlmod the linkstamp tests fail due to the fact we are currently
5251
# overriding rules_rust locally as its not yet released in the BCR
52+
# shellcheck disable=SC2207
53+
absl_targets=($("${bazel}" query "${common_args[@]}" 'attr(timeout, short, tests(@com_google_absl//absl/...))'))
5354
"${bazel}" --bazelrc=/dev/null test "${test_args[@]}" -- \
5455
//foreign:pcre \
5556
@openssl//:libssl \
5657
@rules_rust//test/unit/interleaved_cc_info:all \
5758
@io_bazel_rules_go//tests/core/cgo:all \
5859
-@io_bazel_rules_go//tests/core/cgo:cc_libs_test \
5960
-@io_bazel_rules_go//tests/core/cgo:external_includes_test \
60-
$("${bazel}" query 'attr(timeout, short, tests(@com_google_absl//absl/...))') \
61+
"${absl_targets[@]}" \
6162
-@com_google_absl//absl/time/internal/cctz:time_zone_format_test

tests/scripts/run_tests.sh

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -18,15 +18,15 @@ set -euo pipefail
1818
toolchain_name=""
1919

2020
while getopts "t:h" opt; do
21-
case "$opt" in
22-
"t") toolchain_name="$OPTARG" ;;
21+
case "${opt}" in
22+
"t") toolchain_name="${OPTARG}" ;;
2323
"h")
2424
echo "Usage:"
2525
echo "-t - Toolchain name to use for testing; default is llvm_toolchain"
2626
exit 2
2727
;;
28-
"?")
29-
echo "invalid option: -$OPTARG"
28+
*)
29+
echo "invalid option: -${OPTARG}"
3030
exit 1
3131
;;
3232
esac

tests/scripts/suse_leap_test.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ toolchain="@llvm_toolchain_13_0_0//:cc-toolchain-x86_64-linux"
2525
git_root=$(git rev-parse --show-toplevel)
2626
readonly git_root
2727

28-
echo "git root: $git_root"
28+
echo "git root: ${git_root}"
2929

3030
for image in "${images[@]}"; do
3131
docker pull "${image}"

tests/scripts/suse_tumbleweed_test.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ toolchain="@llvm_toolchain_13_0_0//:cc-toolchain-x86_64-linux"
2525
git_root=$(git rev-parse --show-toplevel)
2626
readonly git_root
2727

28-
echo "git root: $git_root"
28+
echo "git root: ${git_root}"
2929

3030
for image in "${images[@]}"; do
3131
docker pull "${image}"

toolchain/cc_wrapper.sh.tpl

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
1414
# See the License for the specific language governing permissions and
1515
# limitations under the License.
16-
#
16+
1717
# OS X relpath is not really working. This is a wrapper script around gcc
1818
# to simulate relpath behavior.
1919
#
@@ -24,7 +24,9 @@
2424
#
2525
# See https://blogs.oracle.com/dipol/entry/dynamic_libraries_rpath_and_mac
2626
# on how to set those paths for Mach-O binaries.
27-
#
27+
28+
# shellcheck disable=SC1083
29+
2830
set -eu
2931

3032
# See note in toolchain/internal/configure.bzl where we define
@@ -43,6 +45,6 @@ elif [[ ${BASH_SOURCE[0]} == "/"* ]]; then
4345
clang="${execroot_path}/%{toolchain_path_prefix}bin/clang"
4446
exec "${clang}" "${@}"
4547
else
46-
echo >&2 "ERROR: could not find clang; PWD=\"$(pwd)\"; PATH=\"${PATH}\"."
48+
echo >&2 "ERROR: could not find clang; PWD=\"${PWD}\"; PATH=\"${PATH}\"."
4749
exit 5
4850
fi

toolchain/internal/common.bzl

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -41,8 +41,8 @@ def _linux_dist(rctx):
4141
if res.return_code:
4242
fail("Failed to detect machine architecture: \n%s\n%s" % (res.stdout, res.stderr))
4343
info = {}
44-
for l in res.stdout.splitlines():
45-
parts = l.split("=", 1)
44+
for line in res.stdout.splitlines():
45+
parts = line.split("=", 1)
4646
info[parts[0]] = parts[1]
4747

4848
distname = info["ID"].strip('\"')
@@ -122,12 +122,12 @@ def host_os_arch_dict_value(rctx, attr_name, debug = False):
122122

123123
key2 = os_arch_pair(os(rctx), arch(rctx))
124124
if debug:
125-
print("`%s` attribute missing for key '%s' in repository '%s'; checking with key '%s'" % (attr_name, key1, rctx.name, key2))
125+
print("`%s` attribute missing for key '%s' in repository '%s'; checking with key '%s'" % (attr_name, key1, rctx.name, key2)) # buildifier: disable=print
126126
if key2 in d:
127127
return (key2, d.get(key2))
128128

129129
if debug:
130-
print("`%s` attribute missing for key '%s' in repository '%s'; checking with key ''" % (attr_name, key2, rctx.name))
130+
print("`%s` attribute missing for key '%s' in repository '%s'; checking with key ''" % (attr_name, key2, rctx.name)) # buildifier: disable=print
131131
return ("", d.get("")) # Fallback to empty key.
132132

133133
def canonical_dir_path(path):
@@ -147,10 +147,10 @@ def pkg_path_from_label(label):
147147
else:
148148
return label.package
149149

150-
def list_to_string(l):
151-
if l == None:
150+
def list_to_string(ls):
151+
if ls == None:
152152
return "None"
153-
return "[{}]".format(", ".join(["\"{}\"".format(d) for d in l]))
153+
return "[{}]".format(", ".join(["\"{}\"".format(d) for d in ls]))
154154

155155
def attr_dict(attr):
156156
# Returns a mutable dict of attr values from the struct. This is useful to

toolchain/internal/configure.bzl

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -42,12 +42,6 @@ load(
4242
# workspace builds, there is never a @@ in labels.
4343
BZLMOD_ENABLED = "@@" in str(Label("//:unused"))
4444

45-
def _include_dirs_str(rctx, key):
46-
dirs = rctx.attr.cxx_builtin_include_directories.get(key)
47-
if not dirs:
48-
return ""
49-
return ("\n" + 12 * " ").join(["\"%s\"," % d for d in dirs])
50-
5145
def llvm_config_impl(rctx):
5246
_check_os_arch_keys(rctx.attr.sysroot)
5347
_check_os_arch_keys(rctx.attr.cxx_builtin_include_directories)

0 commit comments

Comments
 (0)