Skip to content

Commit d196639

Browse files
authored
Rollup merge of #145845 - Kobzol:fix-distcheck, r=jieyouxu
Make `x test distcheck` self-contained Before, the checked components were extracted under the checked out source root, which caused us to test some weird combination of tarball + checkout sources/aritfacts/configuration. Now `x test distcheck` works with an external temporary directory instead, which should make it self-contained. I also moved some config from the Dockerfile to the test itself, and fixed an issue in tidy that caused `x test tidy` to fail on tarball sources. I also removed `.args(&builder.config.configure_args)`, because it was passing all kinds of crap from the CI config to the distcheck step, which was making it less reproducible. Fixes: #145183 r? ```@jieyouxu``` try-job: x86_64-gnu-distcheck
2 parents cf0df73 + 2ea8621 commit d196639

File tree

4 files changed

+53
-25
lines changed

4 files changed

+53
-25
lines changed

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

Lines changed: 30 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -3117,53 +3117,63 @@ 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));
3124-
3125-
// Guarantee that these are built before we begin running.
3126-
builder.ensure(dist::PlainSourceTarball);
3127-
builder.ensure(dist::Src);
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");
3123+
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);
3129+
3130+
let configure_args: Vec<String> = std::env::var("DISTCHECK_CONFIGURE_ARGS")
3131+
.map(|args| args.split(" ").map(|s| s.to_string()).collect::<Vec<String>>())
3132+
.unwrap_or_default();
31283133

31293134
command("tar")
31303135
.arg("-xf")
3131-
.arg(builder.ensure(dist::PlainSourceTarball).tarball())
3136+
.arg(plain_src_tarball.tarball())
31323137
.arg("--strip-components=1")
3133-
.current_dir(&dir)
3138+
.current_dir(&plain_src_dir)
31343139
.run(builder);
31353140
command("./configure")
3136-
.args(&builder.config.configure_args)
3141+
.arg("--set")
3142+
.arg("rust.omit-git-hash=false")
3143+
.args(&configure_args)
31373144
.arg("--enable-vendor")
3138-
.current_dir(&dir)
3145+
.current_dir(&plain_src_dir)
31393146
.run(builder);
31403147
command(helpers::make(&builder.config.host_target.triple))
31413148
.arg("check")
3142-
.current_dir(&dir)
3149+
// Do not run the build as if we were in CI, otherwise git would be assumed to be
3150+
// present, but we build from a tarball here
3151+
.env("GITHUB_ACTIONS", "0")
3152+
.current_dir(&plain_src_dir)
31433153
.run(builder);
31443154

31453155
// Now make sure that rust-src has all of libstd's dependencies
31463156
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));
3157+
let src_tarball = builder.ensure(dist::Src);
3158+
let src_dir = root_dir.join("distcheck-src");
3159+
builder.clear_dir(&src_dir);
31503160

31513161
command("tar")
31523162
.arg("-xf")
3153-
.arg(builder.ensure(dist::Src).tarball())
3163+
.arg(src_tarball.tarball())
31543164
.arg("--strip-components=1")
3155-
.current_dir(&dir)
3165+
.current_dir(&src_dir)
31563166
.run(builder);
31573167

3158-
let toml = dir.join("rust-src/lib/rustlib/src/rust/library/std/Cargo.toml");
3168+
let toml = src_dir.join("rust-src/lib/rustlib/src/rust/library/std/Cargo.toml");
31593169
command(&builder.initial_cargo)
31603170
// Will read the libstd Cargo.toml
31613171
// which uses the unstable `public-dependency` feature.
31623172
.env("RUSTC_BOOTSTRAP", "1")
31633173
.arg("generate-lockfile")
31643174
.arg("--manifest-path")
31653175
.arg(&toml)
3166-
.current_dir(&dir)
3176+
.current_dir(&src_dir)
31673177
.run(builder);
31683178
}
31693179
}

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: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -33,9 +33,7 @@ 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
36+
# Make distcheck builds faster
37+
ENV DISTCHECK_CONFIGURE_ARGS "--enable-sccache"
3838

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
39+
ENV SCRIPT python3 ../x.py test distcheck

src/tools/tidy/src/gcc_submodule.rs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,12 @@ pub fn check(root_path: &Path, compiler_path: &Path, bad: &mut bool) {
2424
.output()
2525
.expect("Cannot determine git SHA of the src/gcc checkout");
2626

27+
// Git is not available or we are in a tarball
28+
if !git_output.status.success() {
29+
eprintln!("Cannot figure out the SHA of the GCC submodule");
30+
return;
31+
}
32+
2733
// This can return e.g.
2834
// -e607be166673a8de9fc07f6f02c60426e556c5f2 src/gcc
2935
// e607be166673a8de9fc07f6f02c60426e556c5f2 src/gcc (master-e607be166673a8de9fc07f6f02c60426e556c5f2.e607be)

0 commit comments

Comments
 (0)