@@ -6609,6 +6609,58 @@ final class SwiftDriverTests: XCTestCase {
66096609#endif
66106610#endif
66116611 }
6612+
6613+ func testToolSearching( ) throws {
6614+ #if os(Windows)
6615+ let PATH = " Path "
6616+ #else
6617+ let PATH = " PATH "
6618+ #endif
6619+ let SWIFT_FRONTEND_EXEC = " SWIFT_DRIVER_SWIFT_FRONTEND_EXEC "
6620+
6621+ // We need to override SWIFT_DRIVER_SWIFT_FRONTEND_EXEC to prevent it from interfering the tests.
6622+ var driver = try Driver ( args: [ " swiftc " , " -print-target-info " ] , env: [ PATH: ProcessEnv . path!] )
6623+ let jobs = try driver. planBuild ( )
6624+ XCTAssertEqual ( jobs. count, 1 )
6625+ let defaultSwiftFrontend = jobs. first!. tool. absolutePath!
6626+
6627+ try withTemporaryDirectory { toolsDirectory in
6628+ let customSwiftFrontend = toolsDirectory. appending ( component: executableName ( " swift-frontend " ) )
6629+ try localFileSystem. createSymbolicLink ( customSwiftFrontend, pointingAt: defaultSwiftFrontend, relative: false )
6630+
6631+ try withTemporaryDirectory { tempDirectory in
6632+ try localFileSystem. changeCurrentWorkingDirectory ( to: tempDirectory)
6633+ let anotherSwiftFrontend = localFileSystem. currentWorkingDirectory!. appending ( component: executableName ( " swift-frontend " ) )
6634+ try localFileSystem. createSymbolicLink ( anotherSwiftFrontend, pointingAt: defaultSwiftFrontend, relative: false )
6635+
6636+ // test if SWIFT_DRIVER_TOOLNAME_EXEC is respected
6637+ do {
6638+ var driver = try Driver ( args: [ " swiftc " , " -print-target-info " ] ,
6639+ env: [ PATH: ProcessEnv . path!, SWIFT_FRONTEND_EXEC: customSwiftFrontend. pathString] )
6640+ let jobs = try driver. planBuild ( )
6641+ XCTAssertEqual ( jobs. count, 1 )
6642+ XCTAssertEqual ( jobs. first!. tool. name, customSwiftFrontend. pathString)
6643+ }
6644+
6645+ // test if tools directory is respected
6646+ do {
6647+ var driver = try Driver ( args: [ " swiftc " , " -print-target-info " , " -tools-directory " , toolsDirectory. pathString] ,
6648+ env: [ PATH: ProcessEnv . path!] )
6649+ let jobs = try driver. planBuild ( )
6650+ XCTAssertEqual ( jobs. count, 1 )
6651+ XCTAssertEqual ( jobs. first!. tool. name, customSwiftFrontend. pathString)
6652+ }
6653+
6654+ // test if current working directory is searched before PATH
6655+ do {
6656+ var driver = try Driver ( args: [ " swiftc " , " -print-target-info " ] , env: [ PATH: toolsDirectory. pathString] )
6657+ let jobs = try driver. planBuild ( )
6658+ XCTAssertEqual ( jobs. count, 1 )
6659+ XCTAssertEqual ( jobs. first!. tool. name, anotherSwiftFrontend. pathString)
6660+ }
6661+ }
6662+ }
6663+ }
66126664}
66136665
66146666func assertString(
0 commit comments