Skip to content

Commit a727447

Browse files
Refactor to use a dry-run config instead of cfg(test)
This ensures that each build will support the testing design of "dry running" builds. It's also checked that a dry run build is equivalent step-wise to a "wet" run build; the graphs we generate when running are directly compared node/node and edge/edge, both for order and contents.
1 parent b0dbc7c commit a727447

File tree

12 files changed

+393
-293
lines changed

12 files changed

+393
-293
lines changed

src/bootstrap/builder.rs

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -413,8 +413,9 @@ impl<'a> Builder<'a> {
413413
builder
414414
}
415415

416-
pub fn execute_cli(&self) {
416+
pub fn execute_cli(&self) -> Graph<String, bool> {
417417
self.run_step_descriptions(&Builder::get_step_descriptions(self.kind), &self.paths);
418+
self.graph.borrow().clone()
418419
}
419420

420421
pub fn default_doc(&self, paths: Option<&[PathBuf]>) {
@@ -910,13 +911,20 @@ impl<'a> Builder<'a> {
910911
#[cfg(test)]
911912
mod __test {
912913
use config::Config;
914+
use std::thread;
913915
use super::*;
914916

915917
fn configure(host: &[&str], target: &[&str]) -> Config {
916918
let mut config = Config::default_opts();
917919
// don't save toolstates
918920
config.save_toolstates = None;
919921
config.run_host_only = true;
922+
config.dry_run = true;
923+
// try to avoid spurious failures in dist where we create/delete each others file
924+
let dir = config.out.join("tmp-rustbuild-tests")
925+
.join(&thread::current().name().unwrap_or("unknown").replace(":", "-"));
926+
t!(fs::create_dir_all(&dir));
927+
config.out = dir;
920928
config.build = INTERNER.intern_str("A");
921929
config.hosts = vec![config.build].clone().into_iter()
922930
.chain(host.iter().map(|s| INTERNER.intern_str(s))).collect::<Vec<_>>();

src/bootstrap/check.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ impl Step for Std {
5353
true);
5454

5555
let libdir = builder.sysroot_libdir(compiler, target);
56-
add_to_sysroot(&libdir, &libstd_stamp(build, compiler, target));
56+
add_to_sysroot(&build, &libdir, &libstd_stamp(build, compiler, target));
5757
}
5858
}
5959

@@ -102,7 +102,7 @@ impl Step for Rustc {
102102
true);
103103

104104
let libdir = builder.sysroot_libdir(compiler, target);
105-
add_to_sysroot(&libdir, &librustc_stamp(build, compiler, target));
105+
add_to_sysroot(&build, &libdir, &librustc_stamp(build, compiler, target));
106106
}
107107
}
108108

@@ -143,7 +143,7 @@ impl Step for Test {
143143
true);
144144

145145
let libdir = builder.sysroot_libdir(compiler, target);
146-
add_to_sysroot(&libdir, &libtest_stamp(build, compiler, target));
146+
add_to_sysroot(&build, &libdir, &libtest_stamp(build, compiler, target));
147147
}
148148
}
149149

src/bootstrap/compile.rs

Lines changed: 30 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ use build_helper::{output, mtime, up_to_date};
3030
use filetime::FileTime;
3131
use serde_json;
3232

33-
use util::{exe, libdir, is_dylib, copy, read_stamp_file, CiEnv};
33+
use util::{exe, libdir, is_dylib, CiEnv};
3434
use {Build, Compiler, Mode};
3535
use native;
3636
use tool;
@@ -130,7 +130,7 @@ fn copy_musl_third_party_objects(build: &Build,
130130
target: Interned<String>,
131131
into: &Path) {
132132
for &obj in &["crt1.o", "crti.o", "crtn.o"] {
133-
copy(&build.musl_root(target).unwrap().join("lib").join(obj), &into.join(obj));
133+
build.copy(&build.musl_root(target).unwrap().join("lib").join(obj), &into.join(obj));
134134
}
135135
}
136136

@@ -220,13 +220,13 @@ impl Step for StdLink {
220220
target_compiler.host,
221221
target);
222222
let libdir = builder.sysroot_libdir(target_compiler, target);
223-
add_to_sysroot(&libdir, &libstd_stamp(build, compiler, target));
223+
add_to_sysroot(&build, &libdir, &libstd_stamp(build, compiler, target));
224224

