Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Rust: strengthen linting script #18822

Merged
merged 1 commit into from
Feb 24, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion rust/ast-generator/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,9 @@ write_file(
'DST_DIR="$(dirname "$(rlocation "$1")")"',
'mkdir -p "$DST_DIR/src/codegen/grammar"',
] + [
'cp -f --no-preserve=mode "$(rlocation "$%s")" "$DST_DIR/%s"' % item
# using cat instead of cp to honor default umask
# (also, macOS does not support `cp --no-preserve=mode`)
'cat "$(rlocation "$%s")" > "$DST_DIR/%s"' % item
for item in enumerate(_codegen_outs, 2)
],
is_executable = True,
Expand Down
30 changes: 24 additions & 6 deletions rust/lint.py
Original file line number Diff line number Diff line change
@@ -1,20 +1,38 @@
#!/bin/env python3
#!/usr/bin/env python3

import subprocess
import pathlib
import shutil
import sys


def tool(name):
ret = shutil.which(name)
assert ret, f"no {name} binary found on `PATH`"
return ret


this_dir = pathlib.Path(__file__).resolve().parent

cargo = shutil.which("cargo")
assert cargo, "no cargo binary found on `PATH`"
cargo = tool("cargo")
bazel = tool("bazel")

runs = []
runs.append(subprocess.run([cargo, "fmt", "--all", "--quiet"], cwd=this_dir))


def run(tool, args, *, cwd=this_dir):
print("+", tool, args)
runs.append(subprocess.run([tool] + args.split(), cwd=cwd))


# make sure bazel-provided sources are put in tree for `cargo` to work with them
run(bazel, "run ast-generator:inject-sources")
run(cargo, "fmt --all --quiet")

for manifest in this_dir.rglob("Cargo.toml"):
if not manifest.is_relative_to(this_dir / "ql") and not manifest.is_relative_to(this_dir / "integration-tests"):
runs.append(subprocess.run([cargo, "clippy", "--fix", "--allow-dirty", "--allow-staged", "--quiet", "--", "-D", "warnings"],
cwd=manifest.parent))
run(cargo,
"clippy --fix --allow-dirty --allow-staged --quiet -- -D warnings",
cwd=manifest.parent)

sys.exit(max(r.returncode for r in runs))