Skip to content

Commit 622ebc7

Browse files
committed
[Explicit Module Builds] Enable incremental dependency scanning\nWith an opt-out build setting SWIFT_DISABLE_INCREMENTAL_SCAN in case early adoption shows any troubles
1 parent ac358da commit 622ebc7

File tree

5 files changed

+72
-0
lines changed

5 files changed

+72
-0
lines changed

Sources/SWBCore/Settings/BuiltinMacros.swift

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1003,6 +1003,7 @@ public final class BuiltinMacros {
10031003
public static let SWIFT_EMIT_MODULE_INTERFACE = BuiltinMacros.declareBooleanMacro("SWIFT_EMIT_MODULE_INTERFACE")
10041004
public static let SWIFT_ENABLE_BATCH_MODE = BuiltinMacros.declareBooleanMacro("SWIFT_ENABLE_BATCH_MODE")
10051005
public static let SWIFT_ENABLE_INCREMENTAL_COMPILATION = BuiltinMacros.declareBooleanMacro("SWIFT_ENABLE_INCREMENTAL_COMPILATION")
1006+
public static let SWIFT_DISABLE_INCREMENTAL_SCAN = BuiltinMacros.declareBooleanMacro("SWIFT_DISABLE_INCREMENTAL_SCAN")
10061007
public static let SWIFT_ENABLE_LAYOUT_STRING_VALUE_WITNESSES = BuiltinMacros.declareBooleanMacro("SWIFT_ENABLE_LAYOUT_STRING_VALUE_WITNESSES")
10071008
public static let SWIFT_ENABLE_LIBRARY_EVOLUTION = BuiltinMacros.declareBooleanMacro("SWIFT_ENABLE_LIBRARY_EVOLUTION")
10081009
public static let SWIFT_ENABLE_BARE_SLASH_REGEX = BuiltinMacros.declareBooleanMacro("SWIFT_ENABLE_BARE_SLASH_REGEX")
@@ -2164,6 +2165,7 @@ public final class BuiltinMacros {
21642165
SWIFT_EMIT_MODULE_INTERFACE,
21652166
SWIFT_ENABLE_BATCH_MODE,
21662167
SWIFT_ENABLE_INCREMENTAL_COMPILATION,
2168+
SWIFT_DISABLE_INCREMENTAL_SCAN,
21672169
SWIFT_ENABLE_LAYOUT_STRING_VALUE_WITNESSES,
21682170
SWIFT_ENABLE_LIBRARY_EVOLUTION,
21692171
SWIFT_USE_INTEGRATED_DRIVER,

Sources/SWBCore/SpecImplementations/Tools/SwiftCompiler.swift

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -119,6 +119,7 @@ public struct SwiftSourceFileIndexingInfo: SourceFileIndexingInfo {
119119
"-emit-dependencies",
120120
"-serialize-diagnostics",
121121
"-incremental",
122+
"-incremental-dependency-scan",
122123
"-parseable-output",
123124
"-use-frontend-parseable-output",
124125
"-whole-module-optimization",
@@ -153,6 +154,7 @@ public struct SwiftSourceFileIndexingInfo: SourceFileIndexingInfo {
153154
// can be removed after we use the new driver instead (rdar://75851402).
154155
private static let newDriverFlags: Set<ByteString> = [
155156
"-driver-print-graphviz",
157+
"-incremental-dependency-scan",
156158
"-explicit-module-build",
157159
"-experimental-explicit-module-build",
158160
"-nonlib-dependency-scanner",
@@ -1743,6 +1745,10 @@ public final class SwiftCompilerSpec : CompilerSpec, SpecIdentifierType, SwiftDi
17431745

17441746
if cbc.scope.evaluate(BuiltinMacros.SWIFT_ENABLE_INCREMENTAL_COMPILATION) {
17451747
args.append("-incremental")
1748+
if LibSwiftDriver.supportsDriverFlag(spelled: "-incremental-dependency-scan"),
1749+
!cbc.scope.evaluate(BuiltinMacros.SWIFT_DISABLE_INCREMENTAL_SCAN) {
1750+
args.append("-incremental-dependency-scan")
1751+
}
17461752
}
17471753
}
17481754

@@ -3279,6 +3285,8 @@ public final class SwiftCompilerSpec : CompilerSpec, SpecIdentifierType, SwiftDi
32793285
for arg in [
32803286
// Should strip this because it saves some work and avoids writing a useless incremental build record
32813287
"-incremental",
3288+
// Same as above
3289+
"-incremental-dependency-scan",
32823290

32833291
// Stripped because we want to end up in single file mode
32843292
"-enable-batch-mode",

Tests/SWBBuildSystemTests/PreviewsBuildOperationTests.swift

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -831,6 +831,7 @@ fileprivate struct PreviewsBuildOperationTests: CoreBasedTests {
831831
"ENABLE_PREVIEWS": "YES",
832832
"CLANG_ENABLE_MODULES": "YES",
833833
"SDK_STAT_CACHE_ENABLE": "NO",
834+
"SWIFT_DISABLE_INCREMENTAL_SCAN": "YES",
834835

835836
"SWIFT_ENABLE_EXPLICIT_MODULES": explicitModules ? "YES" : "NO",
836837

Tests/SWBBuildSystemTests/SwiftDriverTests.swift

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3616,6 +3616,7 @@ fileprivate struct SwiftDriverTests: CoreBasedTests {
36163616
"ENABLE_PREVIEWS": "YES",
36173617
"SWIFT_USE_INTEGRATED_DRIVER": useIntegratedDriver ? "YES" : "NO",
36183618
"SWIFT_ENABLE_EXPLICIT_MODULES": useIntegratedDriver ? "YES" : "NO",
3619+
"SWIFT_DISABLE_INCREMENTAL_SCAN": "YES",
36193620
"_EXPERIMENTAL_SWIFT_EXPLICIT_MODULES": useIntegratedDriver ? "YES" : "NO",
36203621
// Eager linking is not supported when using the driver binary.
36213622
"EAGER_LINKING": "NO",

Tests/SWBTaskConstructionTests/SwiftTaskConstructionTests.swift

Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -645,6 +645,7 @@ fileprivate struct SwiftTaskConstructionTests: CoreBasedTests {
645645
"SWIFT_PACKAGE_NAME": "FooPkg",
646646
"SWIFT_EMIT_MODULE_INTERFACE": "YES",
647647
"SWIFT_ENABLE_EXPLICIT_MODULES": "YES",
648+
"SWIFT_DISABLE_INCREMENTAL_SCAN": "YES",
648649
]),
649650
],
650651
buildPhases: [
@@ -830,6 +831,7 @@ fileprivate struct SwiftTaskConstructionTests: CoreBasedTests {
830831
"DEFINES_MODULE": "YES",
831832
"SWIFT_VERSION": swiftVersion,
832833
"SWIFT_EMIT_MODULE_INTERFACE": "YES",
834+
"SWIFT_DISABLE_INCREMENTAL_SCAN": "YES",
833835
]),
834836
],
835837
buildPhases: [
@@ -1530,6 +1532,64 @@ fileprivate struct SwiftTaskConstructionTests: CoreBasedTests {
15301532
}
15311533
}
15321534

1535+
@Test(.requireSDKs(.macOS), .enabled(if: LibSwiftDriver.supportsDriverFlag(spelled: "-incremental-dependency-scan")))
1536+
func optOutIncrementalScanning() async throws {
1537+
let testProject = try await TestProject(
1538+
"aProject",
1539+
groupTree: TestGroup(
1540+
"SomeFiles", path: "Sources",
1541+
children: [
1542+
TestFile("main.swift"),
1543+
]),
1544+
buildConfigurations: [
1545+
TestBuildConfiguration(
1546+
"Debug",
1547+
buildSettings: [
1548+
"PRODUCT_NAME": "$(TARGET_NAME)",
1549+
"SWIFT_ENABLE_EXPLICIT_MODULES": "YES",
1550+
]),
1551+
],
1552+
targets: [
1553+
TestStandardTarget(
1554+
"Exec", type: .commandLineTool,
1555+
buildConfigurations: [
1556+
TestBuildConfiguration("Debug",
1557+
buildSettings: [
1558+
"SWIFT_EXEC": swiftCompilerPath.str,
1559+
"SWIFT_VERSION": swiftVersion,
1560+
]),
1561+
],
1562+
buildPhases: [
1563+
TestSourcesBuildPhase([
1564+
"main.swift",
1565+
]),
1566+
])
1567+
])
1568+
let tester = try await TaskConstructionTester(getCore(), testProject)
1569+
1570+
await tester.checkBuild(runDestination: .macOS) { results in
1571+
results.checkTarget("Exec") { target in
1572+
results.checkTask(.matchTarget(target), .matchRuleType("SwiftDriver Compilation Requirements")) { task in
1573+
task.checkCommandLineContains(["-explicit-module-build"])
1574+
task.checkCommandLineContains(["-incremental"])
1575+
task.checkCommandLineContains(["-incremental-dependency-scan"])
1576+
}
1577+
}
1578+
results.checkNoDiagnostics()
1579+
}
1580+
1581+
await tester.checkBuild(BuildParameters(configuration: "Debug", overrides: ["SWIFT_DISABLE_INCREMENTAL_SCAN": "YES"]), runDestination: .macOS) { results in
1582+
results.checkTarget("Exec") { target in
1583+
results.checkTask(.matchTarget(target), .matchRuleType("SwiftDriver Compilation Requirements")) { task in
1584+
task.checkCommandLineContains(["-explicit-module-build"])
1585+
task.checkCommandLineContains(["-incremental"])
1586+
task.checkCommandLineDoesNotContain("-incremental-dependency-scan")
1587+
}
1588+
}
1589+
results.checkNoDiagnostics()
1590+
}
1591+
}
1592+
15331593
@Test(.requireSDKs(.macOS))
15341594
func swift4DisablesExplicitModules() async throws {
15351595
let testProject = try await TestProject(

0 commit comments

Comments
 (0)