about summary refs log tree commit diff
path: root/src/bootstrap/config.rs
diff options
context:
space:
mode:
authorJoshua Nelson <jnelson@cloudflare.com>2022-10-02 08:33:54 -0500
committerJoshua Nelson <jnelson@cloudflare.com>2022-10-02 08:33:54 -0500
commit67220d69702b4428a811d063fce3045da7a4040d (patch)
tree9c57ff9fd38b6dc8b2ff73c5027d00f2cf30bf90 /src/bootstrap/config.rs
parent756e7be5eb923ec955dfd8dec2a0d3ac81cfdf55 (diff)
downloadrust-67220d69702b4428a811d063fce3045da7a4040d.tar.gz
rust-67220d69702b4428a811d063fce3045da7a4040d.zip
Make the `config.src` handling for downloadable bootstrap a little more conservative
In particular, this supports build directories within an unrelated git repository.

As a side effect, it will fall back to the old logic when the source directory is being built from a tarball within an unrelated git repository.
However, that second case is unsupported and untested; we reserve the right to break it in the future.
Diffstat (limited to 'src/bootstrap/config.rs')
-rw-r--r--src/bootstrap/config.rs11
1 files changed, 10 insertions, 1 deletions
diff --git a/src/bootstrap/config.rs b/src/bootstrap/config.rs
index f29b5170ea5..1a913412522 100644
--- a/src/bootstrap/config.rs
+++ b/src/bootstrap/config.rs
@@ -829,10 +829,19 @@ impl Config {
             let s = git_root.to_str().unwrap();
 
             // Bootstrap is quite bad at handling /? in front of paths
-            config.src = match s.strip_prefix("\\\\?\\") {
+            let src = match s.strip_prefix("\\\\?\\") {
                 Some(p) => PathBuf::from(p),
                 None => PathBuf::from(git_root),
             };
+            // If this doesn't have at least `stage0.json`, we guessed wrong. This can happen when,
+            // for example, the build directory is inside of another unrelated git directory.
+            // In that case keep the original `CARGO_MANIFEST_DIR` handling.
+            //
+            // NOTE: this implies that downloadable bootstrap isn't supported when the build directory is outside
+            // the source directory. We could fix that by setting a variable from all three of python, ./x, and x.ps1.
+            if src.join("src").join("stage0.json").exists() {
+                config.src = src;
+            }
         } else {
             // We're building from a tarball, not git sources.
             // We don't support pre-downloaded bootstrap in this case.