Skip to content

Commit d3ad841

Browse files
authored
Rollup merge of #122590 - Nilstrieb:bootstrap-do-you-know-what-the-word-copy-means, r=Mark-Simulacrum
bootstrap: Don't name things copy that are not copies The bootstrap copy methods don't actually copy, they just hard link. Simply lying about it being "copying" can be very confusing! (ask me how I know!). I'm not sure whether the name I chose is the ideal name, but it's definitely better than before.
2 parents a9f8f8b + 52f84fa commit d3ad841

File tree

7 files changed

+79
-63
lines changed

7 files changed

+79
-63
lines changed

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

+21-20
Original file line numberDiff line numberDiff line change
@@ -231,7 +231,7 @@ impl Step for Std {
231231
let target_sysroot_bin =
232232
builder.sysroot_libdir(compiler, target).parent().unwrap().join("bin");
233233
t!(fs::create_dir_all(&target_sysroot_bin));
234-
builder.cp_r(&src_sysroot_bin, &target_sysroot_bin);
234+
builder.cp_link_r(&src_sysroot_bin, &target_sysroot_bin);
235235
}
236236
}
237237

@@ -307,7 +307,7 @@ fn copy_and_stamp(
307307
dependency_type: DependencyType,
308308
) {
309309
let target = libdir.join(name);
310-
builder.copy(&sourcedir.join(name), &target);
310+
builder.copy_link(&sourcedir.join(name), &target);
311311

312312
target_deps.push((target, dependency_type));
313313
}
@@ -316,7 +316,7 @@ fn copy_llvm_libunwind(builder: &Builder<'_>, target: TargetSelection, libdir: &
316316
let libunwind_path = builder.ensure(llvm::Libunwind { target });
317317
let libunwind_source = libunwind_path.join("libunwind.a");
318318
let libunwind_target = libdir.join("libunwind.a");
319-
builder.copy(&libunwind_source, &libunwind_target);
319+
builder.copy_link(&libunwind_source, &libunwind_target);
320320
libunwind_target
321321
}
322322

