@@ -6395,6 +6395,58 @@ final class SwiftDriverTests: XCTestCase {
63956395#endif
63966396#endif
63976397 }
6398+
6399+ func testToolSearching( ) throws {
6400+ #if os(Windows)
6401+ let PATH = " Path "
6402+ #else
6403+ let PATH = " PATH "
6404+ #endif
6405+ let SWIFT_FRONTEND_EXEC = " SWIFT_DRIVER_SWIFT_FRONTEND_EXEC "
6406+
6407+ // We need to override SWIFT_DRIVER_SWIFT_FRONTEND_EXEC to prevent it from interfering the tests.
6408+ var driver = try Driver ( args: [ " swiftc " , " -print-target-info " ] , env: [ PATH: ProcessEnv . path!] )
6409+ let jobs = try driver. planBuild ( )
6410+ XCTAssertEqual ( jobs. count, 1 )
6411+ let defaultSwiftFrontend = jobs. first!. tool. absolutePath!
6412+
6413+ try withTemporaryDirectory { toolsDirectory in
6414+ let customSwiftFrontend = toolsDirectory. appending ( component: executableName ( " swift-frontend " ) )
6415+ try localFileSystem. createSymbolicLink ( customSwiftFrontend, pointingAt: defaultSwiftFrontend, relative: false )
6416+
6417+ try withTemporaryDirectory { tempDirectory in
6418+ try localFileSystem. changeCurrentWorkingDirectory ( to: tempDirectory)
6419+ let anotherSwiftFrontend = localFileSystem. currentWorkingDirectory!. appending ( component: executableName ( " swift-frontend " ) )
6420+ try localFileSystem. createSymbolicLink ( anotherSwiftFrontend, pointingAt: defaultSwiftFrontend, relative: false )
6421+
6422+ // test if SWIFT_DRIVER_TOOLNAME_EXEC is respected
6423+ do {
6424+ var driver = try Driver ( args: [ " swiftc " , " -print-target-info " ] ,
6425+ env: [ PATH: ProcessEnv . path!, SWIFT_FRONTEND_EXEC: customSwiftFrontend. pathString] )
6426+ let jobs = try driver. planBuild ( )
6427+ XCTAssertEqual ( jobs. count, 1 )
6428+ XCTAssertEqual ( jobs. first!. tool. name, customSwiftFrontend. pathString)
6429+ }
6430+
6431+ // test if tools directory is respected
6432+ do {
6433+ var driver = try Driver ( args: [ " swiftc " , " -print-target-info " , " -tools-directory " , toolsDirectory. pathString] ,
6434+ env: [ PATH: ProcessEnv . path!] )
6435+ let jobs = try driver. planBuild ( )
6436+ XCTAssertEqual ( jobs. count, 1 )
6437+ XCTAssertEqual ( jobs. first!. tool. name, customSwiftFrontend. pathString)
6438+ }
6439+
6440+ // test if current working directory is searched before PATH
6441+ do {
6442+ var driver = try Driver ( args: [ " swiftc " , " -print-target-info " ] , env: [ PATH: toolsDirectory. pathString] )
6443+ let jobs = try driver. planBuild ( )
6444+ XCTAssertEqual ( jobs. count, 1 )
6445+ XCTAssertEqual ( jobs. first!. tool. name, anotherSwiftFrontend. pathString)
6446+ }
6447+ }
6448+ }
6449+ }
63986450}
63996451
64006452func assertString(
0 commit comments