Skip to content

Commit b633341

Browse files
committed
Auto merge of #44792 - Mark-Simulacrum:correct-deps, r=alexcrichton
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. Fixes #44739.
2 parents 87a8e8e + 686c101 commit b633341

File tree

7 files changed

+132
-79
lines changed

7 files changed

+132
-79
lines changed

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`

src/bootstrap/check.rs

+40-34
Original file line numberDiff line numberDiff line change
@@ -340,25 +340,28 @@ impl Step for Miri {
340340
let host = self.host;
341341
let compiler = builder.compiler(1, host);
342342

343-
let miri = builder.ensure(tool::Miri { compiler, target: self.host });
344-
let mut cargo = builder.cargo(compiler, Mode::Tool, host, "test");
345-
cargo.arg("--manifest-path").arg(build.src.join("src/tools/miri/Cargo.toml"));
346-
347-
// Don't build tests dynamically, just a pain to work with
348-
cargo.env("RUSTC_NO_PREFER_DYNAMIC", "1");
349-
// miri tests need to know about the stage sysroot
350-
cargo.env("MIRI_SYSROOT", builder.sysroot(compiler));
351-
cargo.env("RUSTC_TEST_SUITE", builder.rustc(compiler));
352-
cargo.env("RUSTC_LIB_PATH", builder.rustc_libdir(compiler));
353-
cargo.env("MIRI_PATH", miri);
354-
355-
builder.add_rustc_lib_path(compiler, &mut cargo);
356-
357-
try_run_expecting(
358-
build,
359-
&mut cargo,
360-
builder.build.config.toolstate.miri.passes(ToolState::Testing),
361-
);
343+
if let Some(miri) = builder.ensure(tool::Miri { compiler, target: self.host }) {
344+
let mut cargo = builder.cargo(compiler, Mode::Tool, host, "test");
345+
cargo.arg("--manifest-path").arg(build.src.join("src/tools/miri/Cargo.toml"));
346+
347+
// Don't build tests dynamically, just a pain to work with
348+
cargo.env("RUSTC_NO_PREFER_DYNAMIC", "1");
349+
// miri tests need to know about the stage sysroot
350+
cargo.env("MIRI_SYSROOT", builder.sysroot(compiler));
351+
cargo.env("RUSTC_TEST_SUITE", builder.rustc(compiler));
352+
cargo.env("RUSTC_LIB_PATH", builder.rustc_libdir(compiler));
353+
cargo.env("MIRI_PATH", miri);
354+
355+
builder.add_rustc_lib_path(compiler, &mut cargo);
356+
357+
try_run_expecting(
358+
build,
359+
&mut cargo,
360+
builder.build.config.toolstate.miri.passes(ToolState::Testing),
361+
);
362+
} else {
363+
eprintln!("failed to test miri: could not build");
364+
}
362365
}
363366
}
364367

@@ -391,24 +394,27 @@ impl Step for Clippy {
391394
let host = self.host;
392395
let compiler = builder.compiler(stage, host);
393396

394-
let clippy = builder.ensure(tool::Clippy { compiler, target: self.host });
395-
let mut cargo = builder.cargo(compiler, Mode::Tool, host, "test");
396-
cargo.arg("--manifest-path").arg(build.src.join("src/tools/clippy/Cargo.toml"));
397+
if let Some(clippy) = builder.ensure(tool::Clippy { compiler, target: self.host }) {
398+
let mut cargo = builder.cargo(compiler, Mode::Tool, host, "test");
399+
cargo.arg("--manifest-path").arg(build.src.join("src/tools/clippy/Cargo.toml"));
397400

398-
// Don't build tests dynamically, just a pain to work with
399-
cargo.env("RUSTC_NO_PREFER_DYNAMIC", "1");
400-
// clippy tests need to know about the stage sysroot
401-
cargo.env("SYSROOT", builder.sysroot(compiler));
402-
// clippy tests need to find the driver
403-
cargo.env("CLIPPY_DRIVER_PATH", clippy);
401+
// Don't build tests dynamically, just a pain to work with
402+
cargo.env("RUSTC_NO_PREFER_DYNAMIC", "1");
403+
// clippy tests need to know about the stage sysroot
404+
cargo.env("SYSROOT", builder.sysroot(compiler));
405+
// clippy tests need to find the driver
406+
cargo.env("CLIPPY_DRIVER_PATH", clippy);
404407

405-
builder.add_rustc_lib_path(compiler, &mut cargo);
408+
builder.add_rustc_lib_path(compiler, &mut cargo);
406409

407-
try_run_expecting(
408-
build,
409-
&mut cargo,
410-
builder.build.config.toolstate.clippy.passes(ToolState::Testing),
411-
);
410+
try_run_expecting(
411+
build,
412+
&mut cargo,
413+
builder.build.config.toolstate.clippy.passes(ToolState::Testing),
414+
);
415+
} else {
416+
eprintln!("failed to test clippy: could not build");
417+
}
412418
}
413419
}
414420

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 {

src/bootstrap/dist.rs

+3-1
Original file line numberDiff line numberDiff line change
@@ -1073,10 +1073,12 @@ impl Step for Rls {
10731073
t!(fs::create_dir_all(&image));
10741074

10751075
// Prepare the image directory
1076+
// We expect RLS to build, because we've exited this step above if tool
1077+
// state for RLS isn't testing.
10761078
let rls = builder.ensure(tool::Rls {
10771079
compiler: builder.compiler(stage, build.build),
10781080
target
1079-
});
1081+
}).expect("Rls to build: toolstate is testing");
10801082
install(&rls, &image.join("bin"), 0o755);
10811083
let doc = image.join("share/doc/rls");
10821084
install(&src.join("README.md"), &doc, 0o644);

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 {

src/bootstrap/tool.rs

+49-25
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

@@ -70,7 +86,7 @@ struct ToolBuild {
7086
}
7187

7288
impl Step for ToolBuild {
73-
type Output = PathBuf;
89+
type Output = Option<PathBuf>;
7490

7591
fn should_run(run: ShouldRun) -> ShouldRun {
7692
run.never()
@@ -80,7 +96,7 @@ impl Step for ToolBuild {
8096
///
8197
/// This will build the specified tool with the specified `host` compiler in
8298
/// `stage` into the normal cargo output directory.
83-
fn run(self, builder: &Builder) -> PathBuf {
99+
fn run(self, builder: &Builder) -> Option<PathBuf> {
84100
let build = builder.build;
85101
let compiler = self.compiler;
86102
let target = self.target;
@@ -100,7 +116,15 @@ 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+
if expectation == BuildExpectation::Succeeding || expectation == BuildExpectation::None {
120+
let cargo_out = build.cargo_out(compiler, Mode::Tool, target)
121+
.join(exe(tool, &compiler.host));
122+
let bin = build.tools_dir(compiler).join(exe(tool, &compiler.host));
123+
copy(&cargo_out, &bin);
124+
Some(bin)
125+
} else {
126+
None
127+
}
104128
}
105129
}
106130

@@ -209,7 +233,7 @@ macro_rules! tool {
209233
mode: $mode,
210234
path: $path,
211235
expectation: BuildExpectation::None,
212-
})
236+
}).expect("expected to build -- BuildExpectation::None")
213237
}
214238
}
215239
)+
@@ -257,7 +281,7 @@ impl Step for RemoteTestServer {
257281
mode: Mode::Libstd,
258282
path: "src/tools/remote-test-server",
259283
expectation: BuildExpectation::None,
260-
})
284+
}).expect("expected to build -- BuildExpectation::None")
261285
}
262286
}
263287

@@ -375,7 +399,7 @@ impl Step for Cargo {
375399
mode: Mode::Librustc,
376400
path: "src/tools/cargo",
377401
expectation: BuildExpectation::None,
378-
})
402+
}).expect("BuildExpectation::None - expected to build")
379403
}
380404
}
381405

@@ -386,7 +410,7 @@ pub struct Clippy {
386410
}
387411

388412
impl Step for Clippy {
389-
type Output = PathBuf;
413+
type Output = Option<PathBuf>;
390414
const DEFAULT: bool = true;
391415
const ONLY_HOSTS: bool = true;
392416

@@ -401,7 +425,7 @@ impl Step for Clippy {
401425
});
402426
}
403427

404-
fn run(self, builder: &Builder) -> PathBuf {
428+
fn run(self, builder: &Builder) -> Option<PathBuf> {
405429
// Clippy depends on procedural macros (serde), which requires a full host
406430
// compiler to be available, so we need to depend on that.
407431
builder.ensure(compile::Rustc {
@@ -426,7 +450,7 @@ pub struct Rls {
426450
}
427451

428452
impl Step for Rls {
429-
type Output = PathBuf;
453+
type Output = Option<PathBuf>;
430454
const DEFAULT: bool = true;
431455
const ONLY_HOSTS: bool = true;
432456

@@ -442,7 +466,7 @@ impl Step for Rls {
442466
});
443467
}
444468

445-
fn run(self, builder: &Builder) -> PathBuf {
469+
fn run(self, builder: &Builder) -> Option<PathBuf> {
446470
builder.ensure(native::Openssl {
447471
target: self.target,
448472
});
@@ -470,7 +494,7 @@ pub struct Rustfmt {
470494
}
471495

472496
impl Step for Rustfmt {
473-
type Output = PathBuf;
497+
type Output = Option<PathBuf>;
474498
const DEFAULT: bool = true;
475499
const ONLY_HOSTS: bool = true;
476500

@@ -486,7 +510,7 @@ impl Step for Rustfmt {
486510
});
487511
}
488512

489-
fn run(self, builder: &Builder) -> PathBuf {
513+
fn run(self, builder: &Builder) -> Option<PathBuf> {
490514
builder.ensure(ToolBuild {
491515
compiler: self.compiler,
492516
target: self.target,
@@ -506,7 +530,7 @@ pub struct Miri {
506530
}
507531

508532
impl Step for Miri {
509-
type Output = PathBuf;
533+
type Output = Option<PathBuf>;
510534
const DEFAULT: bool = true;
511535
const ONLY_HOSTS: bool = true;
512536

@@ -522,7 +546,7 @@ impl Step for Miri {
522546
});
523547
}
524548

525-
fn run(self, builder: &Builder) -> PathBuf {
549+
fn run(self, builder: &Builder) -> Option<PathBuf> {
526550
builder.ensure(ToolBuild {
527551
compiler: self.compiler,
528552
target: self.target,

0 commit comments

Comments
 (0)