Skip to content

Commit bc48601

Browse files
committed
Fix command suggestion for tests
- Allow overriding the path shown per-step - Override the path for the `Crate` step - Add `--stage` to the suggestion
1 parent 9fd68c9 commit bc48601

File tree

2 files changed

+32
-14
lines changed

2 files changed

+32
-14
lines changed

src/bootstrap/builder.rs

Lines changed: 15 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -63,10 +63,17 @@ pub trait Step: 'static + Clone + Debug + PartialEq + Eq + Hash {
6363
/// If true, then this rule should be skipped if --target was specified, but --host was not
6464
const ONLY_HOSTS: bool = false;
6565

66+
/// A user-visible name to display if this step fails.
6667
fn name(&self) -> &'static str {
6768
std::any::type_name::<Self>()
6869
}
6970

71+
/// The path that should be used on the command line to run this step.
72+
fn path(&self, builder: &Builder<'_>) -> PathBuf {
73+
let paths = Self::should_run(ShouldRun::new(builder)).paths;
74+
paths.iter().map(|pathset| pathset.path(builder)).next().expect("no paths for step")
75+
}
76+
7077
/// Primary function to execute this rule. Can call `builder.ensure()`
7178
/// with other steps to run those.
7279
fn run(self, builder: &Builder<'_>) -> Self::Output;
@@ -1560,13 +1567,13 @@ impl<'a> Builder<'a> {
15601567
}
15611568

15621569
let (out, dur) = {
1563-
let paths = S::should_run(ShouldRun::new(self)).paths;
1564-
let path = paths.iter().map(|pathset| pathset.path(self)).next();
15651570
let instructions = ReplicationStep {
15661571
color: self.build.config.color,
1567-
name: step.name(),
15681572
cmd: self.kind,
1569-
path: path.expect("no paths for step"),
1573+
name: step.name(),
1574+
path: step.path(self),
1575+
// FIXME: top_stage might be higher than the stage of the step
1576+
stage: self.top_stage,
15701577
};
15711578
// NOTE: don't hold onto this guard, it will cause a deadlock if the current step calls `ensure` recursively.
15721579
let old_instructions = CURRENT_INSTRUCTIONS
@@ -1606,6 +1613,7 @@ struct ReplicationStep {
16061613
cmd: Kind,
16071614
name: &'static str,
16081615
path: PathBuf,
1616+
stage: u32,
16091617
}
16101618

16111619
lazy_static! {
@@ -1632,9 +1640,10 @@ pub(crate) extern "C" fn print_replication_steps() {
16321640
let _ = stdout.reset();
16331641
let _ = writeln!(
16341642
stdout,
1635-
": to replicate this failure, run `./x.py {} {}`",
1643+
": to replicate this failure, run `./x.py {} {} --stage {}`",
16361644
step.cmd,
1637-
step.path.display()
1645+
step.path.display(),
1646+
step.stage,
16381647
);
16391648
}
16401649
}

src/bootstrap/test.rs

Lines changed: 17 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1788,12 +1788,13 @@ impl Step for RustcGuide {
17881788
}
17891789
}
17901790

1791-
#[derive(Debug, Copy, Clone, PartialEq, Eq, Hash)]
1791+
#[derive(Debug, Clone, PartialEq, Eq, Hash)]
17921792
pub struct CrateLibrustc {
17931793
compiler: Compiler,
17941794
target: TargetSelection,
17951795
test_kind: TestKind,
1796-
krate: Interned<String>,
1796+
krate_name: Interned<String>,
1797+
krate_path: PathBuf,
17971798
}
17981799

17991800
impl Step for CrateLibrustc {
@@ -1817,7 +1818,8 @@ impl Step for CrateLibrustc {
18171818
compiler,
18181819
target: run.target,
18191820
test_kind,
1820-
krate: krate.name,
1821+
krate_name: krate.name,
1822+
krate_path: krate.path.clone(),
18211823
});
18221824
}
18231825
}
@@ -1829,18 +1831,20 @@ impl Step for CrateLibrustc {
18291831
target: self.target,
18301832
mode: Mode::Rustc,
18311833
test_kind: self.test_kind,
1832-
krate: self.krate,
1834+
krate_name: self.krate_name,
1835+
krate_path: self.krate_path.clone(),
18331836
});
18341837
}
18351838
}
18361839

1837-
#[derive(Debug, Copy, Clone, PartialEq, Eq, PartialOrd, Ord, Hash)]
1840+
#[derive(Debug, Clone, PartialEq, Eq, PartialOrd, Ord, Hash)]
18381841
pub struct Crate {
18391842
pub compiler: Compiler,
18401843
pub target: TargetSelection,
18411844
pub mode: Mode,
18421845
pub test_kind: TestKind,
1843-
pub krate: Interned<String>,
1846+
pub krate_name: Interned<String>,
1847+
pub krate_path: PathBuf,
18441848
}
18451849

18461850
impl Step for Crate {
@@ -1863,7 +1867,8 @@ impl Step for Crate {
18631867
target: run.target,
18641868
mode,
18651869
test_kind,
1866-
krate: krate.name,
1870+
krate_name: krate.name,
1871+
krate_path: krate.path.clone(),
18671872
});
18681873
};
18691874

@@ -1874,6 +1879,10 @@ impl Step for Crate {
18741879
}
18751880
}
18761881

1882+
fn path(&self, _builder: &Builder<'_>) -> PathBuf {
1883+
self.krate_path.file_name().expect("top-level directory is not a crate").into()
1884+
}
1885+
18771886
/// Runs all unit tests plus documentation tests for a given crate defined
18781887
/// by a `Cargo.toml` (single manifest)
18791888
///
@@ -1887,7 +1896,7 @@ impl Step for Crate {
18871896
let target = self.target;
18881897
let mode = self.mode;
18891898
let test_kind = self.test_kind;
1890-
let krate = self.krate;
1899+
let krate = self.krate_name;
18911900

18921901
builder.ensure(compile::Std { compiler, target });
18931902
builder.ensure(RemoteCopyLibs { compiler, target });

0 commit comments

Comments
 (0)