improve check::{Std, Rustc}
to handle clippy properly
Signed-off-by: onur-ozkan <work@onurozkan.dev>
This commit is contained in:
parent
d94e7ff065
commit
92ca0a6a04
@ -20,11 +20,22 @@ pub struct Std {
|
||||
///
|
||||
/// [`compile::Rustc`]: crate::core::build_steps::compile::Rustc
|
||||
crates: Vec<String>,
|
||||
/// Override `Builder::kind` on cargo invocations.
|
||||
///
|
||||
/// By default, `Builder::kind` is propagated as the subcommand 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.
|
||||
override_build_kind: Option<Kind>,
|
||||
}
|
||||
|
||||
impl Std {
|
||||
pub fn new(target: TargetSelection) -> Self {
|
||||
Self { target, crates: vec![] }
|
||||
Self::new_with_build_kind(target, None)
|
||||
}
|
||||
|
||||
pub fn new_with_build_kind(target: TargetSelection, kind: Option<Kind>) -> Self {
|
||||
Self { target, crates: vec![], override_build_kind: kind }
|
||||
}
|
||||
}
|
||||
|
||||
@ -38,7 +49,7 @@ fn should_run(run: ShouldRun<'_>) -> ShouldRun<'_> {
|
||||
|
||||
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, override_build_kind: None });
|
||||
}
|
||||
|
||||
fn run(self, builder: &Builder<'_>) {
|
||||
@ -53,7 +64,7 @@ fn run(self, builder: &Builder<'_>) {
|
||||
Mode::Std,
|
||||
SourceType::InTree,
|
||||
target,
|
||||
builder.kind,
|
||||
self.override_build_kind.unwrap_or(builder.kind),
|
||||
);
|
||||
|
||||
std_cargo(builder, target, compiler.stage, &mut cargo);
|
||||
@ -107,7 +118,7 @@ fn run(self, builder: &Builder<'_>) {
|
||||
Mode::Std,
|
||||
SourceType::InTree,
|
||||
target,
|
||||
builder.kind,
|
||||
self.override_build_kind.unwrap_or(builder.kind),
|
||||
);
|
||||
|
||||
// If we're not in stage 0, tests and examples will fail to compile
|
||||
@ -148,16 +159,31 @@ pub struct Rustc {
|
||||
///
|
||||
/// [`compile::Rustc`]: crate::core::build_steps::compile::Rustc
|
||||
crates: Vec<String>,
|
||||
/// Override `Builder::kind` on cargo invocations.
|
||||
///
|
||||
/// By default, `Builder::kind` is propagated as the subcommand 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.
|
||||
override_build_kind: Option<Kind>,
|
||||
}
|
||||
|
||||
impl Rustc {
|
||||
pub fn new(target: TargetSelection, builder: &Builder<'_>) -> Self {
|
||||
Self::new_with_build_kind(target, builder, None)
|
||||
}
|
||||
|
||||
pub fn new_with_build_kind(
|
||||
target: TargetSelection,
|
||||
builder: &Builder<'_>,
|
||||
kind: Option<Kind>,
|
||||
) -> Self {
|
||||
let crates = builder
|
||||
.in_tree_crates("rustc-main", Some(target))
|
||||
.into_iter()
|
||||
.map(|krate| krate.name.to_string())
|
||||
.collect();
|
||||
Self { target, crates }
|
||||
Self { target, crates, override_build_kind: kind }
|
||||
}
|
||||
}
|
||||
|
||||
@ -172,7 +198,7 @@ fn should_run(run: ShouldRun<'_>) -> ShouldRun<'_> {
|
||||
|
||||
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, override_build_kind: None });
|
||||
}
|
||||
|
||||
/// Builds the compiler.
|
||||
@ -193,7 +219,7 @@ fn run(self, builder: &Builder<'_>) {
|
||||
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_build_kind(target, self.override_build_kind));
|
||||
}
|
||||
|
||||
let mut cargo = builder::Cargo::new(
|
||||
@ -202,7 +228,7 @@ fn run(self, builder: &Builder<'_>) {
|
||||
Mode::Rustc,
|
||||
SourceType::InTree,
|
||||
target,
|
||||
builder.kind,
|
||||
self.override_build_kind.unwrap_or(builder.kind),
|
||||
);
|
||||
|
||||
rustc_cargo(builder, &mut cargo, target, &compiler);
|
||||
|
@ -200,7 +200,7 @@ fn run(self, builder: &Builder<'_>) {
|
||||
builder.ensure(compile::Std::new(compiler, compiler.host));
|
||||
builder.ensure(compile::Std::new(compiler, target));
|
||||
} else {
|
||||
builder.ensure(check::Std::new(target));
|
||||
builder.ensure(check::Std::new_with_build_kind(target, Some(Kind::Check)));
|
||||
}
|
||||
|
||||
let mut cargo = builder::Cargo::new(
|
||||
@ -267,7 +267,7 @@ fn run(self, builder: &Builder<'_>) -> Self::Output {
|
||||
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_build_kind(target, builder, Some(Kind::Check)));
|
||||
|
||||
let cargo = prepare_tool_cargo(
|
||||
builder,
|
||||
|
@ -689,7 +689,7 @@ fn pathset_for_paths_removing_matches(
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Copy, Clone, PartialEq, Eq, PartialOrd, Ord, ValueEnum)]
|
||||
#[derive(Debug, Copy, Clone, Eq, Hash, PartialEq, PartialOrd, Ord, ValueEnum)]
|
||||
pub enum Kind {
|
||||
#[value(alias = "b")]
|
||||
Build,
|
||||
|
Loading…
Reference in New Issue
Block a user