Skip to content

Commit

Permalink
Don't duplicate builder code
Browse files Browse the repository at this point in the history
- Add Builder::new_internal
  • Loading branch information
jyn514 committed Jul 28, 2020
1 parent ac48e62 commit d34a1b0
Showing 1 changed file with 14 additions and 19 deletions.
33 changes: 14 additions & 19 deletions src/bootstrap/builder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -501,16 +501,7 @@ impl<'a> Builder<'a> {
_ => return None,
};

let builder = Builder {
build,
top_stage: build.config.stage.unwrap_or(2),
kind,
cache: Cache::new(),
stack: RefCell::new(Vec::new()),
time_spent_on_dependencies: Cell::new(Duration::new(0, 0)),
paths: vec![],
};

let builder = Self::new_internal(build, kind, vec![]);
let builder = &builder;
let mut should_run = ShouldRun::new(builder);
for desc in Builder::get_step_descriptions(builder.kind) {
Expand All @@ -535,6 +526,18 @@ impl<'a> Builder<'a> {
Some(help)
}

fn new_internal(build: &Build, kind: Kind, paths: Vec<PathBuf>) -> Builder<'_> {
Builder {
build,
top_stage: build.config.stage.unwrap_or(2),
kind,
cache: Cache::new(),
stack: RefCell::new(Vec::new()),
time_spent_on_dependencies: Cell::new(Duration::new(0, 0)),
paths,
}
}

pub fn new(build: &Build) -> Builder<'_> {
let (kind, paths) = match build.config.cmd {
Subcommand::Build { ref paths } => (Kind::Build, &paths[..]),
Expand All @@ -550,15 +553,7 @@ impl<'a> Builder<'a> {
Subcommand::Format { .. } | Subcommand::Clean { .. } => panic!(),
};

Builder {
build,
top_stage: build.config.stage.unwrap_or(2),
kind,
cache: Cache::new(),
stack: RefCell::new(Vec::new()),
time_spent_on_dependencies: Cell::new(Duration::new(0, 0)),
paths: paths.to_owned(),
}
Self::new_internal(build, kind, paths.to_owned())
}

pub fn execute_cli(&self) {
Expand Down

0 comments on commit d34a1b0

Please sign in to comment.