Skip to content

Commit 287a252

Browse files
authored
Rollup merge of #87443 - jyn514:submodules-take-n, r=jyn514
Don't treat git repos as non-existent when `ignore_git` is set The new submodule handling depends on `is_git()` to be accurate to decide whether it should handle submodules at all or not. Unfortunately, `is_git()` treated "this directory does not have a git repository" and "this repository should not be used for SHA/version/commit date info" the same. This changes it to distinguish the two. To clarify: ignore_get is set by default whenever channel == "dev", which it is by default whenever you're compiling locally. So basically everyone would hit this, not just people who had explicitly configured ignore_git. Here's an example of an error this fixes: ``` $ x build Updating only changed submodules Submodules updated in 0.01 seconds Finished dev [unoptimized + debuginfo] target(s) in 0.17s warning: x.py has made several changes recently you may want to look at help: consider looking at the changes in `src/bootstrap/CHANGELOG.md` note: to silence this warning, add `changelog-seen = 2` at the top of `config.toml` Building stage0 std artifacts (x86_64-unknown-linux-gnu -> x86_64-unknown-linux-gnu) Finished release [optimized] target(s) in 0.16s Copying stage0 std from stage0 (x86_64-unknown-linux-gnu -> x86_64-unknown-linux-gnu / x86_64-unknown-linux-gnu) Building LLVM for x86_64-unknown-linux-gnu detected home dir change, cleaning out entire build directory running: "cmake" "/home/joshua/rustc3/src/llvm-project/llvm" "-G" "Ninja" "-DLLVM_ENABLE_ASSERTIONS=OFF" "-DLLVM_TARGETS_TO_BUILD=AArch64;ARM;BPF;Hexagon;MSP430;Mips;NVPTX;PowerPC;RISCV;Sparc;SystemZ;WebAssembly;X86" "-DLLVM_EXPERIMENTAL_TARGETS_TO_BUILD=AVR" "-DLLVM_INCLUDE_EXAMPLES=OFF" "-DLLVM_INCLUDE_DOCS=OFF" "-DLLVM_INCLUDE_BENCHMARKS=OFF" "-DLLVM_ENABLE_TERMINFO=OFF" "-DLLVM_ENABLE_LIBEDIT=OFF" "-DLLVM_ENABLE_BINDINGS=OFF" "-DLLVM_ENABLE_Z3_SOLVER=OFF" "-DLLVM_PARALLEL_COMPILE_JOBS=48" "-DLLVM_TARGET_ARCH=x86_64" "-DLLVM_DEFAULT_TARGET_TRIPLE=x86_64-unknown-linux-gnu" "-DLLVM_ENABLE_ZLIB=ON" "-DLLVM_ENABLE_LIBXML2=OFF" "-DLLVM_VERSION_SUFFIX=-rust-dev" "-DCMAKE_INSTALL_MESSAGE=LAZY" "-DCMAKE_C_COMPILER=gcc" "-DCMAKE_CXX_COMPILER=g++" "-DCMAKE_ASM_COMPILER=gcc" "-DCMAKE_C_FLAGS=-ffunction-sections -fdata-sections -fPIC -m64" "-DCMAKE_CXX_FLAGS=-ffunction-sections -fdata-sections -fPIC -m64" "-DCMAKE_INSTALL_PREFIX=/home/joshua/rustc3/build/x86_64-unknown-linux-gnu/llvm" "-DCMAKE_ASM_FLAGS= -ffunction-sections -fdata-sections -fPIC -m64" "-DCMAKE_BUILD_TYPE=Release" CMake Error: The source directory "/home/joshua/rustc3/src/llvm-project/llvm" does not exist. Specify --help for usage, or press the help button on the CMake GUI. thread 'main' panicked at ' command did not execute successfully, got: exit status: 1 build script failed, must exit now', /home/joshua/.local/lib/cargo/registry/src/gh.loli.garden-1ecc6299db9ec823/cmake-0.1.44/src/lib.rs:885:5 note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace finished in 0.783 seconds Build completed unsuccessfully in 0:00:01 ``` I *believe* this regression was only introduced in #87380, not #82653. ``@petrochenkov`` can you check that this fixes the issue you encountered in #82653 (comment) ? r? ``@Mark-Simulacrum``
2 parents 98f7a00 + 7cab739 commit 287a252

File tree

2 files changed

+37
-18
lines changed

