Skip to content

Commit 8c25e27

Browse files
committed
Implement x.py test src/tools/clippy --bless
- Add clippy_dev to the rust workspace Before, it would give an error that it wasn't either included or excluded from the workspace: ``` error: current package believes it's in a workspace when it's not: current: /home/joshua/rustc/src/tools/clippy/clippy_dev/Cargo.toml workspace: /home/joshua/rustc/Cargo.toml this may be fixable by adding `src/tools/clippy/clippy_dev` to the `workspace.members` array of the manifest located at: /home/joshua/rustc/Cargo.toml Alternatively, to keep it out of the workspace, add the package to the `workspace.exclude` array, or add an empty `[workspace]` table to the package's manifest. ``` - Change clippy's copy of compiletest not to special-case rust-lang/rust. Using OUT_DIR confused `clippy_dev` and it couldn't find the test outputs. This is one of the reasons why `cargo dev bless` used to silently do nothing (the others were that `CARGO_TARGET_DIR` and `PROFILE` weren't set appropriately). - Run clippy_dev on test failure I tested this by removing a couple lines from a stderr file, and they were correctly replaced. - Fix clippy_dev warnings
1 parent 2e7eb85 commit 8c25e27

File tree

6 files changed

+42
-10
lines changed

6 files changed

+42
-10
lines changed

Diff for: Cargo.lock

+13
Original file line numberDiff line numberDiff line change
@@ -599,6 +599,19 @@ dependencies = [
599599
name = "clippy-mini-macro-test"
600600
version = "0.2.0"
601601

602+
[[package]]
603+
name = "clippy_dev"
604+
version = "0.0.1"
605+
dependencies = [
606+
"bytecount",
607+
"clap",
608+
"itertools 0.9.0",
609+
"opener",
610+
"regex",
611+
"shell-escape",
612+
"walkdir",
613+
]
614+
602615
[[package]]
603616
name = "clippy_lints"
604617
version = "0.1.53"

Diff for: Cargo.toml

+1
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ members = [
77
"src/rustdoc-json-types",
88
"src/tools/cargotest",
99
"src/tools/clippy",
10+
"src/tools/clippy/clippy_dev",
1011
"src/tools/compiletest",
1112
"src/tools/error_index_generator",
1213
"src/tools/linkchecker",

Diff for: src/bootstrap/builder.rs

+5
Original file line numberDiff line numberDiff line change
@@ -1627,6 +1627,11 @@ impl Cargo {
16271627
pub fn add_rustc_lib_path(&mut self, builder: &Builder<'_>, compiler: Compiler) {
16281628
builder.add_rustc_lib_path(compiler, &mut self.command);
16291629
}
1630+
1631+
pub fn current_dir(&mut self, dir: &Path) -> &mut Cargo {
1632+
self.command.current_dir(dir);
1633+
self
1634+
}
16301635
}
16311636

16321637
impl From<Cargo> for Command {

Diff for: src/bootstrap/test.rs

+20
Original file line numberDiff line numberDiff line change
@@ -632,6 +632,26 @@ impl Step for Clippy {
632632

633633
cargo.add_rustc_lib_path(builder, compiler);
634634

635+
if builder.try_run(&mut cargo.into()) {
636+
// The tests succeeded; nothing to do.
637+
return;
638+
}
639+
640+
if !builder.config.cmd.bless() {
641+
std::process::exit(1);
642+
}
643+
644+
let mut cargo = builder.cargo(compiler, Mode::ToolRustc, SourceType::InTree, host, "run");
645+
cargo.arg("-p").arg("clippy_dev");
646+
// clippy_dev gets confused if it can't find `clippy/Cargo.toml`
647+
cargo.current_dir(&builder.src.join("src").join("tools").join("clippy"));
648+
if builder.config.rust_optimize {
649+
cargo.env("PROFILE", "release");
650+
} else {
651+
cargo.env("PROFILE", "debug");
652+
}
653+
cargo.arg("--");
654+
cargo.arg("bless");
635655
builder.run(&mut cargo.into());
636656
}
637657
}

Diff for: src/tools/clippy/clippy_dev/src/new_lint.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ pub fn create(pass: Option<&str>, lint_name: Option<&str>, category: Option<&str
4444
create_test(&lint).context("Unable to create a test for the new lint")
4545
}
4646

47-
fn create_lint(lint: &LintData) -> io::Result<()> {
47+
fn create_lint(lint: &LintData<'_>) -> io::Result<()> {
4848
let (pass_type, pass_lifetimes, pass_import, context_import) = match lint.pass {
4949
"early" => ("EarlyLintPass", "", "use rustc_ast::ast::*;", "EarlyContext"),
5050
"late" => ("LateLintPass", "<'_>", "use rustc_hir::*;", "LateContext"),
@@ -68,7 +68,7 @@ fn create_lint(lint: &LintData) -> io::Result<()> {
6868
write_file(lint.project_root.join(&lint_path), lint_contents.as_bytes())
6969
}
7070

71-
fn create_test(lint: &LintData) -> io::Result<()> {
71+
fn create_test(lint: &LintData<'_>) -> io::Result<()> {
7272
fn create_project_layout<P: Into<PathBuf>>(lint_name: &str, location: P, case: &str, hint: &str) -> io::Result<()> {
7373
let mut path = location.into().join(case);
7474
fs::create_dir(&path)?;

Diff for: src/tools/clippy/tests/compile-test.rs

+1-8
Original file line numberDiff line numberDiff line change
@@ -83,14 +83,7 @@ fn default_config() -> compiletest::Config {
8383
third_party_crates(),
8484
));
8585

86-
config.build_base = if cargo::is_rustc_test_suite() {
87-
// This make the stderr files go to clippy OUT_DIR on rustc repo build dir
88-
let mut path = PathBuf::from(env!("OUT_DIR"));
89-
path.push("test_build_base");
90-
path
91-
} else {
92-
host_lib().join("test_build_base")
93-
};
86+
config.build_base = host_lib().join("test_build_base");
9487
config.rustc_path = clippy_driver_path();
9588
config
9689
}

0 commit comments

Comments
 (0)