diff --git a/Sources/SWBCore/Settings/BuiltinMacros.swift b/Sources/SWBCore/Settings/BuiltinMacros.swift index ccde9c38..11f2919a 100644 --- a/Sources/SWBCore/Settings/BuiltinMacros.swift +++ b/Sources/SWBCore/Settings/BuiltinMacros.swift @@ -1002,6 +1002,7 @@ public final class BuiltinMacros { public static let SWIFT_EMIT_MODULE_INTERFACE = BuiltinMacros.declareBooleanMacro("SWIFT_EMIT_MODULE_INTERFACE") public static let SWIFT_ENABLE_BATCH_MODE = BuiltinMacros.declareBooleanMacro("SWIFT_ENABLE_BATCH_MODE") public static let SWIFT_ENABLE_INCREMENTAL_COMPILATION = BuiltinMacros.declareBooleanMacro("SWIFT_ENABLE_INCREMENTAL_COMPILATION") + public static let SWIFT_ENABLE_INCREMENTAL_SCAN = BuiltinMacros.declareBooleanMacro("SWIFT_ENABLE_INCREMENTAL_SCAN") public static let SWIFT_ENABLE_LAYOUT_STRING_VALUE_WITNESSES = BuiltinMacros.declareBooleanMacro("SWIFT_ENABLE_LAYOUT_STRING_VALUE_WITNESSES") public static let SWIFT_ENABLE_LIBRARY_EVOLUTION = BuiltinMacros.declareBooleanMacro("SWIFT_ENABLE_LIBRARY_EVOLUTION") public static let SWIFT_ENABLE_BARE_SLASH_REGEX = BuiltinMacros.declareBooleanMacro("SWIFT_ENABLE_BARE_SLASH_REGEX") @@ -2164,6 +2165,7 @@ public final class BuiltinMacros { SWIFT_EMIT_MODULE_INTERFACE, SWIFT_ENABLE_BATCH_MODE, SWIFT_ENABLE_INCREMENTAL_COMPILATION, + SWIFT_ENABLE_INCREMENTAL_SCAN, SWIFT_ENABLE_LAYOUT_STRING_VALUE_WITNESSES, SWIFT_ENABLE_LIBRARY_EVOLUTION, SWIFT_USE_INTEGRATED_DRIVER, diff --git a/Sources/SWBCore/SpecImplementations/Tools/SwiftCompiler.swift b/Sources/SWBCore/SpecImplementations/Tools/SwiftCompiler.swift index 826b2917..44b2fd0f 100644 --- a/Sources/SWBCore/SpecImplementations/Tools/SwiftCompiler.swift +++ b/Sources/SWBCore/SpecImplementations/Tools/SwiftCompiler.swift @@ -119,6 +119,7 @@ public struct SwiftSourceFileIndexingInfo: SourceFileIndexingInfo { "-emit-dependencies", "-serialize-diagnostics", "-incremental", + "-incremental-dependency-scan", "-parseable-output", "-use-frontend-parseable-output", "-whole-module-optimization", @@ -153,6 +154,7 @@ public struct SwiftSourceFileIndexingInfo: SourceFileIndexingInfo { // can be removed after we use the new driver instead (rdar://75851402). private static let newDriverFlags: Set = [ "-driver-print-graphviz", + "-incremental-dependency-scan", "-explicit-module-build", "-experimental-explicit-module-build", "-nonlib-dependency-scanner", @@ -1743,6 +1745,10 @@ public final class SwiftCompilerSpec : CompilerSpec, SpecIdentifierType, SwiftDi if cbc.scope.evaluate(BuiltinMacros.SWIFT_ENABLE_INCREMENTAL_COMPILATION) { args.append("-incremental") + if LibSwiftDriver.supportsDriverFlag(spelled: "-incremental-dependency-scan"), + cbc.scope.evaluate(BuiltinMacros.SWIFT_ENABLE_INCREMENTAL_SCAN) { + args.append("-incremental-dependency-scan") + } } } @@ -3284,6 +3290,8 @@ public final class SwiftCompilerSpec : CompilerSpec, SpecIdentifierType, SwiftDi for arg in [ // Should strip this because it saves some work and avoids writing a useless incremental build record "-incremental", + // Same as above + "-incremental-dependency-scan", // Stripped because we want to end up in single file mode "-enable-batch-mode", diff --git a/Tests/SWBTaskConstructionTests/SwiftTaskConstructionTests.swift b/Tests/SWBTaskConstructionTests/SwiftTaskConstructionTests.swift index 89277df7..42904bd0 100644 --- a/Tests/SWBTaskConstructionTests/SwiftTaskConstructionTests.swift +++ b/Tests/SWBTaskConstructionTests/SwiftTaskConstructionTests.swift @@ -1535,6 +1535,64 @@ fileprivate struct SwiftTaskConstructionTests: CoreBasedTests { } } + @Test(.requireSDKs(.macOS), .enabled(if: LibSwiftDriver.supportsDriverFlag(spelled: "-incremental-dependency-scan"))) + func optOutIncrementalScanning() async throws { + let testProject = try await TestProject( + "aProject", + groupTree: TestGroup( + "SomeFiles", path: "Sources", + children: [ + TestFile("main.swift"), + ]), + buildConfigurations: [ + TestBuildConfiguration( + "Debug", + buildSettings: [ + "PRODUCT_NAME": "$(TARGET_NAME)", + "SWIFT_ENABLE_EXPLICIT_MODULES": "YES", + ]), + ], + targets: [ + TestStandardTarget( + "Exec", type: .commandLineTool, + buildConfigurations: [ + TestBuildConfiguration("Debug", + buildSettings: [ + "SWIFT_EXEC": swiftCompilerPath.str, + "SWIFT_VERSION": swiftVersion, + ]), + ], + buildPhases: [ + TestSourcesBuildPhase([ + "main.swift", + ]), + ]) + ]) + let tester = try await TaskConstructionTester(getCore(), testProject) + + await tester.checkBuild(BuildParameters(configuration: "Debug", overrides: ["SWIFT_ENABLE_INCREMENTAL_SCAN": "YES"]), runDestination: .macOS) { results in + results.checkTarget("Exec") { target in + results.checkTask(.matchTarget(target), .matchRuleType("SwiftDriver Compilation Requirements")) { task in + task.checkCommandLineContains(["-explicit-module-build"]) + task.checkCommandLineContains(["-incremental"]) + task.checkCommandLineContains(["-incremental-dependency-scan"]) + } + } + results.checkNoDiagnostics() + } + + await tester.checkBuild(runDestination: .macOS) { results in + results.checkTarget("Exec") { target in + results.checkTask(.matchTarget(target), .matchRuleType("SwiftDriver Compilation Requirements")) { task in + task.checkCommandLineContains(["-explicit-module-build"]) + task.checkCommandLineContains(["-incremental"]) + task.checkCommandLineDoesNotContain("-incremental-dependency-scan") + } + } + results.checkNoDiagnostics() + } + } + @Test(.requireSDKs(.macOS)) func swift4DisablesExplicitModules() async throws { let testProject = try await TestProject(