Skip to content

Commit dc8a8d9

Browse files
committed
use BuildStamp instead of std paths and strings
Signed-off-by: onur-ozkan <[email protected]>
1 parent 9aed5bb commit dc8a8d9

File tree

12 files changed

+86
-69
lines changed

12 files changed

+86
-69
lines changed

src/bootstrap/src/core/build_steps/check.rs

Lines changed: 20 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,5 @@
11
//! Implementation of compiling the compiler and standard library, in "check"-based modes.
22
3-
use std::path::PathBuf;
4-
53
use crate::core::build_steps::compile::{
64
add_to_sysroot, run_cargo, rustc_cargo, rustc_cargo_env, std_cargo, std_crates_for_run_make,
75
};
@@ -10,6 +8,7 @@ use crate::core::builder::{
108
self, Alias, Builder, Kind, RunConfig, ShouldRun, Step, crate_description,
119
};
1210
use crate::core::config::TargetSelection;
11+
use crate::utils::build_stamp::BuildStamp;
1312
use crate::{Compiler, Mode, Subcommand};
1413

1514
#[derive(Debug, Clone, PartialEq, Eq, Hash)]
@@ -393,8 +392,9 @@ impl Step for RustAnalyzer {
393392

394393
/// Cargo's output path in a given stage, compiled by a particular
395394
/// compiler for the specified target.
396-
fn stamp(builder: &Builder<'_>, compiler: Compiler, target: TargetSelection) -> PathBuf {
397-
builder.cargo_out(compiler, Mode::ToolRustc, target).join(".rust-analyzer-check.stamp")
395+
fn stamp(builder: &Builder<'_>, compiler: Compiler, target: TargetSelection) -> BuildStamp {
396+
BuildStamp::new(&builder.cargo_out(compiler, Mode::ToolRustc, target))
397+
.with_prefix("rust-analyzer-check")
398398
}
399399
}
400400
}
@@ -469,9 +469,8 @@ fn run_tool_check_step(
469469
cargo.arg("--all-targets");
470470
}
471471

472-
let stamp = builder
473-
.cargo_out(compiler, Mode::ToolRustc, target)
474-
.join(format!(".{}-check.stamp", step_type_name.to_lowercase()));
472+
let stamp = BuildStamp::new(&builder.cargo_out(compiler, Mode::ToolRustc, target))
473+
.with_prefix(&format!("{}-check", step_type_name.to_lowercase()));
475474

476475
let _guard = builder.msg_check(format!("{display_name} artifacts"), target);
477476
run_cargo(builder, cargo, builder.config.free_args.clone(), &stamp, vec![], true, false);
@@ -502,8 +501,8 @@ tool_check_step!(Compiletest { path: "src/tools/compiletest", default: false });
502501