225225
if build.config.sanitizers && compiler.stage != 0 && target == "x86_64-apple-darwin" {
226226
// The sanitizers are only built in stage1 or above, so the dylibs will
227227
// be missing in stage0 and causes panic. See the `std()` function above
228228
// for reason why the sanitizers are not built in stage0.
229-
copy_apple_sanitizer_dylibs(&build.native_dir(target), "osx", &libdir);
229+
copy_apple_sanitizer_dylibs(&build, &build.native_dir(target), "osx", &libdir);
230230
}
231231

232232
builder.ensure(tool::CleanTools {
@@ -237,15 +237,15 @@ impl Step for StdLink {
237237
}
238238
}
239239

240-
fn copy_apple_sanitizer_dylibs(native_dir: &Path, platform: &str, into: &Path) {
240+
fn copy_apple_sanitizer_dylibs(build: &Build, native_dir: &Path, platform: &str, into: &Path) {
241241
for &sanitizer in &["asan", "tsan"] {
242242
let filename = format!("libclang_rt.{}_{}_dynamic.dylib", sanitizer, platform);
243243
let mut src_path = native_dir.join(sanitizer);
244244
src_path.push("build");
245245
src_path.push("lib");
246246
src_path.push("darwin");
247247
src_path.push(&filename);
248-
copy(&src_path, &into.join(filename));
248+
build.copy(&src_path, &into.join(filename));
249249
}
250250
}
251251

@@ -301,15 +301,15 @@ impl Step for StartupObjects {
301301
.arg(src_file));
302302
}
303303

304-
copy(dst_file, &sysroot_dir.join(file.to_string() + ".o"));
304+
build.copy(dst_file, &sysroot_dir.join(file.to_string() + ".o"));
305305
}
306306

