Skip to content

Commit cd33d3a

Browse files
Stub out various functions during testing
1 parent e7342b8 commit cd33d3a

File tree

7 files changed

+45
-12
lines changed

7 files changed

+45
-12
lines changed

src/bootstrap/builder.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -687,7 +687,7 @@ impl<'a> Builder<'a> {
687687
// the options through environment variables that are fetched and understood by both.
688688
//
689689
// FIXME: the guard against msvc shouldn't need to be here
690-
if !target.contains("msvc") {
690+
if !target.contains("msvc") && !cfg!(test) {
691691
let ccache = self.config.ccache.as_ref();
692692
let ccacheify = |s: &Path| {
693693
let ccache = match ccache {

src/bootstrap/compile.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -690,6 +690,9 @@ impl Step for CodegenBackend {
690690
cargo.arg("--features").arg(features),
691691
&tmp_stamp,
692692
false);
693+
if cfg!(test) {
694+
return;
695+
}
693696
let mut files = files.into_iter()
694697
.filter(|f| {
695698
let filename = f.file_name().unwrap().to_str().unwrap();
@@ -719,6 +722,7 @@ impl Step for CodegenBackend {
719722
fn copy_codegen_backends_to_sysroot(builder: &Builder,
720723
compiler: Compiler,
721724
target_compiler: Compiler) {
725+
if cfg!(test) { return; }
722726
let build = builder.build;
723727
let target = target_compiler.host;
724728

src/bootstrap/doc.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -817,6 +817,7 @@ impl Step for UnstableBookGen {
817817
}
818818

819819
fn symlink_dir_force(src: &Path, dst: &Path) -> io::Result<()> {
820+
if cfg!(test) { return Ok(()); }
820821
if let Ok(m) = fs::symlink_metadata(dst) {
821822
if m.file_type().is_dir() {
822823
try!(fs::remove_dir_all(dst));

src/bootstrap/lib.rs

Lines changed: 19 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -363,16 +363,19 @@ impl Build {
363363
cc_detect::find(&mut build);
364364
build.verbose("running sanity check");
365365
sanity::check(&mut build);
366-
// If local-rust is the same major.minor as the current version, then force a local-rebuild
367-
let local_version_verbose = output(
368-
Command::new(&build.initial_rustc).arg("--version").arg("--verbose"));
369-
let local_release = local_version_verbose
370-
.lines().filter(|x| x.starts_with("release:"))
371-
.next().unwrap().trim_left_matches("release:").trim();
372-
let my_version = channel::CFG_RELEASE_NUM;
373-
if local_release.split('.').take(2).eq(my_version.split('.').take(2)) {
374-
build.verbose(&format!("auto-detected local-rebuild {}", local_release));
375-
build.local_rebuild = true;
366+
if !cfg!(test) {
367+
// If local-rust is the same major.minor as the current version, then force a
368+
// local-rebuild
369+
let local_version_verbose = output(
370+
Command::new(&build.initial_rustc).arg("--version").arg("--verbose"));
371+
let local_release = local_version_verbose
372+
.lines().filter(|x| x.starts_with("release:"))
373+
.next().unwrap().trim_left_matches("release:").trim();
374+
let my_version = channel::CFG_RELEASE_NUM;
375+
if local_release.split('.').take(2).eq(my_version.split('.').take(2)) {
376+
build.verbose(&format!("auto-detected local-rebuild {}", local_release));
377+
build.local_rebuild = true;
378+
}
376379
}
377380
build.verbose("learning about cargo");
378381
metadata::build(&mut build);
@@ -419,6 +422,7 @@ impl Build {
419422
///
420423
/// After this executes, it will also ensure that `dir` exists.
421424
fn clear_if_dirty(&self, dir: &Path, input: &Path) -> bool {
425+
if cfg!(test) { return true; }
422426
let stamp = dir.join(".stamp");
423427
let mut cleared = false;
424428
if mtime(&stamp) < mtime(input) {
@@ -593,12 +597,14 @@ impl Build {
593597

594598
/// Runs a command, printing out nice contextual information if it fails.
595599
fn run(&self, cmd: &mut Command) {
600+
if cfg!(test) { return; }
596601
self.verbose(&format!("running: {:?}", cmd));
597602
run_silent(cmd)
598603
}
599604

600605
/// Runs a command, printing out nice contextual information if it fails.
601606
fn run_quiet(&self, cmd: &mut Command) {
607+
if cfg!(test) { return; }
602608
self.verbose(&format!("running: {:?}", cmd));
603609
run_suppressed(cmd)
604610
}
@@ -607,6 +613,7 @@ impl Build {
607613
/// Exits if the command failed to execute at all, otherwise returns its
608614
/// `status.success()`.
609615
fn try_run(&self, cmd: &mut Command) -> bool {
616+
if cfg!(test) { return true; }
610617
self.verbose(&format!("running: {:?}", cmd));
611618
try_run_silent(cmd)
612619
}
@@ -615,6 +622,7 @@ impl Build {
615622
/// Exits if the command failed to execute at all, otherwise returns its
616623
/// `status.success()`.
617624
fn try_run_quiet(&self, cmd: &mut Command) -> bool {
625+
if cfg!(test) { return true; }
618626
self.verbose(&format!("running: {:?}", cmd));
619627
try_run_suppressed(cmd)
620628
}
@@ -685,6 +693,7 @@ impl Build {
685693

686694
/// Returns the path to the linker for the given target if it needs to be overridden.
687695
fn linker(&self, target: Interned<String>) -> Option<&Path> {
696+
if cfg!(test) { return None; }
688697
if let Some(linker) = self.config.target_config.get(&target)
689698
.and_then(|c| c.linker.as_ref()) {
690699
Some(linker)

src/bootstrap/native.rs

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,9 @@ impl Step for Llvm {
6060

6161
/// Compile LLVM for `target`.
6262
fn run(self, builder: &Builder) -> PathBuf {
63+
if cfg!(test) {
64+
return PathBuf::from("llvm-config-test-generated");
65+
}
6366
let build = builder.build;
6467
let target = self.target;
6568
let emscripten = self.emscripten;
@@ -336,6 +339,9 @@ impl Step for Lld {
336339

337340
/// Compile LLVM for `target`.
338341
fn run(self, builder: &Builder) -> PathBuf {
342+
if cfg!(test) {
343+
return PathBuf::from("lld-out-dir-test-gen");
344+
}
339345
let target = self.target;
340346
let build = builder.build;
341347

@@ -389,6 +395,9 @@ impl Step for TestHelpers {
389395
/// Compiles the `rust_test_helpers.c` library which we used in various
390396
/// `run-pass` test suites for ABI testing.
391397
fn run(self, builder: &Builder) {
398+
if cfg!(test) {
399+
return;
400+
}
392401
let build = builder.build;
393402
let target = self.target;
394403
let dst = build.test_helpers_out(target);
@@ -441,6 +450,9 @@ impl Step for Openssl {
441450
}
442451

443452
fn run(self, builder: &Builder) {
453+
if cfg!(test) {
454+
return;
455+
}
444456
let build = builder.build;
445457
let target = self.target;
446458
let out = match build.openssl_dir(target) {

src/bootstrap/tool.rs

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -199,7 +199,11 @@ impl Step for ToolBuild {
199199

200200
if !is_expected {
201201
if !is_ext_tool {
202-
exit(1);
202+
if cfg!(test) {
203+
panic!("unexpected failure -- would have hard exited");
204+
} else {
205+
exit(1);
206+
}
203207
} else {
204208
return None;
205209
}

src/bootstrap/util.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@ pub fn staticlib(name: &str, target: &str) -> String {
3434

3535
/// Copies a file from `src` to `dst`
3636
pub fn copy(src: &Path, dst: &Path) {
37+
if cfg!(test) { return; }
3738
let _ = fs::remove_file(&dst);
3839
// Attempt to "easy copy" by creating a hard link (symlinks don't work on
3940
// 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)]) {
6667
}
6768

6869
pub fn read_stamp_file(stamp: &Path) -> Vec<PathBuf> {
70+
if cfg!(test) { return vec![]; }
6971
let mut paths = Vec::new();
7072
let mut contents = Vec::new();
7173
t!(t!(File::open(stamp)).read_to_end(&mut contents));
@@ -215,6 +217,7 @@ impl Drop for TimeIt {
215217
/// Symlinks two directories, using junctions on Windows and normal symlinks on
216218
/// Unix.
217219
pub fn symlink_dir(src: &Path, dest: &Path) -> io::Result<()> {
220+
if cfg!(test) { return Ok(()); }
218221
let _ = fs::remove_dir(dest);
219222
return symlink_dir_inner(src, dest);
220223

0 commit comments

Comments
 (0)