@@ -385,7 +385,7 @@ fn copy_self_contained_objects(
385385
for &obj in &["crtbegin.o", "crtbeginS.o", "crtend.o", "crtendS.o"] {
386386
let src = crt_path.join(obj);
387387
let target = libdir_self_contained.join(obj);
388-
builder.copy(&src, &target);
388+
builder.copy_link(&src, &target);
389389
target_deps.push((target, DependencyType::TargetSelfContained));
390390
}
391391

@@ -418,7 +418,7 @@ fn copy_self_contained_objects(
418418
for obj in ["crt2.o", "dllcrt2.o"].iter() {
419419
let src = compiler_file(builder, &builder.cc(target), target, CLang::C, obj);
420420
let target = libdir_self_contained.join(obj);
421-
builder.copy(&src, &target);
421+
builder.copy_link(&src, &target);
422422
target_deps.push((target, DependencyType::TargetSelfContained));
423423
}
424424
}
@@ -637,7 +637,7 @@ impl Step for StdLink {
637637
let stage0_bin_dir = builder.out.join(host).join("stage0/bin");
638638
let sysroot_bin_dir = sysroot.join("bin");
639639
t!(fs::create_dir_all(&sysroot_bin_dir));
640-
builder.cp_r(&stage0_bin_dir, &sysroot_bin_dir);
640+
builder.cp_link_r(&stage0_bin_dir, &sysroot_bin_dir);
641641

642642
// Copy all *.so files from stage0/lib to stage0-sysroot/lib
643643
let stage0_lib_dir = builder.out.join(host).join("stage0/lib");
@@ -646,7 +646,8 @@ impl Step for StdLink {
646646
let file = t!(file);
647647
let path = file.path();
648648
if path.is_file() && is_dylib(&file.file_name().into_string().unwrap()) {
649-
builder.copy(&path, &sysroot.join("lib").join(path.file_name().unwrap()));
649+
builder
650+
.copy_link(&path, &sysroot.join("lib").join(path.file_name().unwrap()));
650651
}
651652
}
652653
}
@@ -661,7 +662,7 @@ impl Step for StdLink {
661662
.join(host)
662663
.join("codegen-backends");
663664
if stage0_codegen_backends.exists() {
664-
builder.cp_r(&stage0_codegen_backends, &sysroot_codegen_backends);
665+
builder.cp_link_r(&stage0_codegen_backends, &sysroot_codegen_backends);
665666
}
666667
}
667668
}
@@ -684,7 +685,7 @@ fn copy_sanitizers(
684685

685686
for runtime in &runtimes {
686687
let dst = libdir.join(&runtime.name);
687-
builder.copy(&runtime.path, &dst);
688+
builder.copy_link(&runtime.path, &dst);
688689

689690
// The `aarch64-apple-ios-macabi` and `x86_64-apple-ios-macabi` are also supported for
690691
// sanitizers, but they share a sanitizer runtime with `${arch}-apple-darwin`, so we do
@@ -790,7 +791,7 @@ impl Step for StartupObjects {
790791
}
791792

792793
let target = sysroot_dir.join((*file).to_string() + ".o");
793-
builder.copy(dst_file, &target);
794+
builder.copy_link(dst_file, &target);
794795
target_deps.push((target, DependencyType::Target));
795796
}
796797

@@ -812,7 +813,7 @@ fn cp_rustc_component_to_ci_sysroot(
812813
if src.is_dir() {
813814
t!(fs::create_dir_all(dst));
814815
} else {
815-
builder.copy(&src, &dst);
816+
builder.copy_link(&src, &dst);
816817
}
817818
}
818819
}
@@ -1443,7 +1444,7 @@ fn copy_codegen_backends_to_sysroot(
14431444
let dot = filename.find('.').unwrap();
14441445
format!("{}-{}{}", &filename[..dash], builder.rust_release(), &filename[dot..])
14451446
};
1446-
builder.copy(file, &dst.join(target_filename));
1447+
builder.copy_link(file, &dst.join(target_filename));
14471448
}
14481449
}
14491450

