Skip to content

Commit 3ebafec

Browse files
author
David Ungar
authored
Merge pull request #404 from davidungar/driver-use-frontend-path
[Incremental] Another attempt to get the driver to honor -driver-use-frontend-path
2 parents 3c5c2d0 + 5d42385 commit 3ebafec

File tree

4 files changed

+27
-14
lines changed

4 files changed

+27
-14
lines changed

Sources/SwiftDriver/Driver/Driver.swift

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2062,23 +2062,24 @@ extension Driver {
20622062

20632063
// Find the Swift compiler executable.
20642064
let swiftCompilerPrefixArgs: [String]
2065+
let hasFrontendBeenRedirectedForTesting: Bool
20652066
if let frontendPath = parsedOptions.getLastArgument(.driverUseFrontendPath){
20662067
var frontendCommandLine =
20672068
frontendPath.asSingle.split(separator: ";").map { String($0) }
20682069
if frontendCommandLine.isEmpty {
20692070
diagnosticsEngine.emit(.error_no_swift_frontend)
20702071
swiftCompilerPrefixArgs = []
2072+
hasFrontendBeenRedirectedForTesting = false
20712073
} else {
2072-
let frontendPath = frontendCommandLine.removeFirst()
2073-
toolchain.overrideToolPath(
2074-
.swiftCompiler, path: try AbsolutePath(validating: frontendPath))
2074+
let frontendPathString = frontendCommandLine.removeFirst()
2075+
let frontendPath = try AbsolutePath(validating: frontendPathString)
2076+
toolchain.overrideToolPath(.swiftCompiler, path: frontendPath)
20752077
swiftCompilerPrefixArgs = frontendCommandLine
2078+
hasFrontendBeenRedirectedForTesting = FileType.isFrontendExtensionForTesting(frontendPath.extension)
20762079
}
20772080
} else {
20782081
swiftCompilerPrefixArgs = []
2079-
}
2080-
var hasFrontendBeenRedirectedForTesting: Bool {
2081-
return !swiftCompilerPrefixArgs.isEmpty
2082+
hasFrontendBeenRedirectedForTesting = false
20822083
}
20832084

20842085
// Find the SDK, if any.

Sources/SwiftDriver/Jobs/CompileJob.swift

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,8 @@ extension Driver {
7979
case .swift, .image, .dSYM, .dependencies, .autolink, .swiftDocumentation, .swiftInterface,
8080
.privateSwiftInterface, .swiftSourceInfoFile, .diagnostics, .objcHeader, .swiftDeps,
8181
.remap, .tbd, .moduleTrace, .yamlOptimizationRecord, .bitstreamOptimizationRecord, .pcm,
82-
.pch, .clangModuleMap, .jsonTargetInfo, .jsonSwiftArtifacts, .jsonClangDependencies, nil:
82+
.pch, .clangModuleMap, .jsonTargetInfo, .jsonSwiftArtifacts, .jsonClangDependencies,
83+
.python, nil:
8384
return false
8485
}
8586
}
@@ -357,7 +358,8 @@ extension FileType {
357358
case .swift, .dSYM, .autolink, .dependencies, .swiftDocumentation, .pcm,
358359
.diagnostics, .objcHeader, .image, .swiftDeps, .moduleTrace, .tbd,
359360
.yamlOptimizationRecord, .bitstreamOptimizationRecord, .swiftInterface,
360-
.privateSwiftInterface, .swiftSourceInfoFile, .clangModuleMap, .jsonSwiftArtifacts:
361+
.privateSwiftInterface, .swiftSourceInfoFile, .clangModuleMap, .jsonSwiftArtifacts,
362+
.python:
361363
fatalError("Output type can never be a primary output")
362364
}
363365
}

Sources/SwiftDriver/Utilities/FileType.swift

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -130,14 +130,17 @@ public enum FileType: String, Hashable, CaseIterable, Codable {
130130

131131
/// Clang Module Map
132132
case clangModuleMap = "modulemap"
133+
134+
/// Python script (used for tests)
135+
case python = "py"
133136
}
134137

