about summary refs log tree commit diff
diff options
context:
space:
mode:
authorJoshua Nelson <jyn514@gmail.com>2021-07-24 22:20:15 +0000
committerJoshua Nelson <jyn514@gmail.com>2021-07-25 00:03:44 +0000
commit7cab73928a3641e15a7c8d8e0d8b453ec7a5d18d (patch)
treeee1c767e716d4d40d7face6a76ef2f4c0a65dc53
parent18840b0719aa766a1bc49ea2eb5dc2e4cde7da3f (diff)
downloadrust-7cab73928a3641e15a7c8d8e0d8b453ec7a5d18d.tar.gz
rust-7cab73928a3641e15a7c8d8e0d8b453ec7a5d18d.zip
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/github.com-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
```
-rw-r--r--src/bootstrap/channel.rs53
-rw-r--r--src/bootstrap/lib.rs2
2 files changed, 37 insertions, 18 deletions
diff --git a/src/bootstrap/channel.rs b/src/bootstrap/channel.rs
index 6e65be93fec..6478578c3c4 100644
--- a/src/bootstrap/channel.rs
+++ b/src/bootstrap/channel.rs
@@ -12,11 +12,16 @@ use build_helper::output;
 
 use crate::Build;
 
-pub struct GitInfo {
-    inner: Option<Info>,
+pub enum GitInfo {
+    /// This is not a git repository.
+    Absent,
+    /// This is a git repository.
+    /// If the info should be used (`ignore_git` is false), this will be
+    /// `Some`, otherwise it will be `None`.
+    Present(Option<Info>),
 }
 
-struct Info {
+pub struct Info {
     commit_date: String,
     sha: String,
     short_sha: String,
@@ -25,14 +30,20 @@ struct Info {
 impl GitInfo {
     pub fn new(ignore_git: bool, dir: &Path) -> GitInfo {
         // See if this even begins to look like a git dir
-        if ignore_git || !dir.join(".git").exists() {
-            return GitInfo { inner: None };
+        if !dir.join(".git").exists() {
+            return GitInfo::Absent;
         }
 
         // Make sure git commands work
         match Command::new("git").arg("rev-parse").current_dir(dir).output() {
             Ok(ref out) if out.status.success() => {}
-            _ => return GitInfo { inner: None },
+            _ => return GitInfo::Absent,
+        }
+
+        // If we're ignoring the git info, we don't actually need to collect it, just make sure this
+        // was a git repo in the first place.
+        if ignore_git {
+            return GitInfo::Present(None);
         }
 
         // Ok, let's scrape some info
@@ -48,30 +59,35 @@ impl GitInfo {
         let short_ver_hash = output(
             Command::new("git").current_dir(dir).arg("rev-parse").arg("--short=9").arg("HEAD"),
         );
-        GitInfo {
-            inner: Some(Info {
-                commit_date: ver_date.trim().to_string(),
-                sha: ver_hash.trim().to_string(),
-                short_sha: short_ver_hash.trim().to_string(),
-            }),
+        GitInfo::Present(Some(Info {
+            commit_date: ver_date.trim().to_string(),
+            sha: ver_hash.trim().to_string(),
+            short_sha: short_ver_hash.trim().to_string(),
+        }))
+    }
+
+    fn info(&self) -> Option<&Info> {
+        match self {
+            GitInfo::Present(info) => info.as_ref(),
+            GitInfo::Absent => None,
         }
     }
 
     pub fn sha(&self) -> Option<&str> {
-        self.inner.as_ref().map(|s| &s.sha[..])
+        self.info().map(|s| &s.sha[..])
     }
 
     pub fn sha_short(&self) -> Option<&str> {
-        self.inner.as_ref().map(|s| &s.short_sha[..])
+        self.info().map(|s| &s.short_sha[..])
     }
 
     pub fn commit_date(&self) -> Option<&str> {
-        self.inner.as_ref().map(|s| &s.commit_date[..])
+        self.info().map(|s| &s.commit_date[..])
     }
 
     pub fn version(&self, build: &Build, num: &str) -> String {
         let mut version = build.release(num);
-        if let Some(ref inner) = self.inner {
+        if let Some(ref inner) = self.info() {
             version.push_str(" (");
             version.push_str(&inner.short_sha);
             version.push(' ');
@@ -82,6 +98,9 @@ impl GitInfo {
     }
 
     pub fn is_git(&self) -> bool {
-        self.inner.is_some()
+        match self {
+            GitInfo::Absent => false,
+            GitInfo::Present(_) => true,
+        }
     }
 }
diff --git a/src/bootstrap/lib.rs b/src/bootstrap/lib.rs
index 245f3eada2a..3d56650f775 100644
--- a/src/bootstrap/lib.rs
+++ b/src/bootstrap/lib.rs
@@ -1145,7 +1145,7 @@ impl Build {
         match &self.config.channel[..] {
             "stable" => num.to_string(),
             "beta" => {
-                if self.rust_info.is_git() {
+                if self.rust_info.is_git() && !self.config.ignore_git {
                     format!("{}-beta.{}", num, self.beta_prerelease_version())
                 } else {
                     format!("{}-beta", num)