mirror of
https://github.com/openai/codex.git
synced 2026-11-08 20:40:33 +00:00
ci: run argument-comment-lint through bazel package tests
This commit is contained in:
@@ -0,0 +1,19 @@
|
||||
load("@rules_rust//rust:defs.bzl", "rust_binary")
|
||||
|
||||
filegroup(
|
||||
name = "runtime-files",
|
||||
srcs = [
|
||||
"argument-comment-lint",
|
||||
"run-prebuilt-linter.py",
|
||||
"wrapper_common.py",
|
||||
],
|
||||
visibility = ["//visibility:public"],
|
||||
)
|
||||
|
||||
rust_binary(
|
||||
name = "argument-comment-lint-bazel-runner",
|
||||
crate_name = "argument_comment_lint_bazel_runner",
|
||||
crate_root = "bazel_runner.rs",
|
||||
srcs = ["bazel_runner.rs"],
|
||||
visibility = ["//visibility:public"],
|
||||
)
|
||||
@@ -85,7 +85,9 @@ rustup toolchain install nightly-2025-09-18 \
|
||||
|
||||
The checked-in DotSlash file lives at `tools/argument-comment-lint/argument-comment-lint`.
|
||||
`run-prebuilt-linter.py` resolves that file via `dotslash` and is the path used by
|
||||
`just clippy`, `just argument-comment-lint`, and the Rust CI job. The
|
||||
`just clippy` and `just argument-comment-lint`. Bazel-backed CI now drives the
|
||||
same wrapper through package-owned test targets tagged `argument-comment-lint`.
|
||||
The
|
||||
source-build path remains available in `run.py` for people
|
||||
iterating on the lint crate itself.
|
||||
|
||||
@@ -128,6 +130,7 @@ Run the lint against `codex-rs` from the repo root:
|
||||
```bash
|
||||
./tools/argument-comment-lint/run-prebuilt-linter.py -p codex-core
|
||||
just argument-comment-lint -p codex-core
|
||||
bazel test --build_tests_only --test_tag_filters=argument-comment-lint //codex-rs/...
|
||||
```
|
||||
|
||||
If no package selection is provided, `run-prebuilt-linter.py` defaults to checking the
|
||||
|
||||
@@ -0,0 +1,124 @@
|
||||
use std::env;
|
||||
use std::path::Path;
|
||||
use std::process::Command;
|
||||
use std::process::ExitCode;
|
||||
|
||||
fn main() -> ExitCode {
|
||||
match run() {
|
||||
Ok(code) => code,
|
||||
Err(err) => {
|
||||
eprintln!("{err}");
|
||||
ExitCode::from(1)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
fn run() -> Result<ExitCode, String> {
|
||||
let manifest = env::var("ARGUMENT_COMMENT_LINT_MANIFEST")
|
||||
.map_err(|_| "ARGUMENT_COMMENT_LINT_MANIFEST must be set".to_string())?;
|
||||
let workspace_dir = env::current_dir().map_err(|err| format!("failed to get cwd: {err}"))?;
|
||||
let wrapper = find_repo_root(&workspace_dir)?
|
||||
.join("tools")
|
||||
.join("argument-comment-lint")
|
||||
.join("run-prebuilt-linter.py");
|
||||
|
||||
let python = if cfg!(windows) { "python" } else { "python3" };
|
||||
let mut command = Command::new(python);
|
||||
command.arg(&wrapper);
|
||||
command.arg("--manifest-path");
|
||||
command.arg(&manifest);
|
||||
|
||||
// Keep Linux on the narrower target set for now to match the current CI
|
||||
// rollout, while macOS and Windows continue to exercise all targets.
|
||||
if cfg!(target_os = "linux") {
|
||||
command.args(["--", "--lib", "--bins"]);
|
||||
}
|
||||
|
||||
if env::var_os("CARGO_TARGET_DIR").is_none()
|
||||
&& let Some(test_tmpdir) = env::var_os("TEST_TMPDIR")
|
||||
{
|
||||
let sanitized_manifest = manifest.replace('/', "_").replace('\\', "_");
|
||||
let target_dir =
|
||||
Path::new(&test_tmpdir).join(format!("argument-comment-lint-{sanitized_manifest}"));
|
||||
command.env("CARGO_TARGET_DIR", target_dir);
|
||||
}
|
||||
|
||||
if let Some(cargo) = cargo_binary() {
|
||||
let cargo_dir = cargo
|
||||
.parent()
|
||||
.ok_or_else(|| format!("failed to resolve cargo directory from {}", cargo.display()))?;
|
||||
let existing_path = env::var_os("PATH").unwrap_or_default();
|
||||
let mut paths = vec![cargo_dir.to_path_buf()];
|
||||
paths.extend(env::split_paths(&existing_path));
|
||||
let joined_paths =
|
||||
env::join_paths(paths).map_err(|err| format!("failed to build PATH: {err}"))?;
|
||||
command.env("PATH", joined_paths);
|
||||
command.env("CARGO", cargo);
|
||||
}
|
||||
|
||||
let status = command
|
||||
.status()
|
||||
.map_err(|err| format!("failed to execute {python}: {err}"))?;
|
||||
Ok(status
|
||||
.code()
|
||||
.and_then(|code| u8::try_from(code).ok())
|
||||
.map_or_else(|| ExitCode::from(1), ExitCode::from))
|
||||
}
|
||||
|
||||
fn find_repo_root(cwd: &Path) -> Result<&Path, String> {
|
||||
if cwd
|
||||
.join("tools")
|
||||
.join("argument-comment-lint")
|
||||
.join("run-prebuilt-linter.py")
|
||||
.is_file()
|
||||
{
|
||||
return Ok(cwd);
|
||||
}
|
||||
|
||||
let Some(parent) = cwd.parent() else {
|
||||
return Err(format!(
|
||||
"argument-comment wrapper not found relative to {}",
|
||||
cwd.display()
|
||||
));
|
||||
};
|
||||
if parent
|
||||
.join("tools")
|
||||
.join("argument-comment-lint")
|
||||
.join("run-prebuilt-linter.py")
|
||||
.is_file()
|
||||
{
|
||||
return Ok(parent);
|
||||
}
|
||||
|
||||
Err(format!(
|
||||
"argument-comment wrapper not found relative to {}",
|
||||
cwd.display()
|
||||
))
|
||||
}
|
||||
|
||||
fn cargo_binary() -> Option<std::path::PathBuf> {
|
||||
for var in ["HOME", "USERPROFILE"] {
|
||||
if let Some(home) = env::var_os(var) {
|
||||
let cargo_bin = Path::new(&home).join(".cargo").join("bin");
|
||||
let candidate = cargo_bin.join(if cfg!(windows) { "cargo.exe" } else { "cargo" });
|
||||
if candidate.is_file() {
|
||||
return Some(candidate);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if let Ok(cwd) = env::current_dir() {
|
||||
for ancestor in cwd.ancestors() {
|
||||
let candidate = ancestor.join(".cargo").join("bin").join(if cfg!(windows) {
|
||||
"cargo.exe"
|
||||
} else {
|
||||
"cargo"
|
||||
});
|
||||
if candidate.is_file() {
|
||||
return Some(candidate);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
None
|
||||
}
|
||||
@@ -83,6 +83,26 @@ class WrapperCommonTest(unittest.TestCase):
|
||||
],
|
||||
)
|
||||
|
||||
def test_explicit_package_manifest_does_not_force_workspace(self) -> None:
|
||||
parsed = wrapper_common.parse_wrapper_args(
|
||||
[
|
||||
"--manifest-path",
|
||||
"/tmp/custom/Cargo.toml",
|
||||
]
|
||||
)
|
||||
final_args = wrapper_common.build_final_args(parsed, Path("/repo/codex-rs/Cargo.toml"))
|
||||
|
||||
self.assertEqual(
|
||||
final_args,
|
||||
[
|
||||
"--no-deps",
|
||||
"--manifest-path",
|
||||
"/tmp/custom/Cargo.toml",
|
||||
"--",
|
||||
"--all-targets",
|
||||
],
|
||||
)
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
unittest.main()
|
||||
|
||||
@@ -107,7 +107,7 @@ def build_final_args(parsed: ParsedWrapperArgs, manifest_path: Path) -> list[str
|
||||
|
||||
if not parsed.has_manifest_path:
|
||||
final_args.extend(["--manifest-path", str(manifest_path)])
|
||||
if not parsed.has_package_selection:
|
||||
if not parsed.has_package_selection and not parsed.has_manifest_path:
|
||||
final_args.append("--workspace")
|
||||
if not parsed.has_no_deps:
|
||||
final_args.append("--no-deps")
|
||||
|
||||
Reference in New Issue
Block a user