@@ -1227,37 +1227,46 @@ impl Config {
1227
1227
// Infer the rest of the configuration.
1228
1228
1229
1229
// Infer the source directory. This is non-trivial because we want to support a downloaded bootstrap binary,
1230
- // running on a completely machine from where it was compiled.
1230
+ // running on a completely different machine from where it was compiled.
1231
1231
let mut cmd = Command :: new ( "git" ) ;
1232
- // NOTE: we cannot support running from outside the repository because the only path we have available
1233
- // is set at compile time, which can be wrong if bootstrap was downloaded from source .
1232
+ // NOTE: we cannot support running from outside the repository because the only other path we have available
1233
+ // is set at compile time, which can be wrong if bootstrap was downloaded rather than compiled locally .
1234
1234
// We still support running outside the repository if we find we aren't in a git directory.
1235
- cmd. arg ( "rev-parse" ) . arg ( "--show-toplevel" ) ;
1235
+
1236
+ // NOTE: We get a relative path from git to work around an issue on MSYS/mingw. If we used an absolute path,
1237
+ // and end up using MSYS's git rather than git-for-windows, we would get a unix-y MSYS path. But as bootstrap
1238
+ // has already been (kinda-cross-)compiled to Windows land, we require a normal Windows path.
1239
+ cmd. arg ( "rev-parse" ) . arg ( "--show-cdup" ) ;
1236
1240
// Discard stderr because we expect this to fail when building from a tarball.
1237
1241
let output = cmd
1238
1242
. stderr ( std:: process:: Stdio :: null ( ) )
1239
1243
. output ( )
1240
1244
. ok ( )
1241
1245
. and_then ( |output| if output. status . success ( ) { Some ( output) } else { None } ) ;
1242
1246
if let Some ( output) = output {
1243
- let git_root = String :: from_utf8 ( output. stdout ) . unwrap ( ) ;
1244
- // We need to canonicalize this path to make sure it uses backslashes instead of forward slashes.
1245
- let git_root = PathBuf :: from ( git_root. trim ( ) ) . canonicalize ( ) . unwrap ( ) ;
1247
+ let git_root_relative = String :: from_utf8 ( output. stdout ) . unwrap ( ) ;
1248
+ // We need to canonicalize this path to make sure it uses backslashes instead of forward slashes,
1249
+ // and to resolve any relative components.
1250
+ let git_root = env:: current_dir ( )
1251
+ . unwrap ( )
1252
+ . join ( PathBuf :: from ( git_root_relative. trim ( ) ) )
1253
+ . canonicalize ( )
1254
+ . unwrap ( ) ;
1246
1255
let s = git_root. to_str ( ) . unwrap ( ) ;
1247
1256
1248
1257
// Bootstrap is quite bad at handling /? in front of paths
1249
- let src = match s. strip_prefix ( "\\ \\ ?\\ " ) {
1258
+ let git_root = match s. strip_prefix ( "\\ \\ ?\\ " ) {
1250
1259
Some ( p) => PathBuf :: from ( p) ,
1251
- None => PathBuf :: from ( git_root) ,
1260
+ None => git_root,
1252
1261
} ;
1253
1262
// If this doesn't have at least `stage0.json`, we guessed wrong. This can happen when,
1254
1263
// for example, the build directory is inside of another unrelated git directory.
1255
1264
// In that case keep the original `CARGO_MANIFEST_DIR` handling.
1256
1265
//
1257
1266
// NOTE: this implies that downloadable bootstrap isn't supported when the build directory is outside
1258
1267
// the source directory. We could fix that by setting a variable from all three of python, ./x, and x.ps1.
1259
- if src . join ( "src" ) . join ( "stage0.json" ) . exists ( ) {
1260
- config. src = src ;
1268
+ if git_root . join ( "src" ) . join ( "stage0.json" ) . exists ( ) {
1269
+ config. src = git_root ;
1261
1270
}
1262
1271
} else {
1263
1272
// We're building from a tarball, not git sources.
0 commit comments