@@ -1599,7 +1600,7 @@ impl Step for Sysroot {
15991600
OsStr::new(std::env::consts::DLL_EXTENSION),
16001601
];
16011602
let ci_rustc_dir = builder.config.ci_rustc_dir();
1602-
builder.cp_filtered(&ci_rustc_dir, &sysroot, &|path| {
1603+
builder.cp_link_filtered(&ci_rustc_dir, &sysroot, &|path| {
16031604
if path.extension().map_or(true, |ext| !filtered_extensions.contains(&ext)) {
16041605
return true;
16051606
}
@@ -1791,7 +1792,7 @@ impl Step for Assemble {
17911792
let filename = f.file_name().into_string().unwrap();
17921793
if (is_dylib(&filename) || is_debug_info(&filename)) && !proc_macros.contains(&filename)
17931794
{
1794-
builder.copy(&f.path(), &rustc_libdir.join(&filename));
1795+
builder.copy_link(&f.path(), &rustc_libdir.join(&filename));
17951796
}
17961797
}
17971798

@@ -1805,15 +1806,15 @@ impl Step for Assemble {
18051806
if let Some(lld_install) = lld_install {
18061807
let src_exe = exe("lld", target_compiler.host);
18071808
let dst_exe = exe("rust-lld", target_compiler.host);
1808-
builder.copy(&lld_install.join("bin").join(src_exe), &libdir_bin.join(dst_exe));
1809+
builder.copy_link(&lld_install.join("bin").join(src_exe), &libdir_bin.join(dst_exe));
18091810
let self_contained_lld_dir = libdir_bin.join("gcc-ld");
18101811
t!(fs::create_dir_all(&self_contained_lld_dir));
18111812
let lld_wrapper_exe = builder.ensure(crate::core::build_steps::tool::LldWrapper {
18121813
compiler: build_compiler,
18131814
target: target_compiler.host,
18141815
});
18151816
for name in crate::LLD_FILE_NAMES {
1816-
builder.copy(
1817+
builder.copy_link(
18171818
&lld_wrapper_exe,
18181819
&self_contained_lld_dir.join(exe(name, target_compiler.host)),
18191820
);
@@ -1838,7 +1839,7 @@ impl Step for Assemble {
18381839
// When using `download-ci-llvm`, some of the tools
18391840
// may not exist, so skip trying to copy them.
18401841
if src_path.exists() {
1841-
builder.copy(&src_path, &libdir_bin.join(&tool_exe));
1842+
builder.copy_link(&src_path, &libdir_bin.join(&tool_exe));
18421843
}
18431844
}
18441845
}
@@ -1851,7 +1852,7 @@ impl Step for Assemble {
18511852
extra_features: vec![],
18521853
});
18531854
let tool_exe = exe("llvm-bitcode-linker", target_compiler.host);
1854-
builder.copy(&src_path, &libdir_bin.join(&tool_exe));
1855+
builder.copy_link(&src_path, &libdir_bin.join(&tool_exe));
18551856
}
18561857

18571858
// Ensure that `libLLVM.so` ends up in the newly build compiler directory,
@@ -1865,7 +1866,7 @@ impl Step for Assemble {
18651866
let bindir = sysroot.join("bin");
18661867
t!(fs::create_dir_all(bindir));
18671868
let compiler = builder.rustc(target_compiler);
1868-
builder.copy(&rustc, &compiler);
1869+
builder.copy_link(&rustc, &compiler);
18691870

18701871
target_compiler
18711872
}
@@ -1891,7 +1892,7 @@ pub fn add_to_sysroot(
18911892
DependencyType::Target => sysroot_dst,
18921893
DependencyType::TargetSelfContained => self_contained_dst,
18931894
};
1894-
builder.copy(&path, &dst.join(path.file_name().unwrap()));
1895+
builder.copy_link(&path, &dst.join(path.file_name().unwrap()));
18951896
}
18961897
}
18971898

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

+15-14
Original file line numberDiff line numberDiff line change
@@ -272,7 +272,7 @@ fn make_win_dist(
272272
let dist_bin_dir = rust_root.join("bin/");
273273
fs::create_dir_all(&dist_bin_dir).expect("creating dist_bin_dir failed");
274274
for src in rustc_dlls {
275-
builder.copy_to_folder(&src, &dist_bin_dir);
275+
builder.copy_link_to_folder(&src, &dist_bin_dir);
276276
}
277277

278278
//Copy platform tools to platform-specific bin directory
@@ -284,7 +284,7 @@ fn make_win_dist(
284284
.join("self-contained");
285285
fs::create_dir_all(&target_bin_dir).expect("creating target_bin_dir failed");
286286
for src in target_tools {
287-
builder.copy_to_folder(&src, &target_bin_dir);
287+
builder.copy_link_to_folder(&src, &target_bin_dir);
288288
}
289289

290290
// Warn windows-gnu users that the bundled GCC cannot compile C files
@@ -304,7 +304,7 @@ fn make_win_dist(
304304
.join("self-contained");
305305
fs::create_dir_all(&target_lib_dir).expect("creating target_lib_dir failed");
306306
for src in target_libs {
307-
builder.copy_to_folder(&src, &target_lib_dir);
307+
builder.copy_link_to_folder(&src, &target_lib_dir);
308308
}
309309
}
310310

@@ -400,7 +400,7 @@ impl Step for Rustc {
400400

401401
// Copy rustc binary
402402
t!(fs::create_dir_all(image.join("bin")));
403-
builder.cp_r(&src.join("bin"), &image.join("bin"));
403+
builder.cp_link_r(&src.join("bin"), &image.join("bin"));
404404

405405
// If enabled, copy rustdoc binary
406406
if builder
@@ -458,13 +458,13 @@ impl Step for Rustc {
458458
if builder.config.lld_enabled {
459459
let src_dir = builder.sysroot_libdir(compiler, host).parent().unwrap().join("bin");
460460
let rust_lld = exe("rust-lld", compiler.host);
461-
builder.copy(&src_dir.join(&rust_lld), &dst_dir.join(&rust_lld));
461+
builder.copy_link(&src_dir.join(&rust_lld), &dst_dir.join(&rust_lld));
462462
let self_contained_lld_src_dir = src_dir.join("gcc-ld");
463463
let self_contained_lld_dst_dir = dst_dir.join("gcc-ld");
464464
t!(fs::create_dir(&self_contained_lld_dst_dir));
465465
for name in crate::LLD_FILE_NAMES {
466466
let exe_name = exe(name, compiler.host);
467-
builder.copy(
467+
builder.copy_link(
468468
&self_contained_lld_src_dir.join(&exe_name),
469469
&self_contained_lld_dst_dir.join(&exe_name),
470470
);
@@ -609,9 +609,9 @@ fn copy_target_libs(builder: &Builder<'_>, target: TargetSelection, image: &Path
609609
t!(fs::create_dir_all(&self_contained_dst));
610610
for (path, dependency_type) in builder.read_stamp_file(stamp) {
611611
if dependency_type == DependencyType::TargetSelfContained {
612-
builder.copy(&path, &self_contained_dst.join(path.file_name().unwrap()));
612+
builder.copy_link(&path, &self_contained_dst.join(path.file_name().unwrap()));
613613
} else if dependency_type == DependencyType::Target || builder.config.build == target {
614-
builder.copy(&path, &dst.join(path.file_name().unwrap()));
614+
builder.copy_link(&path, &dst.join(path.file_name().unwrap()));
615615
}
616616
}
617617
}
@@ -865,7 +865,8 @@ fn copy_src_dirs(
865865
for item in src_dirs {
866866
let dst = &dst_dir.join(item);
867867
t!(fs::create_dir_all(dst));
868-
builder.cp_filtered(&base.join(item), dst, &|path| filter_fn(exclude_dirs, item, path));
868+
builder
869+
.cp_link_filtered(&base.join(item), dst, &|path| filter_fn(exclude_dirs, item, path));
869870
}
870871
}
871872

@@ -923,7 +924,7 @@ impl Step for Src {
923924
&dst_src,
924925
);
925926
for file in src_files.iter() {
926-
builder.copy(&builder.src.join(file), &dst_src.join(file));
927+
builder.copy_link(&builder.src.join(file), &dst_src.join(file));
927928
}
928929

929930
tarball.generate()
@@ -979,7 +980,7 @@ impl Step for PlainSourceTarball {
979980

980981
// Copy the files normally
981982
for item in &src_files {
982-
builder.copy(&builder.src.join(item), &plain_dst_src.join(item));
983+
builder.copy_link(&builder.src.join(item), &plain_dst_src.join(item));
983984
}
984985

985986
// Create the version file
@@ -1608,7 +1609,7 @@ impl Step for Extended {
16081609

16091610
let prepare = |name: &str| {
16101611
builder.create_dir(&pkg.join(name));
1611-
builder.cp_r(
1612+
builder.cp_link_r(
16121613
&work.join(format!("{}-{}", pkgname(builder, name), target.triple)),
16131614
&pkg.join(name),
16141615
);
@@ -1672,7 +1673,7 @@ impl Step for Extended {
16721673
} else {
16731674
name.to_string()
16741675
};
1675-
builder.cp_r(
1676+
builder.cp_link_r(
16761677
&work.join(format!("{}-{}", pkgname(builder, name), target.triple)).join(dir),
16771678
&exe.join(name),
16781679
);
@@ -2040,7 +2041,7 @@ fn install_llvm_file(
20402041
if install_symlink {
20412042
// For download-ci-llvm, also install the symlink, to match what LLVM does. Using a
20422043
// symlink is fine here, as this is not a rustup component.
2043-
builder.copy(&source, &full_dest);
2044+
builder.copy_link(&source, &full_dest);
20442045
} else {
20452046
// Otherwise, replace the symlink with an equivalent linker script. This is used when
20462047
// projects like miri link against librustc_driver.so. We don't use a symlink, as

src/bootstrap/src/core/build_steps/doc.rs

+6-3
Original file line numberDiff line numberDiff line change
@@ -520,7 +520,10 @@ impl Step for SharedAssets {
520520
t!(fs::write(&version_info, info));
521521
}
522522

523-
builder.copy(&builder.src.join("src").join("doc").join("rust.css"), &out.join("rust.css"));
523+
builder.copy_link(
524+
&builder.src.join("src").join("doc").join("rust.css"),
525+
&out.join("rust.css"),
526+
);
524527

525528
SharedAssetsPaths { version_info }
526529
}
@@ -718,7 +721,7 @@ fn doc_std(
718721
let _guard = builder.msg_doc(compiler, description, target);
719722

720723
builder.run(&mut cargo.into());
721-
builder.cp_r(&out_dir, out);
724+
builder.cp_link_r(&out_dir, out);
722725
}
723726

724727
#[derive(Debug, Clone, Hash, PartialEq, Eq)]
@@ -1151,7 +1154,7 @@ impl Step for RustcBook {
11511154
let out_base = builder.md_doc_out(self.target).join("rustc");
11521155
t!(fs::create_dir_all(&out_base));
11531156
let out_listing = out_base.join("src/lints");
1154-
builder.cp_r(&builder.src.join("src/doc/rustc"), &out_base);
1157+
builder.cp_link_r(&builder.src.join("src/doc/rustc"), &out_base);
11551158
builder.info(&format!("Generating lint docs ({})", self.target));
11561159

11571160
let rustc = builder.rustc(self.compiler);

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

+1-1
Original file line numberDiff line numberDiff line change
@@ -1367,7 +1367,7 @@ impl Step for RunMakeSupport {
13671367

13681368
let cargo_out =
13691369
builder.cargo_out(self.compiler, Mode::ToolStd, self.target).join(&lib_name);
1370-
builder.copy(&cargo_out, &lib);
1370+
builder.copy_link(&cargo_out, &lib);
13711371
lib
13721372
}
13731373
}

src/bootstrap/src/core/build_steps/tool.rs

+4-4
Original file line numberDiff line numberDiff line change
@@ -127,7 +127,7 @@ impl Step for ToolBuild {
127127
}
128128
let cargo_out = builder.cargo_out(compiler, self.mode, target).join(exe(tool, target));
129129
let bin = builder.tools_dir(compiler).join(exe(tool, target));
130-
builder.copy(&cargo_out, &bin);
130+
builder.copy_link(&cargo_out, &bin);
131131
bin
132132
}
133133
}
@@ -507,7 +507,7 @@ impl Step for Rustdoc {
507507
t!(fs::create_dir_all(&bindir));
508508
let bin_rustdoc = bindir.join(exe("rustdoc", target_compiler.host));
509509
let _ = fs::remove_file(&bin_rustdoc);
510-
builder.copy(&tool_rustdoc, &bin_rustdoc);
510+
builder.copy_link(&tool_rustdoc, &bin_rustdoc);
511511
bin_rustdoc
512512
} else {
513513
tool_rustdoc
@@ -686,7 +686,7 @@ impl Step for RustAnalyzerProcMacroSrv {
686686
// so that r-a can use it.
687687
let libexec_path = builder.sysroot(self.compiler).join("libexec");
688688
t!(fs::create_dir_all(&libexec_path));
689-
builder.copy(&path, &libexec_path.join("rust-analyzer-proc-macro-srv"));
689+
builder.copy_link(&path, &libexec_path.join("rust-analyzer-proc-macro-srv"));
690690

691691
Some(path)
692692
}
@@ -765,7 +765,7 @@ macro_rules! tool_extended {
765765
$(for add_bin in $add_bins_to_sysroot {
766766
let bin_source = tools_out.join(exe(add_bin, $sel.target));
767767
let bin_destination = bindir.join(exe(add_bin, $sel.compiler.host));
768-
$builder.copy(&bin_source, &bin_destination);
768+
$builder.copy_link(&bin_source, &bin_destination);
769769
})?
770770

771771
let tool = bindir.join(exe($tool_name, $sel.compiler.host));

0 commit comments

Comments
 (0)