2 files changed

+37
-18
lines changed

src/bootstrap/channel.rs

+36-17
Original file line numberDiff line numberDiff line change
@@ -12,11 +12,16 @@ use build_helper::output;
1212

1313
use crate::Build;
1414

15-
pub struct GitInfo {
16-
inner: Option<Info>,
15+
pub enum GitInfo {
16+
/// This is not a git repository.
17+
Absent,
18+
/// This is a git repository.
19+
/// If the info should be used (`ignore_git` is false), this will be
20+
/// `Some`, otherwise it will be `None`.
21+
Present(Option<Info>),
1722
}
1823

19-
struct Info {
24+
pub struct Info {
2025
commit_date: String,
2126
sha: String,
2227
short_sha: String,
@@ -25,14 +30,20 @@ struct Info {
2530
impl GitInfo {
2631
pub fn new(ignore_git: bool, dir: &Path) -> GitInfo {
2732
// See if this even begins to look like a git dir
28-
if ignore_git || !dir.join(".git").exists() {
29-
return GitInfo { inner: None };
33+
if !dir.join(".git").exists() {
34+
return GitInfo::Absent;
3035
}
3136

3237
// Make sure git commands work
3338
match Command::new("git").arg("rev-parse").current_dir(dir).output() {
3439
Ok(ref out) if out.status.success() => {}
35-
_ => return GitInfo { inner: None },
40+
_ => return GitInfo::Absent,
41+
}
42+
43+
// If we're ignoring the git info, we don't actually need to collect it, just make sure this
44+
// was a git repo in the first place.
45+
if ignore_git {
46+
return GitInfo::Present(None);
3647
}
3748

3849
// Ok, let's scrape some info
@@ -48,30 +59,35 @@ impl GitInfo {
4859
let short_ver_hash = output(
4960
Command::new("git").current_dir(dir).arg("rev-parse").arg("--short=9").arg("HEAD"),
5061
);
51-
GitInfo {
52-
inner: Some(Info {
53-
commit_date: ver_date.trim().to_string(),
54-
sha: ver_hash.trim().to_string(),
55-
short_sha: short_ver_hash.trim().to_string(),
56-
}),
62+
GitInfo::Present(Some(Info {
63+
commit_date: ver_date.trim().to_string(),
64+
sha: ver_hash.trim().to_string(),
65+
short_sha: short_ver_hash.trim().to_string(),
66+
}))
67+
}
68+
69+
fn info(&self) -> Option<&Info> {
70+
match self {
71+
GitInfo::Present(info) => info.as_ref(),
72+
GitInfo::Absent => None,
5773
}
5874
}
5975

6076
pub fn sha(&self) -> Option<&str> {
61-
self.inner.as_ref().map(|s| &s.sha[..])
77+
self.info().map(|s| &s.sha[..])
6278
}
6379

6480
pub fn sha_short(&self) -> Option<&str> {
65-
self.inner.as_ref().map(|s| &s.short_sha[..])
81+
self.info().map(|s| &s.short_sha[..])
6682
}
6783

6884
pub fn commit_date(&self) -> Option<&str> {
69-
self.inner.as_ref().map(|s| &s.commit_date[..])
85+
self.info().map(|s| &s.commit_date[..])
7086
}
7187

7288
pub fn version(&self, build: &Build, num: &str) -> String {
7389
let mut version = build.release(num);
74-
if let Some(ref inner) = self.inner {
90+
if let Some(ref inner) = self.info() {
7591
version.push_str(" (");
7692
version.push_str(&inner.short_sha);
7793
version.push(' ');
@@ -82,6 +98,9 @@ impl GitInfo {
8298
}
8399

84100
pub fn is_git(&self) -> bool {
85-
self.inner.is_some()
101+
match self {
102+
GitInfo::Absent => false,
103+
GitInfo::Present(_) => true,
104+
}
86105
}
87106
}

src/bootstrap/lib.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -1145,7 +1145,7 @@ impl Build {
11451145
match &self.config.channel[..] {
11461146
"stable" => num.to_string(),
11471147
"beta" => {
1148-
if self.rust_info.is_git() {
1148+
if self.rust_info.is_git() && !self.config.ignore_git {
11491149
format!("{}-beta.{}", num, self.beta_prerelease_version())
11501150
} else {
11511151
format!("{}-beta", num)

0 commit comments

Comments
 (0)