Skip to content

Commit a3229e4

Browse files
committed
Make x test distcheck more self-contained
1 parent ee361e8 commit a3229e4

File tree

3 files changed

+36
-24
lines changed

3 files changed

+36
-24
lines changed

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

Lines changed: 21 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -3117,53 +3117,56 @@ impl Step for Distcheck {
31173117
///
31183118
/// FIXME(#136822): dist components are under-tested.
31193119
fn run(self, builder: &Builder<'_>) {
3120-
builder.info("Distcheck");
3121-
let dir = builder.tempdir().join("distcheck");
3122-
let _ = fs::remove_dir_all(&dir);
3123-
t!(fs::create_dir_all(&dir));
3120+
// Use a temporary directory completely outside the current checkout, to avoid reusing any
3121+
// local source code, built artifacts or configuration by accident
3122+
let root_dir = std::env::temp_dir().join("distcheck");
31243123

3125-
// Guarantee that these are built before we begin running.
3126-
builder.ensure(dist::PlainSourceTarball);
3127-
builder.ensure(dist::Src);
3124+
// Check that we can build some basic things from the plain source tarball
3125+
builder.info("Distcheck plain source tarball");
3126+
let plain_src_tarball = builder.ensure(dist::PlainSourceTarball);
3127+
let plain_src_dir = root_dir.join("distcheck-plain-src");
3128+
builder.clear_dir(&plain_src_dir);
31283129

31293130
command("tar")
31303131
.arg("-xf")
3131-
.arg(builder.ensure(dist::PlainSourceTarball).tarball())
3132+
.arg(plain_src_tarball.tarball())
31323133
.arg("--strip-components=1")
3133-
.current_dir(&dir)
3134+
.current_dir(&plain_src_dir)
31343135
.run(builder);
31353136
command("./configure")
3137+
.arg("--set")
3138+
.arg("rust.omit-git-hash=false")
31363139
.args(&builder.config.configure_args)
31373140
.arg("--enable-vendor")
3138-
.current_dir(&dir)
3141+
.current_dir(&plain_src_dir)
31393142
.run(builder);
31403143
command(helpers::make(&builder.config.host_target.triple))
31413144
.arg("check")
3142-
.current_dir(&dir)
3145+
.current_dir(&plain_src_dir)
31433146
.run(builder);
31443147

31453148
// Now make sure that rust-src has all of libstd's dependencies
31463149
builder.info("Distcheck rust-src");
3147-
let dir = builder.tempdir().join("distcheck-src");
3148-
let _ = fs::remove_dir_all(&dir);
3149-
t!(fs::create_dir_all(&dir));
3150+
let src_tarball = builder.ensure(dist::Src);
3151+
let src_dir = root_dir.join("distcheck-src");
3152+
builder.clear_dir(&src_dir);
31503153

31513154
command("tar")
31523155
.arg("-xf")
3153-
.arg(builder.ensure(dist::Src).tarball())
3156+
.arg(src_tarball.tarball())
31543157
.arg("--strip-components=1")
3155-
.current_dir(&dir)
3158+
.current_dir(&src_dir)
31563159
.run(builder);
31573160

3158-
let toml = dir.join("rust-src/lib/rustlib/src/rust/library/std/Cargo.toml");
3161+
let toml = src_dir.join("rust-src/lib/rustlib/src/rust/library/std/Cargo.toml");
31593162
command(&builder.initial_cargo)
31603163
// Will read the libstd Cargo.toml
31613164
// which uses the unstable `public-dependency` feature.
31623165
.env("RUSTC_BOOTSTRAP", "1")
31633166
.arg("generate-lockfile")
31643167
.arg("--manifest-path")
31653168
.arg(&toml)
3166-
.current_dir(&dir)
3169+
.current_dir(&src_dir)
31673170
.run(builder);
31683171
}
31693172
}

src/bootstrap/src/lib.rs

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1950,6 +1950,20 @@ impl Build {
19501950
t!(fs::remove_dir_all(dir))
19511951
}
19521952

1953+
/// Make sure that `dir` will be an empty existing directory after this function ends.
1954+
/// If it existed before, it will be first deleted.
1955+
fn clear_dir(&self, dir: &Path) {
1956+
if self.config.dry_run() {
1957+
return;
1958+
}
1959+
1960+
#[cfg(feature = "tracing")]
1961+
let _span = trace_io!("dir-clear", ?dir);
1962+
1963+
let _ = std::fs::remove_dir_all(dir);
1964+
self.create_dir(dir);
1965+
}
1966+
19531967
fn read_dir(&self, dir: &Path) -> impl Iterator<Item = fs::DirEntry> {
19541968
let iter = match fs::read_dir(dir) {
19551969
Ok(v) => v,

src/ci/docker/host-x86_64/x86_64-gnu-distcheck/Dockerfile

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -33,9 +33,4 @@ RUN apt-get update && apt-get install -y --no-install-recommends \
3333
COPY scripts/sccache.sh /scripts/
3434
RUN sh /scripts/sccache.sh
3535

36-
# We are disabling CI LLVM since distcheck is an offline build.
37-
ENV NO_DOWNLOAD_CI_LLVM 1
38-
39-
ENV RUST_CONFIGURE_ARGS --build=x86_64-unknown-linux-gnu --set rust.omit-git-hash=false
40-
ENV SCRIPT python3 ../x.py --stage 2 test distcheck
41-
ENV DIST_SRC 1
36+
ENV SCRIPT python3 ../x.py test distcheck

0 commit comments

Comments
 (0)