135138
extension FileType: CustomStringConvertible {
136139
public var description: String {
137140
switch self {
138141
case .swift, .sil, .sib, .image, .dSYM, .dependencies, .autolink,
139142
.swiftModule, .swiftDocumentation, .swiftInterface, .swiftSourceInfoFile, .assembly,
140-
.remap, .tbd, .pcm, .pch, .clangModuleMap:
143+
.remap, .tbd, .pcm, .pch, .clangModuleMap, .python:
141144
return rawValue
142145
case .object:
143146
return "object"
@@ -211,7 +214,8 @@ extension FileType {
211214
.swiftDocumentation, .pcm, .diagnostics, .objcHeader, .image,
212215
.swiftDeps, .moduleTrace, .tbd, .yamlOptimizationRecord, .bitstreamOptimizationRecord,
213216
.swiftInterface, .privateSwiftInterface, .swiftSourceInfoFile, .jsonDependencies,
214-
.clangModuleMap, .jsonTargetInfo, .jsonSwiftArtifacts, .jsonClangDependencies:
217+
.clangModuleMap, .jsonTargetInfo, .jsonSwiftArtifacts, .jsonClangDependencies,
218+
.python:
215219
return false
216220
}
217221
}
@@ -302,6 +306,8 @@ extension FileType {
302306
return "bitstream-opt-record"
303307
case .diagnostics:
304308
return "diagnostics"
309+
case .python:
310+
return "python"
305311
}
306312
}
307313
}
@@ -313,7 +319,7 @@ extension FileType {
313319
.objcHeader, .autolink, .importedModules, .tbd, .moduleTrace,
314320
.yamlOptimizationRecord, .swiftInterface, .privateSwiftInterface,
315321
.jsonDependencies, .clangModuleMap, .jsonTargetInfo, .jsonSwiftArtifacts,
316-
.jsonClangDependencies:
322+
.jsonClangDependencies, .python:
317323
return true
318324
case .image, .object, .dSYM, .pch, .sib, .raw_sib, .swiftModule,
319325
.swiftDocumentation, .swiftSourceInfoFile, .llvmBitcode, .diagnostics,
@@ -333,8 +339,13 @@ extension FileType {
333339
.swiftSourceInfoFile, .raw_sil, .raw_sib, .diagnostics, .objcHeader, .swiftDeps, .remap,
334340
.importedModules, .tbd, .moduleTrace, .indexData, .yamlOptimizationRecord,
335341
.bitstreamOptimizationRecord, .pcm, .pch, .jsonDependencies, .clangModuleMap,
336-
.jsonTargetInfo, .jsonSwiftArtifacts, .jsonClangDependencies:
342+
.jsonTargetInfo, .jsonSwiftArtifacts, .jsonClangDependencies, .python:
337343
return false
338344
}
339345
}
346+
347+
static func isFrontendExtensionForTesting(_ extension: String?) -> Bool {
348+
python.rawValue == `extension`
349+
}
350+
340351
}

Tests/SwiftDriverTests/SwiftDriverTests.swift

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1472,7 +1472,6 @@ final class SwiftDriverTests: XCTestCase {
14721472
}
14731473

14741474
func testBatchModeContinueAfterErrors() throws {
1475-
throw XCTSkip("This test requires the fix to honoring -driver-use-frontend-path")
14761475
struct MockExecutor: DriverExecutor {
14771476
let resolver = try! ArgsResolver(fileSystem: localFileSystem)
14781477

@@ -1496,7 +1495,7 @@ final class SwiftDriverTests: XCTestCase {
14961495
}
14971496
}
14981497

1499-
let driver = try Driver(args: ["swiftc", "foo1.swift", "bar1.swift", "-enable-batch-mode", "-driver-use-frontend-path", "/bin/echo"], executor: MockExecutor())
1498+
let driver = try Driver(args: ["swiftc", "foo1.swift", "bar1.swift", "-enable-batch-mode", "-driver-use-frontend-path", "/dummy.py"], executor: MockExecutor())
15001499
}
15011500

15021501
func testSingleThreadedWholeModuleOptimizationCompiles() throws {

0 commit comments

Comments
 (0)