Skip to content

Commit b24dc75

Browse files
committed
Respect --src bootstrap flag
Previously it was simply ignored.
1 parent 2139a78 commit b24dc75

File tree

1 file changed

+49
-45
lines changed

1 file changed

+49
-45
lines changed

Diff for: src/bootstrap/src/core/config/config.rs

+49-45
Original file line numberDiff line numberDiff line change
@@ -1425,52 +1425,56 @@ impl Config {
14251425

14261426
// Infer the rest of the configuration.
14271427

1428-
// Infer the source directory. This is non-trivial because we want to support a downloaded bootstrap binary,
1429-
// running on a completely different machine from where it was compiled.
1430-
let mut cmd = helpers::git(None);
1431-
// NOTE: we cannot support running from outside the repository because the only other path we have available
1432-
// is set at compile time, which can be wrong if bootstrap was downloaded rather than compiled locally.
1433-
// We still support running outside the repository if we find we aren't in a git directory.
1434-
1435-
// NOTE: We get a relative path from git to work around an issue on MSYS/mingw. If we used an absolute path,
1436-
// and end up using MSYS's git rather than git-for-windows, we would get a unix-y MSYS path. But as bootstrap
1437-
// has already been (kinda-cross-)compiled to Windows land, we require a normal Windows path.
1438-
cmd.arg("rev-parse").arg("--show-cdup");
1439-
// Discard stderr because we expect this to fail when building from a tarball.
1440-
let output = cmd
1441-
.as_command_mut()
1442-
.stderr(std::process::Stdio::null())
1443-
.output()
1444-
.ok()
1445-
.and_then(|output| if output.status.success() { Some(output) } else { None });
1446-
if let Some(output) = output {
1447-
let git_root_relative = String::from_utf8(output.stdout).unwrap();
1448-
// We need to canonicalize this path to make sure it uses backslashes instead of forward slashes,
1449-
// and to resolve any relative components.
1450-
let git_root = env::current_dir()
1451-
.unwrap()
1452-
.join(PathBuf::from(git_root_relative.trim()))
1453-
.canonicalize()
1454-
.unwrap();
1455-
let s = git_root.to_str().unwrap();
1456-
1457-
// Bootstrap is quite bad at handling /? in front of paths
1458-
let git_root = match s.strip_prefix("\\\\?\\") {
1459-
Some(p) => PathBuf::from(p),
1460-
None => git_root,
1461-
};
1462-
// If this doesn't have at least `stage0`, we guessed wrong. This can happen when,
1463-
// for example, the build directory is inside of another unrelated git directory.
1464-
// In that case keep the original `CARGO_MANIFEST_DIR` handling.
1465-
//
1466-
// NOTE: this implies that downloadable bootstrap isn't supported when the build directory is outside
1467-
// the source directory. We could fix that by setting a variable from all three of python, ./x, and x.ps1.
1468-
if git_root.join("src").join("stage0").exists() {
1469-
config.src = git_root;
1470-
}
1428+
if let Some(src) = flags.src {
1429+
config.src = src
14711430
} else {
1472-
// We're building from a tarball, not git sources.
1473-
// We don't support pre-downloaded bootstrap in this case.
1431+
// Infer the source directory. This is non-trivial because we want to support a downloaded bootstrap binary,
1432+
// running on a completely different machine from where it was compiled.
1433+
let mut cmd = helpers::git(None);
1434+
// NOTE: we cannot support running from outside the repository because the only other path we have available
1435+
// is set at compile time, which can be wrong if bootstrap was downloaded rather than compiled locally.
1436+
// We still support running outside the repository if we find we aren't in a git directory.
1437+
1438+
// NOTE: We get a relative path from git to work around an issue on MSYS/mingw. If we used an absolute path,
1439+
// and end up using MSYS's git rather than git-for-windows, we would get a unix-y MSYS path. But as bootstrap
1440+
// has already been (kinda-cross-)compiled to Windows land, we require a normal Windows path.
1441+
cmd.arg("rev-parse").arg("--show-cdup");
1442+
// Discard stderr because we expect this to fail when building from a tarball.
1443+
let output = cmd
1444+
.as_command_mut()
1445+
.stderr(std::process::Stdio::null())
1446+
.output()
1447+
.ok()
1448+
.and_then(|output| if output.status.success() { Some(output) } else { None });
1449+
if let Some(output) = output {
1450+
let git_root_relative = String::from_utf8(output.stdout).unwrap();
1451+
// We need to canonicalize this path to make sure it uses backslashes instead of forward slashes,
1452+
// and to resolve any relative components.
1453+
let git_root = env::current_dir()
1454+
.unwrap()
1455+
.join(PathBuf::from(git_root_relative.trim()))
1456+
.canonicalize()
1457+
.unwrap();
1458+
let s = git_root.to_str().unwrap();
1459+
1460+
// Bootstrap is quite bad at handling /? in front of paths
1461+
let git_root = match s.strip_prefix("\\\\?\\") {
1462+
Some(p) => PathBuf::from(p),
1463+
None => git_root,
1464+
};
1465+
// If this doesn't have at least `stage0`, we guessed wrong. This can happen when,
1466+
// for example, the build directory is inside of another unrelated git directory.
1467+
// In that case keep the original `CARGO_MANIFEST_DIR` handling.
1468+
//
1469+
// NOTE: this implies that downloadable bootstrap isn't supported when the build directory is outside
1470+
// the source directory. We could fix that by setting a variable from all three of python, ./x, and x.ps1.
1471+
if git_root.join("src").join("stage0").exists() {
1472+
config.src = git_root;
1473+
}
1474+
} else {
1475+
// We're building from a tarball, not git sources.
1476+
// We don't support pre-downloaded bootstrap in this case.
1477+
}
14741478
}
14751479

14761480
if cfg!(test) {

0 commit comments

Comments
 (0)