]> git.lizzy.rs Git - rust.git/commitdiff
Stub out various functions during testing
authorMark Simulacrum <mark.simulacrum@gmail.com>
Sat, 10 Mar 2018 02:23:35 +0000 (19:23 -0700)
committerMark Simulacrum <mark.simulacrum@gmail.com>
Tue, 3 Apr 2018 17:39:16 +0000 (11:39 -0600)
src/bootstrap/builder.rs
src/bootstrap/compile.rs
src/bootstrap/doc.rs
src/bootstrap/lib.rs
src/bootstrap/native.rs
src/bootstrap/tool.rs
src/bootstrap/util.rs

index 6ae19ac394eec182393e2be1eacd5270ca27ab4e..c2a53e4590e7823a4be0fb65ec1f39d69ce35c98 100644 (file)
@@ -687,7 +687,7 @@ pub fn cargo(&self,
         // the options through environment variables that are fetched and understood by both.
         //
         // FIXME: the guard against msvc shouldn't need to be here
-        if !target.contains("msvc") {
+        if !target.contains("msvc") && !cfg!(test) {
             let ccache = self.config.ccache.as_ref();
             let ccacheify = |s: &Path| {
                 let ccache = match ccache {
index e6aa78fba52ffd21209eef963e3cde30fdad6a72..54b0ed6bb35952d55d40926a41b7b76bb8c511c7 100644 (file)
@@ -690,6 +690,9 @@ fn run(self, builder: &Builder) {
                               cargo.arg("--features").arg(features),
                               &tmp_stamp,
                               false);
+        if cfg!(test) {
+            return;
+        }
         let mut files = files.into_iter()
             .filter(|f| {
                 let filename = f.file_name().unwrap().to_str().unwrap();
@@ -719,6 +722,7 @@ fn run(self, builder: &Builder) {
 fn copy_codegen_backends_to_sysroot(builder: &Builder,
                                     compiler: Compiler,
                                     target_compiler: Compiler) {
+    if cfg!(test) { return; }
     let build = builder.build;
     let target = target_compiler.host;
 
index 44073a5b0757237bda2fe96abb1aa873e6432756..5f3d9ecfc042d5666449346aeaf26f8a496a8d52 100644 (file)
@@ -817,6 +817,7 @@ fn run(self, builder: &Builder) {
 }
 
 fn symlink_dir_force(src: &Path, dst: &Path) -> io::Result<()> {
+    if cfg!(test) { return Ok(()); }
     if let Ok(m) = fs::symlink_metadata(dst) {
         if m.file_type().is_dir() {
             try!(fs::remove_dir_all(dst));
index cad4a794cf00592b03fade3abfdc52db24dccd8e..a4287df677e3fdfc598133bff7e22033b7f04cc1 100644 (file)
@@ -363,16 +363,19 @@ pub fn new(config: Config) -> Build {
         cc_detect::find(&mut build);
         build.verbose("running sanity check");
         sanity::check(&mut build);
-        // If local-rust is the same major.minor as the current version, then force a local-rebuild
-        let local_version_verbose = output(
-            Command::new(&build.initial_rustc).arg("--version").arg("--verbose"));
-        let local_release = local_version_verbose
-            .lines().filter(|x| x.starts_with("release:"))
-            .next().unwrap().trim_left_matches("release:").trim();
-        let my_version = channel::CFG_RELEASE_NUM;
-        if local_release.split('.').take(2).eq(my_version.split('.').take(2)) {
-            build.verbose(&format!("auto-detected local-rebuild {}", local_release));
-            build.local_rebuild = true;
+        if !cfg!(test) {
+            // If local-rust is the same major.minor as the current version, then force a
+            // local-rebuild
+            let local_version_verbose = output(
+                Command::new(&build.initial_rustc).arg("--version").arg("--verbose"));
+            let local_release = local_version_verbose
+                .lines().filter(|x| x.starts_with("release:"))
+                .next().unwrap().trim_left_matches("release:").trim();
+            let my_version = channel::CFG_RELEASE_NUM;
+            if local_release.split('.').take(2).eq(my_version.split('.').take(2)) {
+                build.verbose(&format!("auto-detected local-rebuild {}", local_release));
+                build.local_rebuild = true;
+            }
         }
         build.verbose("learning about cargo");
         metadata::build(&mut build);
@@ -419,6 +422,7 @@ pub fn build(&mut self) {
     ///
     /// After this executes, it will also ensure that `dir` exists.
     fn clear_if_dirty(&self, dir: &Path, input: &Path) -> bool {
+        if cfg!(test) { return true; }
         let stamp = dir.join(".stamp");
         let mut cleared = false;
         if mtime(&stamp) < mtime(input) {
@@ -593,12 +597,14 @@ fn rustc_snapshot_libdir(&self) -> PathBuf {
 
     /// Runs a command, printing out nice contextual information if it fails.
     fn run(&self, cmd: &mut Command) {
+        if cfg!(test) { return; }
         self.verbose(&format!("running: {:?}", cmd));
         run_silent(cmd)
     }
 
     /// Runs a command, printing out nice contextual information if it fails.
     fn run_quiet(&self, cmd: &mut Command) {
+        if cfg!(test) { return; }
         self.verbose(&format!("running: {:?}", cmd));
         run_suppressed(cmd)
     }
@@ -607,6 +613,7 @@ fn run_quiet(&self, cmd: &mut Command) {
     /// Exits if the command failed to execute at all, otherwise returns its
     /// `status.success()`.
     fn try_run(&self, cmd: &mut Command) -> bool {
+        if cfg!(test) { return true; }
         self.verbose(&format!("running: {:?}", cmd));
         try_run_silent(cmd)
     }
@@ -615,6 +622,7 @@ fn try_run(&self, cmd: &mut Command) -> bool {
     /// Exits if the command failed to execute at all, otherwise returns its
     /// `status.success()`.
     fn try_run_quiet(&self, cmd: &mut Command) -> bool {
+        if cfg!(test) { return true; }
         self.verbose(&format!("running: {:?}", cmd));
         try_run_suppressed(cmd)
     }
@@ -685,6 +693,7 @@ fn cxx(&self, target: Interned<String>) -> Result<&Path, String> {
 
     /// Returns the path to the linker for the given target if it needs to be overridden.
     fn linker(&self, target: Interned<String>) -> Option<&Path> {
+        if cfg!(test) { return None; }
         if let Some(linker) = self.config.target_config.get(&target)
                                                        .and_then(|c| c.linker.as_ref()) {
             Some(linker)
index f923ad46bcbaa07d79b35c6e1a1baf39e44e62a1..f95f8e01dae50e7f152a08dfdf9841fcba5480bc 100644 (file)
@@ -60,6 +60,9 @@ fn make_run(run: RunConfig) {
 
     /// Compile LLVM for `target`.
     fn run(self, builder: &Builder) -> PathBuf {
+        if cfg!(test) {
+            return PathBuf::from("llvm-config-test-generated");
+        }
         let build = builder.build;
         let target = self.target;
         let emscripten = self.emscripten;
@@ -336,6 +339,9 @@ fn make_run(run: RunConfig) {
 
     /// Compile LLVM for `target`.
     fn run(self, builder: &Builder) -> PathBuf {
+        if cfg!(test) {
+            return PathBuf::from("lld-out-dir-test-gen");
+        }
         let target = self.target;
         let build = builder.build;
 
@@ -389,6 +395,9 @@ fn make_run(run: RunConfig) {
     /// Compiles the `rust_test_helpers.c` library which we used in various
     /// `run-pass` test suites for ABI testing.
     fn run(self, builder: &Builder) {
+        if cfg!(test) {
+            return;
+        }
         let build = builder.build;
         let target = self.target;
         let dst = build.test_helpers_out(target);
@@ -441,6 +450,9 @@ fn should_run(run: ShouldRun) -> ShouldRun {
     }
 
     fn run(self, builder: &Builder) {
+        if cfg!(test) {
+            return;
+        }
         let build = builder.build;
         let target = self.target;
         let out = match build.openssl_dir(target) {
index 2bb46cc5171d61b0881782f5474eb2aee3dee461..362ec0c3b5085751b10000d629a4a620fd28c58f 100644 (file)
@@ -199,7 +199,11 @@ fn run(self, builder: &Builder) -> Option<PathBuf> {
 
         if !is_expected {
             if !is_ext_tool {
-                exit(1);
+                if cfg!(test) {
+                    panic!("unexpected failure -- would have hard exited");
+                } else {
+                    exit(1);
+                }
             } else {
                 return None;
             }
index 492eceef05c75045e711b4309565b214592422ff..99d0548a05e7f896bd7918c519441471f62192b4 100644 (file)
@@ -34,6 +34,7 @@ pub fn staticlib(name: &str, target: &str) -> String {
 
 /// Copies a file from `src` to `dst`
 pub fn copy(src: &Path, dst: &Path) {
+    if cfg!(test) { return; }
     let _ = fs::remove_file(&dst);
     // Attempt to "easy copy" by creating a hard link (symlinks don't work on
     // windows), but if that fails just fall back to a slow `copy` operation.
@@ -66,6 +67,7 @@ pub fn replace_in_file(path: &Path, replacements: &[(&str, &str)]) {
 }
 
 pub fn read_stamp_file(stamp: &Path) -> Vec<PathBuf> {
+    if cfg!(test) { return vec![]; }
     let mut paths = Vec::new();
     let mut contents = Vec::new();
     t!(t!(File::open(stamp)).read_to_end(&mut contents));
@@ -215,6 +217,7 @@ fn drop(&mut self) {
 /// Symlinks two directories, using junctions on Windows and normal symlinks on
 /// Unix.
 pub fn symlink_dir(src: &Path, dest: &Path) -> io::Result<()> {
+    if cfg!(test) { return Ok(()); }
     let _ = fs::remove_dir(dest);
     return symlink_dir_inner(src, dest);