]> git.lizzy.rs Git - rust.git/commitdiff
Permit constructing Builder without executing
authorMark Simulacrum <mark.simulacrum@gmail.com>
Sat, 10 Mar 2018 02:05:06 +0000 (19:05 -0700)
committerMark Simulacrum <mark.simulacrum@gmail.com>
Tue, 3 Apr 2018 17:39:16 +0000 (11:39 -0600)
src/bootstrap/builder.rs
src/bootstrap/lib.rs

index 0464840c3e8187c89d195a47a1902bd446aa2ff1..6ae19ac394eec182393e2be1eacd5270ca27ab4e 100644 (file)
@@ -42,6 +42,7 @@ pub struct Builder<'a> {
     cache: Cache,
     stack: RefCell<Vec<Box<Any>>>,
     time_spent_on_dependencies: Cell<Duration>,
+    pub paths: Vec<PathBuf>,
 }
 
 impl<'a> Deref for Builder<'a> {
@@ -351,6 +352,7 @@ pub fn get_help(build: &Build, subcommand: &str) -> Option<String> {
             cache: Cache::new(),
             stack: RefCell::new(Vec::new()),
             time_spent_on_dependencies: Cell::new(Duration::new(0, 0)),
+            paths: vec![],
         };
 
         let builder = &builder;
@@ -367,7 +369,7 @@ pub fn get_help(build: &Build, subcommand: &str) -> Option<String> {
         Some(help)
     }
 
-    pub fn run(build: &Build) {
+    pub fn new(build: &Build) -> Builder {
         let (kind, paths) = match build.config.cmd {
             Subcommand::Build { ref paths } => (Kind::Build, &paths[..]),
             Subcommand::Check { ref paths } => (Kind::Check, &paths[..]),
@@ -379,12 +381,6 @@ pub fn run(build: &Build) {
             Subcommand::Clean { .. } => panic!(),
         };
 
-        if let Some(path) = paths.get(0) {
-            if path == Path::new("nonexistent/path/to/trigger/cargo/metadata") {
-                return;
-            }
-        }
-
         let builder = Builder {
             build,
             top_stage: build.config.stage.unwrap_or(2),
@@ -392,15 +388,20 @@ pub fn run(build: &Build) {
             cache: Cache::new(),
             stack: RefCell::new(Vec::new()),
             time_spent_on_dependencies: Cell::new(Duration::new(0, 0)),
+            paths: paths.to_owned(),
         };
 
         if kind == Kind::Dist {
-            assert!(!build.config.test_miri, "Do not distribute with miri enabled.\n\
+            assert!(!builder.config.test_miri, "Do not distribute with miri enabled.\n\
                 The distributed libraries would include all MIR (increasing binary size).
                 The distributed MIR would include validation statements.");
         }
 
-        StepDescription::run(&Builder::get_step_descriptions(builder.kind), &builder, paths);
+        builder
+    }
+
+    pub fn execute_cli(&self) {
+        StepDescription::run(&Builder::get_step_descriptions(self.kind), self, &self.paths);
     }
 
     pub fn default_doc(&self, paths: Option<&[PathBuf]>) {
index 8b19bff3f6af87d160123c44b6cf8a7bdf8cd0d3..cbe19aeb63353b3f9c7de56665dd1fbbc91c6b80 100644 (file)
@@ -394,7 +394,13 @@ pub fn build(&mut self) {
         self.verbose("learning about cargo");
         metadata::build(self);
 
-        builder::Builder::run(&self);
+        let builder = builder::Builder::new(&self);
+        if let Some(path) = builder.paths.get(0) {
+            if path == Path::new("nonexistent/path/to/trigger/cargo/metadata") {
+                return;
+            }
+        }
+        builder.execute_cli();
 
         // Check for postponed failures from `test --no-fail-fast`.
         let failures = self.delayed_failures.borrow();