]> git.lizzy.rs Git - rust.git/commitdiff
Don't duplicate builder code
authorJoshua Nelson <jyn514@gmail.com>
Thu, 2 Jul 2020 12:07:56 +0000 (08:07 -0400)
committerJoshua Nelson <jyn514@gmail.com>
Tue, 28 Jul 2020 03:11:17 +0000 (23:11 -0400)
- Add Builder::new_internal

src/bootstrap/builder.rs

index c1e56347ab1e0111ed0ff5d0bd71f1c88aead816..c1c3c2f3ea79776dbf6d127a95e77fc5169cae70 100644 (file)
@@ -501,16 +501,7 @@ pub fn get_help(build: &Build, subcommand: &str) -> Option<String> {
             _ => 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) {
@@ -535,6 +526,18 @@ pub fn get_help(build: &Build, subcommand: &str) -> Option<String> {
         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[..]),
@@ -550,15 +553,7 @@ pub fn new(build: &Build) -> Builder<'_> {
             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) {