Skip to content

Commit a5e56b6

Browse files
Permit constructing Builder without executing
1 parent 84b5b34 commit a5e56b6

File tree

2 files changed

+17
-10
lines changed

2 files changed

+17
-10
lines changed

src/bootstrap/builder.rs

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@ pub struct Builder<'a> {
4242
cache: Cache,
4343
stack: RefCell<Vec<Box<Any>>>,
4444
time_spent_on_dependencies: Cell<Duration>,
45+
pub paths: Vec<PathBuf>,
4546
}
4647

4748
impl<'a> Deref for Builder<'a> {
@@ -351,6 +352,7 @@ impl<'a> Builder<'a> {
351352
cache: Cache::new(),
352353
stack: RefCell::new(Vec::new()),
353354
time_spent_on_dependencies: Cell::new(Duration::new(0, 0)),
355+
paths: vec![],
354356
};
355357

356358
let builder = &builder;
@@ -367,7 +369,7 @@ impl<'a> Builder<'a> {
367369
Some(help)
368370
}
369371

370-
pub fn run(build: &Build) {
372+
pub fn new(build: &Build) -> Builder {
371373
let (kind, paths) = match build.config.cmd {
372374
Subcommand::Build { ref paths } => (Kind::Build, &paths[..]),
373375
Subcommand::Check { ref paths } => (Kind::Check, &paths[..]),
@@ -379,28 +381,27 @@ impl<'a> Builder<'a> {
379381
Subcommand::Clean { .. } => panic!(),
380382
};
381383

382-
if let Some(path) = paths.get(0) {
383-
if path == Path::new("nonexistent/path/to/trigger/cargo/metadata") {
384-
return;
385-
}
386-
}
387-
388384
let builder = Builder {
389385
build,
390386
top_stage: build.config.stage.unwrap_or(2),
391387
kind,
392388
cache: Cache::new(),
393389
stack: RefCell::new(Vec::new()),
394390
time_spent_on_dependencies: Cell::new(Duration::new(0, 0)),
391+
paths: paths.to_owned(),
395392
};
396393

397394
if kind == Kind::Dist {
398-
assert!(!build.config.test_miri, "Do not distribute with miri enabled.\n\
395+
assert!(!builder.config.test_miri, "Do not distribute with miri enabled.\n\
399396
The distributed libraries would include all MIR (increasing binary size).
400397
The distributed MIR would include validation statements.");
401398
}
402399

403-
StepDescription::run(&Builder::get_step_descriptions(builder.kind), &builder, paths);
400+
builder
401+
}
402+
403+
pub fn execute_cli(&self) {
404+
StepDescription::run(&Builder::get_step_descriptions(self.kind), self, &self.paths);
404405
}
405406

406407
pub fn default_doc(&self, paths: Option<&[PathBuf]>) {

src/bootstrap/lib.rs

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -394,7 +394,13 @@ impl Build {
394394
self.verbose("learning about cargo");
395395
metadata::build(self);
396396

397-
builder::Builder::run(&self);
397+
let builder = builder::Builder::new(&self);
398+
if let Some(path) = builder.paths.get(0) {
399+
if path == Path::new("nonexistent/path/to/trigger/cargo/metadata") {
400+
return;
401+
}
402+
}
403+
builder.execute_cli();
398404

399405
// Check for postponed failures from `test --no-fail-fast`.
400406
let failures = self.delayed_failures.borrow();

0 commit comments

Comments
 (0)