@@ -1385,64 +1385,95 @@ fn file_override() {
1385
1385
}
1386
1386
1387
1387
#[ test]
1388
- #[ cfg_attr(
1389
- not( unix) ,
1390
- ignore = "TODO: Figure out how to write a wrapper toolchain on Windows"
1391
- ) ]
1392
1388
fn file_override_path ( ) {
1393
1389
setup ( & |config| {
1394
- let cwd = config. current_dir ( ) ;
1395
- let toolchain_path = cwd. join ( "ephemeral" ) ;
1396
- let toolchain_bin = toolchain_path. join ( "bin" ) ;
1397
- fs:: create_dir_all ( & toolchain_bin) . unwrap ( ) ;
1398
-
1399
- // Inject a wrapper binary for rustc.
1400
- let rustc = toolchain_bin. join ( "rustc" ) ;
1401
- #[ cfg( unix) ]
1402
- {
1403
- use std:: os:: unix:: fs:: PermissionsExt ;
1404
- raw:: write_file ( & rustc, "#!/bin/sh\n echo custom-toolchain" ) . unwrap ( ) ;
1405
- fs:: set_permissions ( rustc, fs:: Permissions :: from_mode ( 0o755 ) ) . unwrap ( ) ;
1406
- }
1390
+ expect_ok ( config, & [ "rustup" , "default" , "stable" ] ) ;
1391
+ expect_ok (
1392
+ config,
1393
+ & [
1394
+ "rustup" ,
1395
+ "toolchain" ,
1396
+ "install" ,
1397
+ "nightly" ,
1398
+ "--no-self-update" ,
1399
+ ] ,
1400
+ ) ;
1407
1401
1408
- let toolchain_file = cwd. join ( "rust-toolchain.toml" ) ;
1402
+ let toolchain_path = config
1403
+ . rustupdir
1404
+ . join ( "toolchains" )
1405
+ . join ( format ! ( "nightly-{}" , this_host_triple( ) ) ) ;
1406
+ let toolchain_file = config. current_dir ( ) . join ( "rust-toolchain.toml" ) ;
1409
1407
raw:: write_file (
1410
1408
& toolchain_file,
1411
1409
& format ! ( "[toolchain]\n path=\" {}\" " , toolchain_path. display( ) ) ,
1412
1410
)
1413
1411
. unwrap ( ) ;
1414
1412
1415
- expect_stdout_ok ( config, & [ "rustc" , "--version" ] , "custom-toolchain " ) ;
1413
+ expect_stdout_ok ( config, & [ "rustc" , "--version" ] , "hash-nightly-2 " ) ;
1416
1414
} ) ;
1417
1415
}
1418
1416
1419
1417
#[ test]
1420
- #[ cfg_attr(
1421
- not( unix) ,
1422
- ignore = "TODO: Figure out how to write a wrapper toolchain on Windows"
1423
- ) ]
1424
1418
fn file_override_path_relative ( ) {
1425
1419
setup ( & |config| {
1426
- let cwd = config. current_dir ( ) ;
1427
- let toolchain_path = cwd. join ( "ephemeral" ) ;
1428
- let toolchain_bin = toolchain_path. join ( "bin" ) ;
1429
- fs:: create_dir_all ( & toolchain_bin) . unwrap ( ) ;
1420
+ expect_ok ( config, & [ "rustup" , "default" , "stable" ] ) ;
1421
+ expect_ok (
1422
+ config,
1423
+ & [
1424
+ "rustup" ,
1425
+ "toolchain" ,
1426
+ "install" ,
1427
+ "nightly" ,
1428
+ "--no-self-update" ,
1429
+ ] ,
1430
+ ) ;
1430
1431
1431
- // Inject a wrapper binary for rustc.
1432
- let rustc = toolchain_bin. join ( "rustc" ) ;
1433
- #[ cfg( unix) ]
1434
- {
1435
- use std:: os:: unix:: fs:: PermissionsExt ;
1436
- raw:: write_file ( & rustc, "#!/bin/sh\n echo custom-toolchain" ) . unwrap ( ) ;
1437
- fs:: set_permissions ( rustc, fs:: Permissions :: from_mode ( 0o755 ) ) . unwrap ( ) ;
1432
+ let toolchain_path = config
1433
+ . rustupdir
1434
+ . join ( "toolchains" )
1435
+ . join ( format ! ( "nightly-{}" , this_host_triple( ) ) )
1436
+ . canonicalize ( )
1437
+ . unwrap ( ) ;
1438
+ let toolchain_file = config
1439
+ . current_dir ( )
1440
+ . canonicalize ( )
1441
+ . unwrap ( )
1442
+ . join ( "rust-toolchain.toml" ) ;
1443
+
1444
+ // Find shared prefix so we can determine a relative path
1445
+ let mut p1 = dbg ! ( & toolchain_path) . components ( ) . peekable ( ) ;
1446
+ let mut p2 = dbg ! ( & toolchain_file) . components ( ) . peekable ( ) ;
1447
+ while let ( Some ( p1p) , Some ( p2p) ) = ( p1. peek ( ) , p2. peek ( ) ) {
1448
+ if p1p == p2p {
1449
+ let _ = p1. next ( ) ;
1450
+ let _ = p2. next ( ) ;
1451
+ } else {
1452
+ // The two paths diverge here
1453
+ break ;
1454
+ }
1438
1455
}
1456
+ let mut relative_path = PathBuf :: new ( ) ;
1457
+ // NOTE: We skip 1 since we don't need to .. across the .toml file at the end of the path
1458
+ for _ in p2. skip ( 1 ) {
1459
+ relative_path. push ( ".." ) ;
1460
+ }
1461
+ for p in p1 {
1462
+ relative_path. push ( p) ;
1463
+ }
1464
+ assert ! ( relative_path. is_relative( ) ) ;
1439
1465
1440
- let toolchain_file = cwd. join ( "rust-toolchain.toml" ) ;
1441
- raw:: write_file ( & toolchain_file, "[toolchain]\n path=\" ephemeral\" " ) . unwrap ( ) ;
1466
+ raw:: write_file (
1467
+ & toolchain_file,
1468
+ & format ! ( "[toolchain]\n path=\" {}\" " , relative_path. display( ) ) ,
1469
+ )
1470
+ . unwrap ( ) ;
1442
1471
1443
- // Change into ephemeral so that we actually test that the path is relative to the override
1444
- config. change_dir ( & toolchain_path, || {
1445
- expect_stdout_ok ( config, & [ "rustc" , "--version" ] , "custom-toolchain" )
1472
+ // Change into an ephemeral dir so that we test that the path is relative to the override
1473
+ let ephemeral = config. current_dir ( ) . join ( "ephemeral" ) ;
1474
+ fs:: create_dir_all ( & ephemeral) . unwrap ( ) ;
1475
+ config. change_dir ( & ephemeral, || {
1476
+ expect_stdout_ok ( config, & [ "rustc" , "--version" ] , "hash-nightly-2" ) ;
1446
1477
} ) ;
1447
1478
} ) ;
1448
1479
}
0 commit comments