Skip to content

Commit 96ba480

Browse files
authored
Rollup merge of rust-lang#41047 - cuviper:src_is_git, r=alexcrichton
Only use cargo-vendor if building from git sources The only time we need to vendor sources is when building from git. If one is building from a rustc source tarball, everything should already be in place. This also matters for distros which do offline builds, as they can't install cargo-vendor this way. This adds a common `Build::src_is_git` flag, and then uses it in the dist-src target to decide whether to install or use `cargo-vendor` at all. Fixes rust-lang#41042.
2 parents d25a6d8 + 4d32ff4 commit 96ba480

File tree

3 files changed

+27
-24
lines changed

3 files changed

+27
-24
lines changed

src/bootstrap/dist.rs

Lines changed: 22 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -433,29 +433,32 @@ pub fn rust_src(build: &Build) {
433433
copy(&build.src.join(item), &dst_src.join(item));
434434
}
435435

436-
// Get cargo-vendor installed, if it isn't already.
437-
let mut has_cargo_vendor = false;
438-
let mut cmd = Command::new(&build.cargo);
439-
for line in output(cmd.arg("install").arg("--list")).lines() {
440-
has_cargo_vendor |= line.starts_with("cargo-vendor ");
441-
}
442-
if !has_cargo_vendor {
436+
// If we're building from git sources, we need to vendor a complete distribution.
437+
if build.src_is_git {
438+
// Get cargo-vendor installed, if it isn't already.
439+
let mut has_cargo_vendor = false;
440+
let mut cmd = Command::new(&build.cargo);
441+
for line in output(cmd.arg("install").arg("--list")).lines() {
442+
has_cargo_vendor |= line.starts_with("cargo-vendor ");
443+
}
444+
if !has_cargo_vendor {
445+
let mut cmd = Command::new(&build.cargo);
446+
cmd.arg("install")
447+
.arg("--force")
448+
.arg("--debug")
449+
.arg("--vers").arg(CARGO_VENDOR_VERSION)
450+
.arg("cargo-vendor")
451+
.env("RUSTC", &build.rustc);
452+
build.run(&mut cmd);
453+
}
454+
455+
// Vendor all Cargo dependencies
443456
let mut cmd = Command::new(&build.cargo);
444-
cmd.arg("install")
445-
.arg("--force")
446-
.arg("--debug")
447-
.arg("--vers").arg(CARGO_VENDOR_VERSION)
448-
.arg("cargo-vendor")
449-
.env("RUSTC", &build.rustc);
457+
cmd.arg("vendor")
458+
.current_dir(&dst_src.join("src"));
450459
build.run(&mut cmd);
451460
}
452461

453-
// Vendor all Cargo dependencies
454-
let mut cmd = Command::new(&build.cargo);
455-
cmd.arg("vendor")
456-
.current_dir(&dst_src.join("src"));
457-
build.run(&mut cmd);
458-
459462
// Create source tarball in rust-installer format
460463
let mut cmd = Command::new(SH_CMD);
461464
cmd.arg(sanitize_sh(&build.src.join("src/rust-installer/gen-installer.sh")))

src/bootstrap/lib.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -162,6 +162,7 @@ pub struct Build {
162162
cxx: HashMap<String, gcc::Tool>,
163163
crates: HashMap<String, Crate>,
164164
is_sudo: bool,
165+
src_is_git: bool,
165166
}
166167

167168
#[derive(Debug)]
@@ -233,6 +234,7 @@ impl Build {
233234
};
234235
let rust_info = channel::GitInfo::new(&src);
235236
let cargo_info = channel::GitInfo::new(&src.join("cargo"));
237+
let src_is_git = src.join(".git").exists();
236238

237239
Build {
238240
flags: flags,
@@ -251,6 +253,7 @@ impl Build {
251253
lldb_version: None,
252254
lldb_python_dir: None,
253255
is_sudo: is_sudo,
256+
src_is_git: src_is_git,
254257
}
255258
}
256259

@@ -307,10 +310,7 @@ impl Build {
307310
OutOfSync,
308311
}
309312

310-
if !self.config.submodules {
311-
return
312-
}
313-
if fs::metadata(self.src.join(".git")).is_err() {
313+
if !self.src_is_git || !self.config.submodules {
314314
return
315315
}
316316
let git = || {

src/bootstrap/sanity.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ pub fn check(build: &mut Build) {
6565

6666
// If we've got a git directory we're gona need git to update
6767
// submodules and learn about various other aspects.
68-
if fs::metadata(build.src.join(".git")).is_ok() {
68+
if build.src_is_git {
6969
need_cmd("git".as_ref());
7070
}
7171

0 commit comments

Comments
 (0)