Skip to content

Commit

Permalink
improve check::{Std, Rustc} to handle clippy properly
Browse files Browse the repository at this point in the history
Signed-off-by: onur-ozkan <[email protected]>
  • Loading branch information
onur-ozkan committed Jul 27, 2024
1 parent d94e7ff commit 4b87b59
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 8 deletions.
45 changes: 38 additions & 7 deletions src/bootstrap/src/core/build_steps/check.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,11 +20,22 @@ pub struct Std {
///
/// [`compile::Rustc`]: crate::core::build_steps::compile::Rustc
crates: Vec<String>,
/// Whether to force `Kind::Check` on cargo invocations.
///
/// By default, `Builder::kind` is propagated to the cargo invocations. However, there are cases
/// when this is not desirable. For example, when running `x clippy $tool_name`, passing `Builder::kind`
/// to cargo invocations would run clippy on the entire compiler and library, which is not useful if
/// we only want to lint a few crates with specific rules.
force_check: bool,
}

impl Std {
pub fn new(target: TargetSelection) -> Self {
Self { target, crates: vec![] }
Self { target, crates: vec![], force_check: false }
}

pub fn new_with_force_check_flag(target: TargetSelection, force_check: bool) -> Self {
Self { target, crates: vec![], force_check }
}
}

Expand All @@ -38,7 +49,7 @@ impl Step for Std {

fn make_run(run: RunConfig<'_>) {
let crates = run.make_run_crates(Alias::Library);
run.builder.ensure(Std { target: run.target, crates });
run.builder.ensure(Std { target: run.target, crates, force_check: false });
}

fn run(self, builder: &Builder<'_>) {
Expand All @@ -53,7 +64,7 @@ impl Step for Std {
Mode::Std,
SourceType::InTree,
target,
builder.kind,
if self.force_check { Kind::Check } else { builder.kind },
);

std_cargo(builder, target, compiler.stage, &mut cargo);
Expand Down Expand Up @@ -148,6 +159,13 @@ pub struct Rustc {
///
/// [`compile::Rustc`]: crate::core::build_steps::compile::Rustc
crates: Vec<String>,
/// Whether to force `Kind::Check` on cargo invocations.
///
/// By default, `Builder::kind` is propagated to the cargo invocations. However, there are cases
/// when this is not desirable. For example, when running `x clippy $tool_name`, passing `Builder::kind`
/// to cargo invocations would run clippy on the entire compiler and library, which is not useful if
/// we only want to lint a few crates with specific rules.
force_check: bool,
}

impl Rustc {
Expand All @@ -157,7 +175,20 @@ impl Rustc {
.into_iter()
.map(|krate| krate.name.to_string())
.collect();
Self { target, crates }
Self { target, crates, force_check: false }
}

pub fn new_with_force_check_flag(
target: TargetSelection,
builder: &Builder<'_>,
force_check: bool,
) -> Self {
let crates = builder
.in_tree_crates("rustc-main", Some(target))
.into_iter()
.map(|krate| krate.name.to_string())
.collect();
Self { target, crates, force_check }
}
}

Expand All @@ -172,7 +203,7 @@ impl Step for Rustc {

fn make_run(run: RunConfig<'_>) {
let crates = run.make_run_crates(Alias::Compiler);
run.builder.ensure(Rustc { target: run.target, crates });
run.builder.ensure(Rustc { target: run.target, crates, force_check: false });
}

/// Builds the compiler.
Expand All @@ -193,7 +224,7 @@ impl Step for Rustc {
builder.ensure(crate::core::build_steps::compile::Std::new(compiler, compiler.host));
builder.ensure(crate::core::build_steps::compile::Std::new(compiler, target));
} else {
builder.ensure(Std::new(target));
builder.ensure(Std::new_with_force_check_flag(target, self.force_check));
}

let mut cargo = builder::Cargo::new(
Expand All @@ -202,7 +233,7 @@ impl Step for Rustc {
Mode::Rustc,
SourceType::InTree,
target,
builder.kind,
if self.force_check { Kind::Check } else { builder.kind },
);

rustc_cargo(builder, &mut cargo, target, &compiler);
Expand Down
2 changes: 1 addition & 1 deletion src/bootstrap/src/core/build_steps/clippy.rs
Original file line number Diff line number Diff line change
Expand Up @@ -267,7 +267,7 @@ macro_rules! lint_any {
let compiler = builder.compiler(builder.top_stage, builder.config.build);
let target = self.target;

builder.ensure(check::Rustc::new(target, builder));
builder.ensure(check::Rustc::new_with_force_check_flag(target, builder, true));

let cargo = prepare_tool_cargo(
builder,
Expand Down

0 comments on commit 4b87b59

Please sign in to comment.