Skip to content

Commit ceba2be

Browse files
committed
Vendor libtest's dependencies in the rust-src component
This is the Rust side of rust-lang/wg-cargo-std-aware#23
1 parent fe8f026 commit ceba2be

File tree

2 files changed

+45
-2
lines changed

2 files changed

+45
-2
lines changed

src/bootstrap/dist.rs

+24-2
Original file line numberDiff line numberDiff line change
@@ -1040,6 +1040,30 @@ impl Step for Src {
10401040
builder.copy(&builder.src.join(file), &dst_src.join(file));
10411041
}
10421042

1043+
// libtest includes std and everything else, so vendoring it
1044+
// creates exactly what's needed for `cargo -Zbuild-std` or any
1045+
// other analysis of the stdlib's source. Cargo also needs help
1046+
// finding the lock, so we copy it to libtest temporarily.
1047+
//
1048+
// Note that this requires std to only have one version of each
1049+
// crate. e.g. two versions of getopts won't be patchable.
1050+
let dst_libtest = dst_src.join("library/test");
1051+
let dst_vendor = dst_src.join("vendor");
1052+
let root_lock = dst_src.join("Cargo.lock");
1053+
let temp_lock = dst_libtest.join("Cargo.lock");
1054+
1055+
// `cargo vendor` will delete everything from the lockfile that
1056+
// isn't used by libtest, so we need to not use any links!
1057+
builder.really_copy(&root_lock, &temp_lock);
1058+
1059+
let mut cmd = Command::new(&builder.initial_cargo);
1060+
cmd.arg("vendor").arg(dst_vendor).current_dir(&dst_libtest);
1061+
builder.info("Dist src");
1062+
let _time = timeit(builder);
1063+
builder.run(&mut cmd);
1064+
1065+
builder.remove(&temp_lock);
1066+
10431067
// Create source tarball in rust-installer format
10441068
let mut cmd = rust_installer(builder);
10451069
cmd.arg("generate")
@@ -1056,8 +1080,6 @@ impl Step for Src {
10561080
.arg("--component-name=rust-src")
10571081
.arg("--legacy-manifest-dirs=rustlib,cargo");
10581082

1059-
builder.info("Dist src");
1060-
let _time = timeit(builder);
10611083
builder.run(&mut cmd);
10621084

10631085
builder.remove_dir(&image);

src/bootstrap/lib.rs

+21
Original file line numberDiff line numberDiff line change
@@ -1167,6 +1167,27 @@ impl Build {
11671167
paths
11681168
}
11691169

1170+
/// Copies a file from `src` to `dst` and doesn't use links, so
1171+
/// that the copy can be modified without affecting the original.
1172+
pub fn really_copy(&self, src: &Path, dst: &Path) {
1173+
if self.config.dry_run {
1174+
return;
1175+
}
1176+
self.verbose_than(1, &format!("Copy {:?} to {:?}", src, dst));
1177+
if src == dst {
1178+
return;
1179+
}
1180+
let _ = fs::remove_file(&dst);
1181+
let metadata = t!(src.symlink_metadata());
1182+
if let Err(e) = fs::copy(src, dst) {
1183+
panic!("failed to copy `{}` to `{}`: {}", src.display(), dst.display(), e)
1184+
}
1185+
t!(fs::set_permissions(dst, metadata.permissions()));
1186+
let atime = FileTime::from_last_access_time(&metadata);
1187+
let mtime = FileTime::from_last_modification_time(&metadata);
1188+
t!(filetime::set_file_times(dst, atime, mtime));
1189+
}
1190+
11701191
/// Copies a file from `src` to `dst`
11711192
pub fn copy(&self, src: &Path, dst: &Path) {
11721193
if self.config.dry_run {

0 commit comments

Comments
 (0)