Skip to content

Commit def1184

Browse files
redsun82Copilot
andcommitted
Rust: allow formatting without linting, fix codegen runfiles path
`lint.py --format-only` gives the upcoming `just format` verb a way to reformat without failing on pre-existing lint findings. codegen.sh looked up its runfiles via `external/ql+`, which only resolves in a main-repository layout. `../ql+` works from both, so codegen keeps working when the repository is consumed as a bazel dependency. Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
1 parent 278db14 commit def1184

2 files changed

Lines changed: 32 additions & 17 deletions

File tree

rust/codegen/codegen.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
set -eu
44

5-
source misc/bazel/runfiles.sh 2>/dev/null || source external/ql+/misc/bazel/runfiles.sh
5+
source misc/bazel/runfiles.sh 2>/dev/null || source ../ql+/misc/bazel/runfiles.sh
66

77
ast_generator="$(rlocation "$1")"
88
grammar_file="$(rlocation "$2")"

rust/lint.py

Lines changed: 31 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,15 @@
44
import pathlib
55
import shutil
66
import sys
7+
import argparse
8+
9+
10+
def options():
11+
parser = argparse.ArgumentParser(description="lint rust language pack code")
12+
parser.add_argument(
13+
"--format-only", action="store_true", help="Only apply formatting"
14+
)
15+
return parser.parse_args()
716

817

918
def tool(name):
@@ -12,27 +21,33 @@ def tool(name):
1221
return ret
1322

1423

15-
this_dir = pathlib.Path(__file__).resolve().parent
24+
def main():
25+
args = options()
26+
this_dir = pathlib.Path(__file__).resolve().parent
27+
28+
cargo = tool("cargo")
29+
bazel = tool("bazel")
1630

17-
cargo = tool("cargo")
18-
bazel = tool("bazel")
31+
runs = []
1932

20-
runs = []
33+
def run(tool, args, *, cwd=this_dir):
34+
print("+", tool, args)
35+
runs.append(subprocess.run([tool] + args.split(), cwd=cwd))
2136

2237

23-
def run(tool, args, *, cwd=this_dir):
24-
print("+", tool, args)
25-
runs.append(subprocess.run([tool] + args.split(), cwd=cwd))
38+
# make sure bazel-provided sources are put in tree for `cargo` to work with them
39+
run(bazel, "run ast-generator:inject-sources")
40+
run(cargo, "fmt --all --quiet")
2641

42+
if not args.format_only:
43+
for manifest in this_dir.rglob("Cargo.toml"):
44+
if not manifest.is_relative_to(this_dir / "ql") and not manifest.is_relative_to(this_dir / "integration-tests"):
45+
run(cargo,
46+
"clippy --fix --allow-dirty --allow-staged --quiet -- -D warnings",
47+
cwd=manifest.parent)
2748

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")
49+
return max(r.returncode for r in runs)
3150

32-
for manifest in this_dir.rglob("Cargo.toml"):
33-
if not manifest.is_relative_to(this_dir / "ql") and not manifest.is_relative_to(this_dir / "integration-tests"):
34-
run(cargo,
35-
"clippy --fix --allow-dirty --allow-staged --quiet -- -D warnings",
36-
cwd=manifest.parent)
3751

38-
sys.exit(max(r.returncode for r in runs))
52+
if __name__ == "__main__":
53+
sys.exit(main())

0 commit comments

Comments
 (0)