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

Implement x.py test src/tools/clippy --bless #84189

Merged
merged 1 commit into from
Apr 29, 2021
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
13 changes: 13 additions & 0 deletions Cargo.lock
Original file line number Diff line number Diff line change
Expand Up @@ -599,6 +599,19 @@ dependencies = [
name = "clippy-mini-macro-test"
version = "0.2.0"

[[package]]
name = "clippy_dev"
version = "0.0.1"
dependencies = [
"bytecount",
"clap",
"itertools 0.9.0",
"opener",
"regex",
"shell-escape",
"walkdir",
]

[[package]]
name = "clippy_lints"
version = "0.1.53"
Expand Down
1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ members = [
"src/rustdoc-json-types",
"src/tools/cargotest",
"src/tools/clippy",
"src/tools/clippy/clippy_dev",
"src/tools/compiletest",
"src/tools/error_index_generator",
"src/tools/linkchecker",
Expand Down
5 changes: 5 additions & 0 deletions src/bootstrap/builder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1627,6 +1627,11 @@ impl Cargo {
pub fn add_rustc_lib_path(&mut self, builder: &Builder<'_>, compiler: Compiler) {
builder.add_rustc_lib_path(compiler, &mut self.command);
}

pub fn current_dir(&mut self, dir: &Path) -> &mut Cargo {
self.command.current_dir(dir);
self
}
}

impl From<Cargo> for Command {
Expand Down
20 changes: 20 additions & 0 deletions src/bootstrap/test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -632,6 +632,26 @@ impl Step for Clippy {

cargo.add_rustc_lib_path(builder, compiler);

if builder.try_run(&mut cargo.into()) {
// The tests succeeded; nothing to do.
return;
}

if !builder.config.cmd.bless() {
std::process::exit(1);
}

let mut cargo = builder.cargo(compiler, Mode::ToolRustc, SourceType::InTree, host, "run");
cargo.arg("-p").arg("clippy_dev");
// clippy_dev gets confused if it can't find `clippy/Cargo.toml`
cargo.current_dir(&builder.src.join("src").join("tools").join("clippy"));
if builder.config.rust_optimize {
cargo.env("PROFILE", "release");
} else {
cargo.env("PROFILE", "debug");
}
cargo.arg("--");
cargo.arg("bless");
builder.run(&mut cargo.into());
}
}
Expand Down
4 changes: 2 additions & 2 deletions src/tools/clippy/clippy_dev/src/new_lint.rs
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ pub fn create(pass: Option<&str>, lint_name: Option<&str>, category: Option<&str
create_test(&lint).context("Unable to create a test for the new lint")
}

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

fn create_test(lint: &LintData) -> io::Result<()> {
fn create_test(lint: &LintData<'_>) -> io::Result<()> {
fn create_project_layout<P: Into<PathBuf>>(lint_name: &str, location: P, case: &str, hint: &str) -> io::Result<()> {
let mut path = location.into().join(case);
fs::create_dir(&path)?;
Expand Down
9 changes: 1 addition & 8 deletions src/tools/clippy/tests/compile-test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -83,14 +83,7 @@ fn default_config() -> compiletest::Config {
third_party_crates(),
));

config.build_base = if cargo::is_rustc_test_suite() {
// This make the stderr files go to clippy OUT_DIR on rustc repo build dir
let mut path = PathBuf::from(env!("OUT_DIR"));
path.push("test_build_base");
path
} else {
host_lib().join("test_build_base")
};
config.build_base = host_lib().join("test_build_base");
config.rustc_path = clippy_driver_path();
config
}
Expand Down