503502
/// Cargo's output path for the standard library in a given stage, compiled
504503
/// by a particular compiler for the specified target.
505-
fn libstd_stamp(builder: &Builder<'_>, compiler: Compiler, target: TargetSelection) -> PathBuf {
506-
builder.cargo_out(compiler, Mode::Std, target).join(".libstd-check.stamp")
504+
fn libstd_stamp(builder: &Builder<'_>, compiler: Compiler, target: TargetSelection) -> BuildStamp {
505+
BuildStamp::new(&builder.cargo_out(compiler, Mode::Std, target)).with_prefix("libstd-check")
507506
}
508507

509508
/// Cargo's output path for the standard library in a given stage, compiled
@@ -512,14 +511,19 @@ fn libstd_test_stamp(
512511
builder: &Builder<'_>,
513512
compiler: Compiler,
514513
target: TargetSelection,
515-
) -> PathBuf {
516-
builder.cargo_out(compiler, Mode::Std, target).join(".libstd-check-test.stamp")
514+
) -> BuildStamp {
515+
BuildStamp::new(&builder.cargo_out(compiler, Mode::Std, target))
516+
.with_prefix("libstd-check-test")
517517
}
518518

519519
/// Cargo's output path for librustc in a given stage, compiled by a particular
520520
/// compiler for the specified target.
521-
fn librustc_stamp(builder: &Builder<'_>, compiler: Compiler, target: TargetSelection) -> PathBuf {
522-
builder.cargo_out(compiler, Mode::Rustc, target).join(".librustc-check.stamp")
521+
fn librustc_stamp(
522+
builder: &Builder<'_>,
523+
compiler: Compiler,
524+
target: TargetSelection,
525+
) -> BuildStamp {
526+
BuildStamp::new(&builder.cargo_out(compiler, Mode::Rustc, target)).with_prefix("librustc-check")
523527
}
524528

525529
/// Cargo's output path for librustc_codegen_llvm in a given stage, compiled by a particular
@@ -529,8 +533,7 @@ fn codegen_backend_stamp(
529533
compiler: Compiler,
530534
target: TargetSelection,
531535
backend: &str,
532-
) -> PathBuf {
533-
builder
534-
.cargo_out(compiler, Mode::Codegen, target)
535-
.join(format!(".librustc_codegen_{backend}-check.stamp"))
536+
) -> BuildStamp {
537+
BuildStamp::new(&builder.cargo_out(compiler, Mode::Codegen, target))
538+
.with_prefix(&format!("librustc_codegen_{backend}-check"))
536539
}

src/bootstrap/src/core/build_steps/clean.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ use std::io::{self, ErrorKind};
1010
use std::path::Path;
1111

1212
use crate::core::builder::{Builder, RunConfig, ShouldRun, Step, crate_description};
13+
use crate::utils::build_stamp::BuildStamp;
1314
use crate::utils::helpers::t;
1415
use crate::{Build, Compiler, Kind, Mode, Subcommand};
1516

@@ -146,7 +147,7 @@ fn clean_default(build: &Build) {
146147
rm_rf(&build.out.join("dist"));
147148
rm_rf(&build.out.join("bootstrap").join(".last-warned-change-id"));
148149
rm_rf(&build.out.join("bootstrap-shims-dump"));
149-
rm_rf(&build.out.join("rustfmt.stamp"));
150+
rm_rf(BuildStamp::new(&build.out).with_prefix("rustfmt").as_ref());
150151

151152
let mut hosts: Vec<_> = build.hosts.iter().map(|t| build.out.join(t)).collect();
152153
// After cross-compilation, artifacts of the host architecture (which may differ from build.host)

src/bootstrap/src/core/build_steps/clippy.rs

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ use crate::builder::{Builder, ShouldRun};
77
use crate::core::build_steps::compile::std_crates_for_run_make;
88
use crate::core::builder;
99
use crate::core::builder::{Alias, Kind, RunConfig, Step, crate_description};
10+
use crate::utils::build_stamp::BuildStamp;
1011
use crate::{Mode, Subcommand, TargetSelection};
1112

1213
/// Disable the most spammy clippy lints
@@ -307,9 +308,9 @@ macro_rules! lint_any {
307308
&target,
308309
);
309310

310-
let stamp = builder
311-
.cargo_out(compiler, Mode::ToolRustc, target)
312-
.join(format!(".{}-check.stamp", stringify!($name).to_lowercase()));
311+
let stringified_name = stringify!($name).to_lowercase();
312+
let stamp = BuildStamp::new(&builder.cargo_out(compiler, Mode::ToolRustc, target))
313+
.with_prefix(&format!("{}-check", stringified_name));
313314

314315
run_cargo(
315316
builder,

src/bootstrap/src/core/build_steps/compile.rs

Lines changed: 17 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ use crate::core::builder::{
2424
Builder, Cargo, Kind, PathSet, RunConfig, ShouldRun, Step, TaskPath, crate_description,
2525
};
2626
use crate::core::config::{DebuginfoLevel, LlvmLibunwind, RustcLto, TargetSelection};
27+
use crate::utils::build_stamp::BuildStamp;
2728
use crate::utils::exec::command;
2829
use crate::utils::helpers::{
2930
exe, get_clang_cl_resource_dir, is_debug_info, is_dylib, symlink_dir, t, up_to_date,
@@ -984,7 +985,7 @@ impl Step for Rustc {
984985
true, // Only ship rustc_driver.so and .rmeta files, not all intermediate .rlib files.
985986
);
986987

987-
let target_root_dir = stamp.parent().unwrap();
988+
let target_root_dir = stamp.as_ref().parent().unwrap();
988989
// When building `librustc_driver.so` (like `libLLVM.so`) on linux, it can contain
989990
// unexpected debuginfo from dependencies, for example from the C++ standard library used in
990991
// our LLVM wrapper. Unless we're explicitly requesting `librustc_driver` to be built with
@@ -1447,7 +1448,7 @@ impl Step for CodegenBackend {
14471448
.arg(builder.src.join(format!("compiler/rustc_codegen_{backend}/Cargo.toml")));
14481449
rustc_cargo_env(builder, &mut cargo, target, compiler.stage);
14491450

1450-
let tmp_stamp = out_dir.join(".tmp.stamp");
1451+
let tmp_stamp = BuildStamp::new(&out_dir).with_prefix("tmp");
14511452

14521453
let _guard = builder.msg_build(compiler, format_args!("codegen backend {backend}"), target);
14531454
let files = run_cargo(builder, cargo, vec![], &tmp_stamp, vec![], false, false);
@@ -1525,8 +1526,12 @@ fn copy_codegen_backends_to_sysroot(
15251526

15261527
/// Cargo's output path for the standard library in a given stage, compiled
15271528
/// by a particular compiler for the specified target.
1528-
pub fn libstd_stamp(builder: &Builder<'_>, compiler: Compiler, target: TargetSelection) -> PathBuf {
1529-
builder.cargo_out(compiler, Mode::Std, target).join(".libstd.stamp")
1529+
pub fn libstd_stamp(
1530+
builder: &Builder<'_>,
1531+
compiler: Compiler,
1532+
target: TargetSelection,
1533+
) -> BuildStamp {
1534+
BuildStamp::new(&builder.cargo_out(compiler, Mode::Std, target)).with_prefix("libstd")
15301535
}
15311536

15321537
/// Cargo's output path for librustc in a given stage, compiled by a particular
@@ -1535,8 +1540,8 @@ pub fn librustc_stamp(
15351540
builder: &Builder<'_>,
15361541
compiler: Compiler,
15371542
target: TargetSelection,
1538-
) -> PathBuf {
1539-
builder.cargo_out(compiler, Mode::Rustc, target).join(".librustc.stamp")
1543+
) -> BuildStamp {
1544+
BuildStamp::new(&builder.cargo_out(compiler, Mode::Rustc, target)).with_prefix("librustc")
15401545
}
15411546

15421547
/// Cargo's output path for librustc_codegen_llvm in a given stage, compiled by a particular
@@ -1546,10 +1551,9 @@ fn codegen_backend_stamp(
15461551
compiler: Compiler,
15471552
target: TargetSelection,
15481553
backend: &str,
1549-
) -> PathBuf {
1550-
builder
1551-
.cargo_out(compiler, Mode::Codegen, target)
1552-
.join(format!(".librustc_codegen_{backend}.stamp"))
1554+
) -> BuildStamp {
1555+
BuildStamp::new(&builder.cargo_out(compiler, Mode::Codegen, target))
1556+
.with_prefix(&format!("librustc_codegen_{backend}"))
15531557
}
15541558

15551559
pub fn compiler_file(
@@ -2014,7 +2018,7 @@ pub fn add_to_sysroot(
20142018
builder: &Builder<'_>,
20152019
sysroot_dst: &Path,
20162020
sysroot_host_dst: &Path,
2017-
stamp: &Path,
2021+
stamp: &BuildStamp,
20182022
) {
20192023
let self_contained_dst = &sysroot_dst.join("self-contained");
20202024
t!(fs::create_dir_all(sysroot_dst));
@@ -2034,13 +2038,13 @@ pub fn run_cargo(
20342038
builder: &Builder<'_>,
20352039
cargo: Cargo,
20362040
tail_args: Vec<String>,
2037-
stamp: &Path,
2041+
stamp: &BuildStamp,
20382042
additional_target_deps: Vec<(PathBuf, DependencyType)>,
20392043
is_check: bool,
20402044
rlib_only_metadata: bool,
20412045
) -> Vec<PathBuf> {
20422046
// `target_root_dir` looks like $dir/$target/release
2043-
let target_root_dir = stamp.parent().unwrap();
2047+
let target_root_dir = stamp.as_ref().parent().unwrap();
20442048
// `target_deps_dir` looks like $dir/$target/release/deps
20452049
let target_deps_dir = target_root_dir.join("deps");
20462050
// `host_root_dir` looks like $dir/release

src/bootstrap/src/core/build_steps/dist.rs

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ use crate::core::build_steps::vendor::default_paths_to_vendor;
2323
use crate::core::build_steps::{compile, llvm};
2424
use crate::core::builder::{Builder, Kind, RunConfig, ShouldRun, Step};
2525
use crate::core::config::TargetSelection;
26+
use crate::utils::build_stamp::BuildStamp;
2627
use crate::utils::channel::{self, Info};
2728
use crate::utils::exec::{BootstrapCommand, command};
2829
use crate::utils::helpers::{
@@ -584,7 +585,7 @@ fn skip_host_target_lib(builder: &Builder<'_>, compiler: Compiler) -> bool {
584585
/// Check that all objects in rlibs for UEFI targets are COFF. This
585586
/// ensures that the C compiler isn't producing ELF objects, which would
586587
/// not link correctly with the COFF objects.
587-
fn verify_uefi_rlib_format(builder: &Builder<'_>, target: TargetSelection, stamp: &Path) {
588+
fn verify_uefi_rlib_format(builder: &Builder<'_>, target: TargetSelection, stamp: &BuildStamp) {
588589
if !target.ends_with("-uefi") {
589590
return;
590591
}
@@ -615,7 +616,12 @@ fn verify_uefi_rlib_format(builder: &Builder<'_>, target: TargetSelection, stamp
615616
}
616617

617618
/// Copy stamped files into an image's `target/lib` directory.
618-
fn copy_target_libs(builder: &Builder<'_>, target: TargetSelection, image: &Path, stamp: &Path) {
619+
fn copy_target_libs(
620+
builder: &Builder<'_>,
621+
target: TargetSelection,
622+
image: &Path,
623+
stamp: &BuildStamp,
624+
) {
619625
let dst = image.join("lib/rustlib").join(target).join("lib");
620626
let self_contained_dst = dst.join("self-contained");
621627
t!(fs::create_dir_all(&dst));

src/bootstrap/src/core/build_steps/format.rs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ use build_helper::git::get_git_modified_files;
1111
use ignore::WalkBuilder;
1212

1313
use crate::core::builder::Builder;
14+
use crate::utils::build_stamp::BuildStamp;
1415
use crate::utils::exec::command;
1516
use crate::utils::helpers::{self, program_out_of_date, t};
1617

@@ -55,8 +56,8 @@ fn rustfmt(
5556
}
5657
}
5758

58-
fn get_rustfmt_version(build: &Builder<'_>) -> Option<(String, PathBuf)> {
59-
let stamp_file = build.out.join("rustfmt.stamp");
59+
fn get_rustfmt_version(build: &Builder<'_>) -> Option<(String, BuildStamp)> {
60+
let stamp_file = BuildStamp::new(&build.out).with_prefix("rustfmt");
6061

6162
let mut cmd = command(build.initial_rustfmt()?);
6263
cmd.arg("--version");

src/bootstrap/src/core/build_steps/test.rs

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ use crate::core::builder::{
2121
};
2222
use crate::core::config::TargetSelection;
2323
use crate::core::config::flags::{Subcommand, get_completion};
24+
use crate::utils::build_stamp::BuildStamp;
2425
use crate::utils::exec::{BootstrapCommand, command};
2526
use crate::utils::helpers::{
2627
self, LldThreads, add_link_lib_path, add_rustdoc_cargo_linker_args, dylib_path, dylib_path_var,
@@ -2234,10 +2235,8 @@ impl BookTest {
22342235
&[],
22352236
);
22362237

2237-
let stamp = builder
2238-
.cargo_out(compiler, mode, target)
2239-
.join(PathBuf::from(dep).file_name().unwrap())
2240-
.with_extension("stamp");
2238+
let stamp = BuildStamp::new(&builder.cargo_out(compiler, mode, target))
2239+
.with_prefix(PathBuf::from(dep).file_name().and_then(|v| v.to_str()).unwrap());
22412240

22422241
let output_paths = run_cargo(builder, cargo, vec![], &stamp, vec![], false, false);
22432242
let directories = output_paths

src/bootstrap/src/core/download.rs

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ use build_helper::ci::CiEnv;
1010
use xz2::bufread::XzDecoder;
1111

1212
use crate::core::config::BUILDER_CONFIG_FILENAME;
13+
use crate::utils::build_stamp::BuildStamp;
1314
use crate::utils::exec::{BootstrapCommand, command};
1415
use crate::utils::helpers::{check_run, exe, hex_encode, move_file, program_out_of_date};
1516
use crate::{Config, t};
@@ -46,7 +47,7 @@ impl Config {
4647
self.verbose > 0
4748
}
4849

49-
pub(crate) fn create(&self, path: &Path, s: &str) {
50+
pub(crate) fn create<P: AsRef<Path>>(&self, path: P, s: &str) {
5051
if self.dry_run() {
5152
return;
5253
}
@@ -426,7 +427,7 @@ impl Config {
426427
let version = &self.stage0_metadata.compiler.version;
427428
let host = self.build;
428429

429-
let clippy_stamp = self.initial_sysroot.join(".clippy-stamp");
430+
let clippy_stamp = BuildStamp::new(&self.initial_sysroot).with_prefix("clippy");
430431
let cargo_clippy = self.initial_sysroot.join("bin").join(exe("cargo-clippy", host));
431432
if cargo_clippy.exists() && !program_out_of_date(&clippy_stamp, date) {
432433
return cargo_clippy;
@@ -460,7 +461,7 @@ impl Config {
460461
let host = self.build;
461462
let bin_root = self.out.join(host).join("rustfmt");
462463
let rustfmt_path = bin_root.join("bin").join(exe("rustfmt", host));
463-
let rustfmt_stamp = bin_root.join(".rustfmt-stamp");
464+
let rustfmt_stamp = BuildStamp::new(&bin_root).with_prefix("rustfmt");
464465
if rustfmt_path.exists() && !program_out_of_date(&rustfmt_stamp, &channel) {
465466
return Some(rustfmt_path);
466467
}
@@ -567,7 +568,7 @@ impl Config {
567568
) {
568569
let host = self.build.triple;
569570
let bin_root = self.out.join(host).join(sysroot);
570-
let rustc_stamp = bin_root.join(".rustc-stamp");
571+
let rustc_stamp = BuildStamp::new(&bin_root).with_prefix("rustc");
571572

572573
if !bin_root.join("bin").join(exe("rustc", self.build)).exists()
573574
|| program_out_of_date(&rustc_stamp, stamp_key)
@@ -728,7 +729,7 @@ download-rustc = false
728729
}
729730

730731
let llvm_root = self.ci_llvm_root();
731-
let llvm_stamp = llvm_root.join(".llvm-stamp");
732+
let llvm_stamp = BuildStamp::new(&llvm_root).with_prefix("llvm");
732733
let llvm_sha = detect_llvm_sha(self, self.rust_info.is_managed_git_subrepository());
733734
let key = format!("{}{}", llvm_sha, self.llvm_assertions);
734735
if program_out_of_date(&llvm_stamp, &key) && !self.dry_run() {

src/bootstrap/src/lib.rs

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ use build_helper::ci::gha;
3030
use build_helper::exit;
3131
use sha2::digest::Digest;
3232
use termcolor::{ColorChoice, StandardStream, WriteColor};
33+
use utils::build_stamp::BuildStamp;
3334
use utils::channel::GitInfo;
3435
use utils::helpers::hex_encode;
3536

@@ -604,13 +605,13 @@ impl Build {
604605
///
605606
/// After this executes, it will also ensure that `dir` exists.
606607
fn clear_if_dirty(&self, dir: &Path, input: &Path) -> bool {
607-
let stamp = dir.join(".stamp");
608+
let stamp = BuildStamp::new(dir);
608609
let mut cleared = false;
609-
if mtime(&stamp) < mtime(input) {
610+
if mtime(stamp.as_ref()) < mtime(input) {
610611
self.verbose(|| println!("Dirty - {}", dir.display()));
611612
let _ = fs::remove_dir_all(dir);
612613
cleared = true;
613-
} else if stamp.exists() {
614+
} else if stamp.as_ref().exists() {
614615
return cleared;
615616
}
616617
t!(fs::create_dir_all(dir));
@@ -1624,21 +1625,21 @@ Executed at: {executed_at}"#,
16241625
ret
16251626
}
16261627

1627-
fn read_stamp_file(&self, stamp: &Path) -> Vec<(PathBuf, DependencyType)> {
1628+
fn read_stamp_file(&self, stamp: &BuildStamp) -> Vec<(PathBuf, DependencyType)> {
16281629
if self.config.dry_run() {
16291630
return Vec::new();
16301631
}
16311632

1632-
if !stamp.exists() {
1633+
if !stamp.as_ref().exists() {
16331634
eprintln!(
16341635
"ERROR: Unable to find the stamp file {}, did you try to keep a nonexistent build stage?",
1635-
stamp.display()
1636+
stamp.as_ref().display()
16361637
);
16371638
crate::exit!(1);
16381639
}
16391640

16401641
let mut paths = Vec::new();
1641-
let contents = t!(fs::read(stamp), &stamp);
1642+
let contents = t!(fs::read(stamp.as_ref()), stamp.as_ref());
16421643
// This is the method we use for extracting paths from the stamp file passed to us. See
16431644
// run_cargo for more information (in compile.rs).
16441645
for part in contents.split(|b| *b == 0) {

0 commit comments

Comments
 (0)