Skip to content

Commit 0fcd3e7

Browse files
Make sure to clear out the stageN-{rustc,std,tools} directories.
We copy built tool binaries into a dedicated directory to avoid deleting them, stageN-tools-bin. These aren't ever cleared out by code, since there should be no reason to do so, and we'll simply overwrite them as necessary. When clearing out the stageN-{std,rustc,tools} directories, make sure to delete both Cargo directories -- per-target and build scripts. This ensures that changing libstd doesn't cause problems due to build scripts not being rebuilt, even though they should be.
1 parent b796087 commit 0fcd3e7

File tree

5 files changed

+72
-31
lines changed

5 files changed

+72
-31
lines changed

Diff for: src/bootstrap/builder.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -612,7 +612,7 @@ impl<'a> Builder<'a> {
612612
// Set this for all builds to make sure doc builds also get it.
613613
cargo.env("CFG_RELEASE_CHANNEL", &self.build.config.channel);
614614

615-
if self.is_verbose() {
615+
if self.is_very_verbose() {
616616
cargo.arg("-v");
617617
}
618618
// FIXME: cargo bench does not accept `--release`

Diff for: src/bootstrap/compile.rs

+9-14
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ use build_helper::{output, mtime, up_to_date};
2929
use filetime::FileTime;
3030
use serde_json;
3131

32-
use util::{exe, libdir, is_dylib, copy};
32+
use util::{exe, libdir, is_dylib, copy, read_stamp_file};
3333
use {Build, Compiler, Mode};
3434
use native;
3535
use tool;
@@ -102,7 +102,7 @@ impl Step for Std {
102102
copy_musl_third_party_objects(build, target, &libdir);
103103
}
104104

105-
let out_dir = build.cargo_out(compiler, Mode::Libstd, target);
105+
let out_dir = build.stage_out(compiler, Mode::Libstd);
106106
build.clear_if_dirty(&out_dir, &builder.rustc(compiler));
107107
let mut cargo = builder.cargo(compiler, Mode::Libstd, target, "build");
108108
std_cargo(build, &compiler, target, &mut cargo);
@@ -354,7 +354,7 @@ impl Step for Test {
354354
let _folder = build.fold_output(|| format!("stage{}-test", compiler.stage));
355355
println!("Building stage{} test artifacts ({} -> {})", compiler.stage,
356356
&compiler.host, target);
357-
let out_dir = build.cargo_out(compiler, Mode::Libtest, target);
357+
let out_dir = build.stage_out(compiler, Mode::Libtest);
358358
build.clear_if_dirty(&out_dir, &libstd_stamp(build, compiler, target));
359359
let mut cargo = builder.cargo(compiler, Mode::Libtest, target, "build");
360360
test_cargo(build, &compiler, target, &mut cargo);
@@ -480,8 +480,9 @@ impl Step for Rustc {
480480
println!("Building stage{} compiler artifacts ({} -> {})",
481481
compiler.stage, &compiler.host, target);
482482

483-
let out_dir = build.cargo_out(compiler, Mode::Librustc, target);
484-
build.clear_if_dirty(&out_dir, &libtest_stamp(build, compiler, target));
483+
let stage_out = builder.stage_out(compiler, Mode::Librustc);
484+
build.clear_if_dirty(&stage_out, &libstd_stamp(build, compiler, target));
485+
build.clear_if_dirty(&stage_out, &libtest_stamp(build, compiler, target));
485486

486487
let mut cargo = builder.cargo(compiler, Mode::Librustc, target, "build");
487488
rustc_cargo(build, &compiler, target, &mut cargo);
@@ -757,15 +758,7 @@ impl Step for Assemble {
757758
/// `sysroot_dst` provided.
758759
fn add_to_sysroot(sysroot_dst: &Path, stamp: &Path) {
759760
t!(fs::create_dir_all(&sysroot_dst));
760-
let mut contents = Vec::new();
761-
t!(t!(File::open(stamp)).read_to_end(&mut contents));
762-
// This is the method we use for extracting paths from the stamp file passed to us. See
763-
// run_cargo for more information (in this file).
764-
for part in contents.split(|b| *b == 0) {
765-
if part.is_empty() {
766-
continue
767-
}
768-
let path = Path::new(t!(str::from_utf8(part)));
761+
for path in read_stamp_file(stamp) {
769762
copy(&path, &sysroot_dst.join(path.file_name().unwrap()));
770763
}
771764
}
@@ -938,6 +931,8 @@ fn run_cargo(build: &Build, cargo: &mut Command, stamp: &Path) {
938931
let max = max.unwrap();
939932
let max_path = max_path.unwrap();
940933
if stamp_contents == new_contents && max <= stamp_mtime {
934+
build.verbose(&format!("not updating {:?}; contents equal and {} <= {}",
935+
stamp, max, stamp_mtime));
941936
return
942937
}
943938
if max > stamp_mtime {

Diff for: src/bootstrap/lib.rs

+11-2
Original file line numberDiff line numberDiff line change
@@ -385,16 +385,19 @@ impl Build {
385385
/// Clear out `dir` if `input` is newer.
386386
///
387387
/// After this executes, it will also ensure that `dir` exists.
388-
fn clear_if_dirty(&self, dir: &Path, input: &Path) {
388+
fn clear_if_dirty(&self, dir: &Path, input: &Path) -> bool {
389389
let stamp = dir.join(".stamp");
390+
let mut cleared = false;
390391
if mtime(&stamp) < mtime(input) {
391392
self.verbose(&format!("Dirty - {}", dir.display()));
392393
let _ = fs::remove_dir_all(dir);
394+
cleared = true;
393395
} else if stamp.exists() {
394-
return
396+
return cleared;
395397
}
396398
t!(fs::create_dir_all(dir));
397399
t!(File::create(stamp));
400+
cleared
398401
}
399402

400403
/// Get the space-separated set of activated features for the standard
@@ -435,6 +438,12 @@ impl Build {
435438
if self.config.rust_optimize {"release"} else {"debug"}
436439
}
437440

441+
fn tools_dir(&self, compiler: Compiler) -> PathBuf {
442+
let out = self.out.join(&*compiler.host).join(format!("stage{}-tools-bin", compiler.stage));
443+
t!(fs::create_dir_all(&out));
444+
out
445+
}
446+
438447
/// Get the directory for incremental by-products when using the
439448
/// given compiler.
440449
fn incremental_dir(&self, compiler: Compiler) -> PathBuf {

Diff for: src/bootstrap/tool.rs

+32-12
Original file line numberDiff line numberDiff line change
@@ -38,24 +38,40 @@ impl Step for CleanTools {
3838
run.never()
3939
}
4040

41-
/// Build a tool in `src/tools`
42-
///
43-
/// This will build the specified tool with the specified `host` compiler in
44-
/// `stage` into the normal cargo output directory.
4541
fn run(self, builder: &Builder) {
4642
let build = builder.build;
4743
let compiler = self.compiler;
4844
let target = self.target;
4945
let mode = self.mode;
5046

51-
let stamp = match mode {
52-
Mode::Libstd => libstd_stamp(build, compiler, target),
53-
Mode::Libtest => libtest_stamp(build, compiler, target),
54-
Mode::Librustc => librustc_stamp(build, compiler, target),
55-
_ => panic!(),
47+
// This is for the original compiler, but if we're forced to use stage 1, then
48+
// std/test/rustc stamps won't exist in stage 2, so we need to get those from stage 1, since
49+
// we copy the libs forward.
50+
let tools_dir = build.stage_out(compiler, Mode::Tool);
51+
let compiler = if builder.force_use_stage1(compiler, target) {
52+
builder.compiler(1, compiler.host)
53+
} else {
54+
compiler
5655
};
57-
let out_dir = build.cargo_out(compiler, Mode::Tool, target);
58-
build.clear_if_dirty(&out_dir, &stamp);
56+
57+
for &cur_mode in &[Mode::Libstd, Mode::Libtest, Mode::Librustc] {
58+
let stamp = match cur_mode {
59+
Mode::Libstd => libstd_stamp(build, compiler, target),
60+
Mode::Libtest => libtest_stamp(build, compiler, target),
61+
Mode::Librustc => librustc_stamp(build, compiler, target),
62+
_ => panic!(),
63+
};
64+
65+
if build.clear_if_dirty(&tools_dir, &stamp) {
66+
break;
67+
}
68+
69+
// If we are a rustc tool, and std changed, we also need to clear ourselves out -- our
70+
// dependencies depend on std. Therefore, we iterate up until our own mode.
71+
if mode == cur_mode {
72+
break;
73+
}
74+
}
5975
}
6076
}
6177

@@ -100,7 +116,11 @@ impl Step for ToolBuild {
100116

101117
let mut cargo = prepare_tool_cargo(builder, compiler, target, "build", path);
102118
build.run_expecting(&mut cargo, expectation);
103-
build.cargo_out(compiler, Mode::Tool, target).join(exe(tool, &compiler.host))
119+
let cargo_out = build.cargo_out(compiler, Mode::Tool, target)
120+
.join(exe(tool, &compiler.host));
121+
let bin = build.tools_dir(compiler).join(exe(tool, &compiler.host));
122+
copy(&cargo_out, &bin);
123+
bin
104124
}
105125
}
106126

Diff for: src/bootstrap/util.rs

+19-2
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,9 @@
1414
//! not a lot of interesting happenings here unfortunately.
1515
1616
use std::env;
17-
use std::fs;
18-
use std::io::{self, Write};
17+
use std::str;
18+
use std::fs::{self, File};
19+
use std::io::{self, Read, Write};
1920
use std::path::{Path, PathBuf};
2021
use std::process::Command;
2122
use std::time::{SystemTime, Instant};
@@ -50,6 +51,22 @@ pub fn copy(src: &Path, dst: &Path) {
5051
t!(filetime::set_file_times(dst, atime, mtime));
5152
}
5253

54+
pub fn read_stamp_file(stamp: &Path) -> Vec<PathBuf> {
55+
let mut paths = Vec::new();
56+
let mut contents = Vec::new();
57+
t!(t!(File::open(stamp)).read_to_end(&mut contents));
58+
// This is the method we use for extracting paths from the stamp file passed to us. See
59+
// run_cargo for more information (in compile.rs).
60+
for part in contents.split(|b| *b == 0) {
61+
if part.is_empty() {
62+
continue
63+
}
64+
let path = PathBuf::from(t!(str::from_utf8(part)));
65+
paths.push(path);
66+
}
67+
paths
68+
}
69+
5370
/// Copies the `src` directory recursively to `dst`. Both are assumed to exist
5471
/// when this function is called.
5572
pub fn cp_r(src: &Path, dst: &Path) {

0 commit comments

Comments
 (0)