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