Skip to content

Commit 52250a8

Browse files
[SwiftPreview] Fix SwiftUI preview when using caching and response file
Fix a bug that swift preview can fail when using compilation caching and command-line is too long (so response file is used). rdar://162547707
1 parent 015858b commit 52250a8

File tree

1 file changed

+7
-3
lines changed

1 file changed

+7
-3
lines changed

Sources/SWBCore/SpecImplementations/Tools/SwiftCompiler.swift

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3585,14 +3585,18 @@ public final class SwiftCompilerSpec : CompilerSpec, SpecIdentifierType, SwiftDi
35853585
) {
35863586
commandLine = newCommandLine
35873587
// For swift caching jobs, add extra flags.
3588-
if commandLine.contains("-cache-compile-job") {
3588+
if driverPayload.casOptions != nil {
35893589
// Ideally, we should ask if swift-frontend supports the flag but we can only ask driver for an approximation.
35903590
if LibSwiftDriver.supportsDriverFlag(spelled: "-module-import-from-cas") {
35913591
commandLine.append("-module-import-from-cas")
35923592
}
35933593
// Then drop the cache build flag to do uncached preview compilation.
3594-
commandLine.removeAll {
3595-
$0 == "-cache-compile-job"
3594+
if LibSwiftDriver.supportsDriverFlag(spelled: "-no-cache-compile-job") {
3595+
commandLine.append("-no-cache-compile-job")
3596+
} else {
3597+
commandLine.removeAll {
3598+
$0 == "-cache-compile-job"
3599+
}
35963600
}
35973601
}
35983602
// Add vfsoverlay after the driver invocation as it can affect the module dependencies, causing modules from regular builds not being reused here.

0 commit comments

Comments
 (0)