Skip to content

Commit

Permalink
cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
jyn514 committed Jul 24, 2021
1 parent a6f8a1d commit c47f73b
Show file tree
Hide file tree
Showing 8 changed files with 59 additions and 71 deletions.
57 changes: 31 additions & 26 deletions src/bootstrap/builder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -70,17 +70,6 @@ pub(crate) trait Step: 'static + Clone + Debug + PartialEq + Eq + Hash {

fn info(_step_info: &mut StepInfo<'_, '_, Self>);

/// The path that should be used on the command line to run this step.
fn path(&self, builder: &Builder<'_>) -> PathBuf {
let paths = Self::should_run(ShouldRun::new(builder)).paths;
paths.iter().map(|pathset| pathset.path(builder)).next().expect("no paths for step")
}

// /// The stage that should be passed to x.py to run this step.
// fn stage(&self, builder: &Builder<'_>) -> u32 {
// builder.top_stage
// }

/// Primary function to execute this rule. Can call `builder.ensure()`
/// with other steps to run those.
fn run(self, builder: &Builder<'_>) -> Self::Output;
Expand Down Expand Up @@ -1752,6 +1741,7 @@ pub(crate) struct StepInfo<'a, 'b, S> {
host: Option<TargetSelection>,
target: Option<TargetSelection>,
cmd: Option<Kind>,
path: Option<PathBuf>,
}

impl<'a> From<Compiler> for Cow<'a, Compiler> {
Expand All @@ -1768,7 +1758,16 @@ impl<'a> From<&'a Compiler> for Cow<'a, Compiler> {

impl<'a, 'b, S> StepInfo<'a, 'b, S> {
pub(crate) fn new(builder: &'a Builder<'b>, step: &'a S) -> Self {
Self { builder, step, compiler: None, stage: None, host: None, target: None, cmd: None }
Self {
builder,
step,
compiler: None,
stage: None,
host: None,
target: None,
cmd: None,
path: None,
}
}

pub(crate) fn compiler(&mut self, val: impl Into<Cow<'a, Compiler>>) -> &mut Self {
Expand Down Expand Up @@ -1813,6 +1812,14 @@ impl<'a, 'b, S> StepInfo<'a, 'b, S> {
self
}

pub(crate) fn path(&mut self, val: PathBuf) -> &mut Self {
if self.path.is_some() {
panic!("cannot overwrite path");
}
self.path = Some(val);
self
}

/// Print a command that will run the current step.
///
/// This serves two purposes:
Expand All @@ -1822,33 +1829,31 @@ impl<'a, 'b, S> StepInfo<'a, 'b, S> {
where
S: Step,
{
if self.builder.config.dry_run {
let builder = self.builder;
if builder.config.dry_run {
return;
}
// let stage = self.stage.unwrap_or(self.builder.top_stage);
let stage = self.stage.expect("missing stage");
// let kind = self.cmd.unwrap_or(self.builder.kind);
let kind = self.cmd.expect("missing kind");
print!(
"{} {} --stage {}",
kind,
self.step.path(self.builder).display(),
stage,
);
let stage = self.stage.unwrap_or(self.builder.top_stage);
let kind = self.cmd.unwrap_or_else(|| panic!("missing kind for {}", self.step.name()));
let path = self.path.clone().unwrap_or_else(|| {
let paths = S::should_run(ShouldRun::new(builder)).paths;
paths.iter().map(|pathset| pathset.path(builder)).next().expect("no paths for step")
});
print!("{} {} --stage {}", kind, path.display(), stage,);
if let Some(host) = self.host {
// Almost always, this will be the same as build. Don't print it if so.
if host != self.builder.config.build {
if host != builder.config.build {
print!(" --host {}", host);
}
}
if let Some(target) = self.target {
let different_from_host = self.host.map_or(false, |h| h != target);
if target != self.builder.config.build || different_from_host {
if target != builder.config.build || different_from_host {
print!(" --target {}", target);
}
}
if kind == Kind::Test {
for arg in self.builder.config.cmd.test_args() {
for arg in builder.config.cmd.test_args() {
print!(" --test-args \"{}\"", arg);
}
}
Expand Down
21 changes: 1 addition & 20 deletions src/bootstrap/check.rs
Original file line number Diff line number Diff line change
Expand Up @@ -94,10 +94,6 @@ impl Step for Std {
std_cargo(builder, target, compiler.stage, &mut cargo);

builder.step_info(&self);
// builder.info(&format!(
// "Checking stage{} std artifacts ({} -> {})",
// builder.top_stage, &compiler.host, target
// ));
run_cargo(
builder,
cargo,
Expand Down Expand Up @@ -141,7 +137,7 @@ impl Step for Std {
}

builder.info(&format!(
"Checking stage{} std test/bench/example targets ({} -> {})",
"check library/alloc --stage {} --all-targets --host {} --target {}",
builder.top_stage, &compiler.host, target
));
run_cargo(
Expand Down Expand Up @@ -222,10 +218,6 @@ impl Step for Rustc {
}

builder.step_info(&self);
// builder.info(&format!(
// "Checking stage{} compiler artifacts ({} -> {})",
// builder.top_stage, &compiler.host, target
// ));
run_cargo(
builder,
cargo,
Expand Down Expand Up @@ -287,10 +279,6 @@ impl Step for CodegenBackend {
rustc_cargo_env(builder, &mut cargo, target);

builder.step_info(&self);
// builder.info(&format!(
// "Checking stage{} {} artifacts ({} -> {})",
// builder.top_stage, backend, &compiler.host.triple, target.triple
// ));

run_cargo(
builder,
Expand Down Expand Up @@ -358,13 +346,6 @@ macro_rules! tool_check_step {
cargo.rustflag("-Zunstable-options");

builder.step_info(&self);
// builder.info(&format!(
// "Checking stage{} {} artifacts ({} -> {})",
// builder.top_stage,
// stringify!($name).to_lowercase(),
// &compiler.host.triple,
// target.triple
// ));
run_cargo(
builder,
cargo,
Expand Down
2 changes: 1 addition & 1 deletion src/bootstrap/dist.rs
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ macro_rules! compiler_target_info {
let step = step_info.step;
step_info.compiler(&step.compiler).target(step.target).cmd(Kind::Dist);
}
}
};
}

#[derive(Debug, PartialOrd, Ord, Copy, Clone, Hash, PartialEq, Eq)]
Expand Down
8 changes: 4 additions & 4 deletions src/bootstrap/doc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ macro_rules! target_info {
fn info(step_info: &mut StepInfo<'_, '_, Self>) {
step_info.target(step_info.step.target).cmd(Kind::Doc);
}
}
};
}

macro_rules! compiler_target_info {
Expand All @@ -45,7 +45,7 @@ macro_rules! compiler_target_info {
let step = step_info.step;
step_info.compiler(&step.compiler).target(step.target).cmd(Kind::Doc);
}
}
};
}

macro_rules! stage_target_info {
Expand All @@ -54,7 +54,7 @@ macro_rules! stage_target_info {
let step = step_info.step;
step_info.stage(step.stage).target(step.target).cmd(Kind::Doc);
}
}
};
}

macro_rules! book {
Expand Down Expand Up @@ -818,7 +818,7 @@ impl Step for UnstableBookGen {
fn run(self, builder: &Builder<'_>) {
let target = self.target;

builder.info(&format!("Generating unstable book md files ({})", target));
builder.step_info(&self);
let out = builder.md_doc_out(target).join("unstable-book");
builder.create_dir(&out);
builder.remove_dir(&out);
Expand Down
2 changes: 1 addition & 1 deletion src/bootstrap/install.rs
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ macro_rules! compiler_target_info {
let step = step_info.step;
step_info.compiler(&step.compiler).target(step.target).cmd(Kind::Install);
}
}
};
}

macro_rules! install {
Expand Down
2 changes: 1 addition & 1 deletion src/bootstrap/native.rs
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ macro_rules! target_info {
fn info(step_info: &mut StepInfo<'_, '_, Self>) {
step_info.target(step_info.step.target).cmd(Kind::Build);
}
}
};
}

pub struct Meta {
Expand Down
37 changes: 19 additions & 18 deletions src/bootstrap/test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ macro_rules! host_info {
let step = step_info.step;
step_info.host(step.host).cmd(Kind::Test);
}
}
};
}

macro_rules! stage_host_info {
Expand All @@ -41,7 +41,7 @@ macro_rules! stage_host_info {
let step = step_info.step;
step_info.stage(step.stage).host(step.host).cmd(Kind::Test);
}
}
};
}

macro_rules! compiler_target_info {
Expand All @@ -50,7 +50,7 @@ macro_rules! compiler_target_info {
let step = step_info.step;
step_info.compiler(&step.compiler).target(step.target).cmd(Kind::Test);
}
}
};
}

const ADB_TEST_DIR: &str = "/data/tmp/work";
Expand Down Expand Up @@ -1047,7 +1047,7 @@ impl Step for Tidy {
try_run(builder, &mut cmd);

if builder.config.channel == "dev" || builder.config.channel == "nightly" {
builder.info("fmt check");
builder.info("fmt --check");
if builder.config.initial_rustfmt.is_none() {
let inferred_rustfmt_dir = builder.config.initial_rustc.parent().unwrap();
eprintln!(
Expand Down Expand Up @@ -1291,11 +1291,14 @@ impl Step for Compiletest {
run.never()
}

compiler_target_info!();

fn path(&self, _builder: &Builder<'_>) -> PathBuf {
fn info(step_info: &mut StepInfo<'_, '_, Self>) {
let step = step_info.step;
// FIXME: it would be nice to suggest exactly the tests that fail, but that info isn't known without first running compiletest.
self.path.into()
step_info
.path(step.path.into())
.compiler(&step.compiler)
.target(step.target)
.cmd(Kind::Test);
}

/// Executes the `compiletest` tool to run a suite of tests.
Expand Down Expand Up @@ -1667,10 +1670,7 @@ note: if you're sure you want to do this, please open an issue as to why. In the

builder.ci_env.force_coloring_in_ci(&mut cmd);

builder.info(&format!(
"Check compiletest suite={} mode={} ({} -> {})",
suite, mode, &compiler.host, target
));
builder.step_info(&self);
let _time = util::timeit(&builder);
try_run(builder, &mut cmd);

Expand Down Expand Up @@ -1704,8 +1704,7 @@ impl Step for BookTest {

fn info(step_info: &mut StepInfo<'_, '_, Self>) {
let step = step_info.step;
todo!("path");
step_info.compiler(&step.compiler).cmd(Kind::Test);
step_info.path(step.path.clone()).compiler(&step.compiler).cmd(Kind::Test);
}

/// Runs the documentation tests for a book in `src/doc`.
Expand Down Expand Up @@ -2056,10 +2055,12 @@ impl Step for Crate {
}
}

compiler_target_info!();

fn path(&self, _builder: &Builder<'_>) -> PathBuf {
self.krate_path.file_name().expect("top-level directory is not a crate").into()
fn info(step_info: &mut StepInfo<'_, '_, Self>) {
let step = step_info.step;
// FIXME: it would be nice to suggest exactly the tests that fail, but that info isn't known without first running compiletest.
step_info
.path(step.krate_path.file_name().expect("top-level directory is not a crate").into());
step_info.compiler(&step.compiler).target(step.target).cmd(Kind::Test);
}

/// Runs all unit tests plus documentation tests for a given crate defined
Expand Down
1 change: 1 addition & 0 deletions src/bootstrap/tool.rs
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ impl Step for ToolBuild {
fn info(step_info: &mut StepInfo<'_, '_, Self>) {
let step = step_info.step;
// todo!("path");
step_info.path(step.path.into());
step_info.compiler(&step.compiler).target(step.target).cmd(Kind::Build);
}

Expand Down

0 comments on commit c47f73b

Please sign in to comment.