307307
for obj in ["crt2.o", "dllcrt2.o"].iter() {
308308
let src = compiler_file(build,
309309
build.cc(target),
310310
target,
311311
obj);
312-
copy(&src, &sysroot_dir.join(obj));
312+
build.copy(&src, &sysroot_dir.join(obj));
313313
}
314314
}
315315
}
@@ -420,7 +420,7 @@ impl Step for TestLink {
420420
&compiler.host,
421421
target_compiler.host,
422422
target);
423-
add_to_sysroot(&builder.sysroot_libdir(target_compiler, target),
423+
add_to_sysroot(&build, &builder.sysroot_libdir(target_compiler, target),
424424
&libtest_stamp(build, compiler, target));
425425
builder.ensure(tool::CleanTools {
426426
compiler: target_compiler,
@@ -575,7 +575,7 @@ impl Step for RustcLink {
575575
&compiler.host,
576576
target_compiler.host,
577577
target);
578-
add_to_sysroot(&builder.sysroot_libdir(target_compiler, target),
578+
add_to_sysroot(&build, &builder.sysroot_libdir(target_compiler, target),
579579
&librustc_stamp(build, compiler, target));
580580
builder.ensure(tool::CleanTools {
581581
compiler: target_compiler,
@@ -690,7 +690,7 @@ impl Step for CodegenBackend {
690690
cargo.arg("--features").arg(features),
691691
&tmp_stamp,
692692
false);
693-
if cfg!(test) {
693+
if builder.config.dry_run {
694694
return;
695695
}
696696
let mut files = files.into_iter()
@@ -736,6 +736,10 @@ fn copy_codegen_backends_to_sysroot(builder: &Builder,
736736
let dst = builder.sysroot_codegen_backends(target_compiler);
737737
t!(fs::create_dir_all(&dst));
738738

739+
if builder.config.dry_run {
740+
return;
741+
}
742+
739743
for backend in builder.config.rust_codegen_backends.iter() {
740744
let stamp = codegen_backend_stamp(build, compiler, target, *backend);
741745
let mut dylib = String::new();
@@ -751,7 +755,7 @@ fn copy_codegen_backends_to_sysroot(builder: &Builder,
751755
backend,
752756
&filename[dot..])
753757
};
754-
copy(&file, &dst.join(target_filename));
758+
build.copy(&file, &dst.join(target_filename));
755759
}
756760
}
757761

@@ -767,7 +771,7 @@ fn copy_lld_to_sysroot(builder: &Builder,
767771
t!(fs::create_dir_all(&dst));
768772

769773
let exe = exe("lld", &target);
770-
copy(&lld_install_root.join("bin").join(&exe), &dst.join(&exe));
774+
builder.copy(&lld_install_root.join("bin").join(&exe), &dst.join(&exe));
771775
}
772776

773777
/// Cargo's output path for the standard library in a given stage, compiled
@@ -936,10 +940,10 @@ impl Step for Assemble {
936940
let sysroot_libdir = sysroot.join(libdir(&*host));
937941
t!(fs::create_dir_all(&sysroot_libdir));
938942
let src_libdir = builder.sysroot_libdir(build_compiler, host);
939-
for f in t!(fs::read_dir(&src_libdir)).map(|f| t!(f)) {
943+
for f in builder.read_dir(&src_libdir) {
940944
let filename = f.file_name().into_string().unwrap();
941945
if is_dylib(&filename) {
942-
copy(&f.path(), &sysroot_libdir.join(&filename));
946+
builder.copy(&f.path(), &sysroot_libdir.join(&filename));
943947
}
944948
}
945949

@@ -957,7 +961,7 @@ impl Step for Assemble {
957961
t!(fs::create_dir_all(&bindir));
958962
let compiler = builder.rustc(target_compiler);
959963
let _ = fs::remove_file(&compiler);
960-
copy(&rustc, &compiler);
964+
builder.copy(&rustc, &compiler);
961965

962966
target_compiler
963967
}
@@ -967,10 +971,10 @@ impl Step for Assemble {
967971
///
968972
/// For a particular stage this will link the file listed in `stamp` into the
969973
/// `sysroot_dst` provided.
970-
pub fn add_to_sysroot(sysroot_dst: &Path, stamp: &Path) {
974+
pub fn add_to_sysroot(build: &Build, sysroot_dst: &Path, stamp: &Path) {
971975
t!(fs::create_dir_all(&sysroot_dst));
972-
for path in read_stamp_file(stamp) {
973-
copy(&path, &sysroot_dst.join(path.file_name().unwrap()));
976+
for path in build.read_stamp_file(stamp) {
977+
build.copy(&path, &sysroot_dst.join(path.file_name().unwrap()));
974978
}
975979
}
976980

@@ -1000,6 +1004,10 @@ fn stderr_isatty() -> bool {
10001004
pub fn run_cargo(build: &Build, cargo: &mut Command, stamp: &Path, is_check: bool)
10011005
-> Vec<PathBuf>
10021006
{
1007+
if build.config.dry_run {
1008+
return Vec::new();
1009+
}
1010+
10031011
// `target_root_dir` looks like $dir/$target/release
10041012
let target_root_dir = stamp.parent().unwrap();
10051013
// `target_deps_dir` looks like $dir/$target/release/deps
@@ -1141,6 +1149,9 @@ pub fn stream_cargo(
11411149
cargo: &mut Command,
11421150
cb: &mut FnMut(CargoMessage),
11431151
) -> bool {
1152+
if build.config.dry_run {
1153+
return true;
1154+
}
11441155
// Instruct Cargo to give us json messages on stdout, critically leaving
11451156
// stderr as piped so we can get those pretty colors.
11461157
cargo.arg("--message-format").arg("json")

src/bootstrap/config.rs

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
1616
use std::collections::{HashMap, HashSet};
1717
use std::env;
18-
use std::fs::File;
18+
use std::fs::{self, File};
1919
use std::io::prelude::*;
2020
use std::path::{Path, PathBuf};
2121
use std::process;
@@ -69,6 +69,7 @@ pub struct Config {
6969
pub jobs: Option<u32>,
7070
pub cmd: Subcommand,
7171
pub incremental: bool,
72+
pub dry_run: bool,
7273

7374
// llvm codegen options
7475
pub llvm_enabled: bool,
@@ -362,8 +363,15 @@ impl Config {
362363
config.jobs = flags.jobs;
363364
config.cmd = flags.cmd;
364365
config.incremental = flags.incremental;
366+
config.dry_run = flags.dry_run;
365367
config.keep_stage = flags.keep_stage;
366368

369+
if config.dry_run {
370+
let dir = config.out.join("tmp-dry-run");
371+
t!(fs::create_dir_all(&dir));
372+
config.out = dir;
373+
}
374+
367375
// If --target was specified but --host wasn't specified, don't run any host-only tests.
368376
config.run_host_only = !(flags.host.is_empty() && !flags.target.is_empty());
369377

0 commit comments

Comments
 (0)