Skip to content

Commit d34a1b0

Browse files
committed
Don't duplicate builder code
- Add Builder::new_internal
1 parent ac48e62 commit d34a1b0

File tree

1 file changed

+14
-19
lines changed

1 file changed

+14
-19
lines changed

src/bootstrap/builder.rs

+14-19
Original file line numberDiff line numberDiff line change
@@ -501,16 +501,7 @@ impl<'a> Builder<'a> {
501501
_ => return None,
502502
};
503503

504-
let builder = Builder {
505-
build,
506-
top_stage: build.config.stage.unwrap_or(2),
507-
kind,
508-
cache: Cache::new(),
509-
stack: RefCell::new(Vec::new()),
510-
time_spent_on_dependencies: Cell::new(Duration::new(0, 0)),
511-
paths: vec![],
512-
};
513-
504+
let builder = Self::new_internal(build, kind, vec![]);
514505
let builder = &builder;
515506
let mut should_run = ShouldRun::new(builder);
516507
for desc in Builder::get_step_descriptions(builder.kind) {
@@ -535,6 +526,18 @@ impl<'a> Builder<'a> {
535526
Some(help)
536527
}
537528

529+
fn new_internal(build: &Build, kind: Kind, paths: Vec<PathBuf>) -> Builder<'_> {
530+
Builder {
531+
build,
532+
top_stage: build.config.stage.unwrap_or(2),
533+
kind,
534+
cache: Cache::new(),
535+
stack: RefCell::new(Vec::new()),
536+
time_spent_on_dependencies: Cell::new(Duration::new(0, 0)),
537+
paths,
538+
}
539+
}
540+
538541
pub fn new(build: &Build) -> Builder<'_> {
539542
let (kind, paths) = match build.config.cmd {
540543
Subcommand::Build { ref paths } => (Kind::Build, &paths[..]),
@@ -550,15 +553,7 @@ impl<'a> Builder<'a> {
550553
Subcommand::Format { .. } | Subcommand::Clean { .. } => panic!(),
551554
};
552555

553-
Builder {
554-
build,
555-
top_stage: build.config.stage.unwrap_or(2),
556-
kind,
557-
cache: Cache::new(),
558-
stack: RefCell::new(Vec::new()),
559-
time_spent_on_dependencies: Cell::new(Duration::new(0, 0)),
560-
paths: paths.to_owned(),
561-
}
556+
Self::new_internal(build, kind, paths.to_owned())
562557
}
563558

564559
pub fn execute_cli(&self) {

0 commit comments

Comments
 (0)