@@ -6627,6 +6627,61 @@ final class SwiftDriverTests: XCTestCase {
6627
6627
#endif
6628
6628
#endif
6629
6629
}
6630
+
6631
+ func testToolSearching( ) throws {
6632
+ #if os(Windows)
6633
+ let PATH = " Path "
6634
+ #else
6635
+ let PATH = " PATH "
6636
+ #endif
6637
+ let SWIFT_FRONTEND_EXEC = " SWIFT_DRIVER_SWIFT_FRONTEND_EXEC "
6638
+
6639
+ // Reset the environment to ensure tool resolution is exactly run against PATH.
6640
+ var driver = try Driver ( args: [ " swiftc " , " -print-target-info " ] , env: [ PATH: ProcessEnv . path!] )
6641
+ let jobs = try driver. planBuild ( )
6642
+ XCTAssertEqual ( jobs. count, 1 )
6643
+ let defaultSwiftFrontend = jobs. first!. tool. absolutePath!
6644
+ let originalWorkingDirectory = localFileSystem. currentWorkingDirectory!
6645
+
6646
+ try withTemporaryDirectory { toolsDirectory in
6647
+ let customSwiftFrontend = toolsDirectory. appending ( component: executableName ( " swift-frontend " ) )
6648
+ try localFileSystem. createSymbolicLink ( customSwiftFrontend, pointingAt: defaultSwiftFrontend, relative: false )
6649
+
6650
+ try withTemporaryDirectory { tempDirectory in
6651
+ try localFileSystem. changeCurrentWorkingDirectory ( to: tempDirectory)
6652
+ defer { try ! localFileSystem. changeCurrentWorkingDirectory ( to: originalWorkingDirectory) }
6653
+
6654
+ let anotherSwiftFrontend = localFileSystem. currentWorkingDirectory!. appending ( component: executableName ( " swift-frontend " ) )
6655
+ try localFileSystem. createSymbolicLink ( anotherSwiftFrontend, pointingAt: defaultSwiftFrontend, relative: false )
6656
+
6657
+ // test if SWIFT_DRIVER_TOOLNAME_EXEC is respected
6658
+ do {
6659
+ var driver = try Driver ( args: [ " swiftc " , " -print-target-info " ] ,
6660
+ env: [ PATH: ProcessEnv . path!, SWIFT_FRONTEND_EXEC: customSwiftFrontend. pathString] )
6661
+ let jobs = try driver. planBuild ( )
6662
+ XCTAssertEqual ( jobs. count, 1 )
6663
+ XCTAssertEqual ( jobs. first!. tool. name, customSwiftFrontend. pathString)
6664
+ }
6665
+
6666
+ // test if tools directory is respected
6667
+ do {
6668
+ var driver = try Driver ( args: [ " swiftc " , " -print-target-info " , " -tools-directory " , toolsDirectory. pathString] ,
6669
+ env: [ PATH: ProcessEnv . path!] )
6670
+ let jobs = try driver. planBuild ( )
6671
+ XCTAssertEqual ( jobs. count, 1 )
6672
+ XCTAssertEqual ( jobs. first!. tool. name, customSwiftFrontend. pathString)
6673
+ }
6674
+
6675
+ // test if current working directory is searched before PATH
6676
+ do {
6677
+ var driver = try Driver ( args: [ " swiftc " , " -print-target-info " ] , env: [ PATH: toolsDirectory. pathString] )
6678
+ let jobs = try driver. planBuild ( )
6679
+ XCTAssertEqual ( jobs. count, 1 )
6680
+ XCTAssertEqual ( jobs. first!. tool. name, anotherSwiftFrontend. pathString)
6681
+ }
6682
+ }
6683
+ }
6684
+ }
6630
6685
}
6631
6686
6632
6687
func assertString(
0 commit comments