Skip to content

Commit 81b6848

Browse files
authored
Merge pull request #18822 from github/redsun82/rust-lint
Rust: strengthen linting script
2 parents 425fa0d + 292b962 commit 81b6848

File tree

2 files changed

+27
-7
lines changed

2 files changed

+27
-7
lines changed

rust/ast-generator/BUILD.bazel

+3-1
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,9 @@ write_file(
6666
'DST_DIR="$(dirname "$(rlocation "$1")")"',
6767
'mkdir -p "$DST_DIR/src/codegen/grammar"',
6868
] + [
69-
'cp -f --no-preserve=mode "$(rlocation "$%s")" "$DST_DIR/%s"' % item
69+
# using cat instead of cp to honor default umask
70+
# (also, macOS does not support `cp --no-preserve=mode`)
71+
'cat "$(rlocation "$%s")" > "$DST_DIR/%s"' % item
7072
for item in enumerate(_codegen_outs, 2)
7173
],
7274
is_executable = True,

rust/lint.py

+24-6
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,38 @@
1-
#!/bin/env python3
1+
#!/usr/bin/env python3
22

33
import subprocess
44
import pathlib
55
import shutil
66
import sys
77

8+
9+
def tool(name):
10+
ret = shutil.which(name)
11+
assert ret, f"no {name} binary found on `PATH`"
12+
return ret
13+
14+
815
this_dir = pathlib.Path(__file__).resolve().parent
916

10-
cargo = shutil.which("cargo")
11-
assert cargo, "no cargo binary found on `PATH`"
17+
cargo = tool("cargo")
18+
bazel = tool("bazel")
1219

1320
runs = []
14-
runs.append(subprocess.run([cargo, "fmt", "--all", "--quiet"], cwd=this_dir))
21+
22+
23+
def run(tool, args, *, cwd=this_dir):
24+
print("+", tool, args)
25+
runs.append(subprocess.run([tool] + args.split(), cwd=cwd))
26+
27+
28+
# make sure bazel-provided sources are put in tree for `cargo` to work with them
29+
run(bazel, "run ast-generator:inject-sources")
30+
run(cargo, "fmt --all --quiet")
1531

1632
for manifest in this_dir.rglob("Cargo.toml"):
1733
if not manifest.is_relative_to(this_dir / "ql") and not manifest.is_relative_to(this_dir / "integration-tests"):
18-
runs.append(subprocess.run([cargo, "clippy", "--fix", "--allow-dirty", "--allow-staged", "--quiet", "--", "-D", "warnings"],
19-
cwd=manifest.parent))
34+
run(cargo,
35+
"clippy --fix --allow-dirty --allow-staged --quiet -- -D warnings",
36+
cwd=manifest.parent)
37+
2038
sys.exit(max(r.returncode for r in runs))

0 commit comments

Comments
 (0)