Skip to content

Commit e7753dd

Browse files
Merge pull request #1862 from cachemeifyoucan/eng/PR-resolved-plugin-validation
[Caching] Support -resolved-plugin-validation
2 parents 4f38059 + 453b224 commit e7753dd

File tree

9 files changed

+70
-16
lines changed

9 files changed

+70
-16
lines changed

Sources/SwiftDriver/ExplicitModuleBuilds/ExplicitDependencyBuildPlanner.swift

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,7 @@ public typealias ExternalTargetModuleDetailsMap = [ModuleDependencyId: ExternalT
5353
private let mainModuleName: String?
5454
private let cas: SwiftScanCAS?
5555
private let swiftScanOracle: InterModuleDependencyOracle
56+
private let prefixMap: [(AbsolutePath, AbsolutePath)]
5657

5758
/// Clang PCM names contain a hash of the command-line arguments that were used to build them.
5859
/// We avoid re-running the hash computation with the use of this cache
@@ -73,7 +74,8 @@ public typealias ExternalTargetModuleDetailsMap = [ModuleDependencyId: ExternalT
7374
dependencyOracle: InterModuleDependencyOracle,
7475
integratedDriver: Bool = true,
7576
supportsExplicitInterfaceBuild: Bool = false,
76-
cas: SwiftScanCAS? = nil) throws {
77+
cas: SwiftScanCAS? = nil,
78+
prefixMap: [(AbsolutePath, AbsolutePath)] = []) throws {
7779
self.dependencyGraph = dependencyGraph
7880
self.toolchain = toolchain
7981
self.swiftScanOracle = dependencyOracle
@@ -82,6 +84,7 @@ public typealias ExternalTargetModuleDetailsMap = [ModuleDependencyId: ExternalT
8284
self.reachabilityMap = try dependencyGraph.computeTransitiveClosure()
8385
self.supportsExplicitInterfaceBuild = supportsExplicitInterfaceBuild
8486
self.cas = cas
87+
self.prefixMap = prefixMap
8588
}
8689

8790
/// Supports resolving bridging header pch command from swiftScan.
@@ -185,6 +188,12 @@ public typealias ExternalTargetModuleDetailsMap = [ModuleDependencyId: ExternalT
185188
}
186189
}
187190

191+
// Add prefix mapping. The option is cache invariant so it can be added without affecting cache key.
192+
for (key, value) in prefixMap {
193+
commandLine.appendFlag("-cache-replay-prefix-map")
194+
commandLine.appendFlag(value.pathString + "=" + key.pathString)
195+
}
196+
188197
jobs.append(Job(
189198
moduleName: moduleId.moduleName,
190199
kind: .compileModuleFromInterface,
@@ -238,6 +247,12 @@ public typealias ExternalTargetModuleDetailsMap = [ModuleDependencyId: ExternalT
238247
cacheKeys = [:]
239248
}
240249

250+
// Add prefix mapping. The option is cache invariant so it can be added without affecting cache key.
251+
for (key, value) in prefixMap {
252+
commandLine.appendFlag("-cache-replay-prefix-map")
253+
commandLine.appendFlag(value.pathString + "=" + key.pathString)
254+
}
255+
241256
jobs.append(Job(
242257
moduleName: moduleId.moduleName,
243258
kind: .generatePCM,

Sources/SwiftDriver/ExplicitModuleBuilds/ModuleDependencyScanning.swift

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -195,6 +195,10 @@ public extension Driver {
195195
}
196196
}
197197

198+
if isFrontendArgSupported(.resolvedPluginVerification) {
199+
commandLine.appendFlag(.resolvedPluginVerification)
200+
}
201+
198202
// Pass on the input files
199203
commandLine.append(contentsOf: inputFiles.filter { $0.type == .swift }.map { .path($0.file) })
200204
return (inputs, commandLine)

Sources/SwiftDriver/Jobs/FrontendJobHelpers.swift

Lines changed: 15 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -84,12 +84,13 @@ extension Driver {
8484
break
8585
}
8686

87+
let isPlanJobForExplicitModule = parsedOptions.contains(.driverExplicitModuleBuild) &&
88+
moduleDependencyGraphUse == .computed
8789
let jobNeedPathRemap: Bool
8890
// If in ExplicitModuleBuild mode and the dependency graph has been computed, add module
8991
// dependencies.
9092
// May also be used for generation of the dependency graph itself in ExplicitModuleBuild mode.
91-
if (parsedOptions.contains(.driverExplicitModuleBuild) &&
92-
moduleDependencyGraphUse == .computed) {
93+
if isPlanJobForExplicitModule {
9394
switch kind {
9495
case .generatePCH:
9596
try addExplicitPCHBuildArguments(inputs: &inputs, commandLine: &commandLine)
@@ -344,10 +345,12 @@ extension Driver {
344345
}
345346

346347
// Emit user-provided plugin paths, in order.
347-
if isFrontendArgSupported(.externalPluginPath) {
348-
try commandLine.appendAll(.pluginPath, .externalPluginPath, .loadPluginLibrary, .loadPluginExecutable, from: &parsedOptions)
349-
} else if isFrontendArgSupported(.pluginPath) {
350-
try commandLine.appendAll(.pluginPath, .loadPluginLibrary, from: &parsedOptions)
348+
if !isPlanJobForExplicitModule {
349+
if isFrontendArgSupported(.externalPluginPath) {
350+
try commandLine.appendAll(.pluginPath, .externalPluginPath, .loadPluginLibrary, .loadPluginExecutable, from: &parsedOptions)
351+
} else if isFrontendArgSupported(.pluginPath) {
352+
try commandLine.appendAll(.pluginPath, .loadPluginLibrary, from: &parsedOptions)
353+
}
351354
}
352355

353356
if isFrontendArgSupported(.blockListFile) {
@@ -563,19 +566,22 @@ extension Driver {
563566
.appending(components: frontendTargetInfo.target.triple.platformName() ?? "", "Swift.swiftmodule")
564567
let hasToolchainStdlib = try fileSystem.exists(toolchainStdlibPath)
565568

569+
let skipMacroOptions = isPlanJobForExplicitModule && isFrontendArgSupported(.loadResolvedPlugin)
566570
// If the resource directory has the standard library, prefer the toolchain's plugins
567571
// to the platform SDK plugins.
568-
if hasToolchainStdlib {
572+
// For explicit module build, the resolved plugins are provided by scanner.
573+
if hasToolchainStdlib, !skipMacroOptions {
569574
try addPluginPathArguments(commandLine: &commandLine)
570575
}
571576

572577
try toolchain.addPlatformSpecificCommonFrontendOptions(commandLine: &commandLine,
573578
inputs: &inputs,
574579
frontendTargetInfo: frontendTargetInfo,
575-
driver: &self)
580+
driver: &self,
581+
skipMacroOptions: skipMacroOptions)
576582

577583
// Otherwise, prefer the platform's plugins.
578-
if !hasToolchainStdlib {
584+
if !hasToolchainStdlib, !skipMacroOptions {
579585
try addPluginPathArguments(commandLine: &commandLine)
580586
}
581587

Sources/SwiftDriver/Jobs/Planning.swift

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -688,7 +688,8 @@ extension Driver {
688688
integratedDriver: integratedDriver,
689689
supportsExplicitInterfaceBuild:
690690
isFrontendArgSupported(.explicitInterfaceModuleBuild),
691-
cas: cas)
691+
cas: cas,
692+
prefixMap: prefixMapping)
692693

693694
return try explicitDependencyBuildPlanner!.generateExplicitModuleDependenciesBuildJobs()
694695
}

Sources/SwiftDriver/Toolchains/DarwinToolchain.swift

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -392,7 +392,8 @@ public final class DarwinToolchain: Toolchain {
392392
commandLine: inout [Job.ArgTemplate],
393393
inputs: inout [TypedVirtualPath],
394394
frontendTargetInfo: FrontendTargetInfo,
395-
driver: inout Driver
395+
driver: inout Driver,
396+
skipMacroOptions: Bool
396397
) throws {
397398
guard let sdkPath = frontendTargetInfo.sdkPath?.path,
398399
let sdkInfo = getTargetSDKInfo(sdkPath: sdkPath) else { return }
@@ -477,7 +478,7 @@ public final class DarwinToolchain: Toolchain {
477478
}
478479
}
479480

480-
if driver.isFrontendArgSupported(.externalPluginPath) {
481+
if driver.isFrontendArgSupported(.externalPluginPath) && !skipMacroOptions {
481482
// If the PLATFORM_DIR environment variable is set, also add plugin
482483
// paths into it. Since this is a user override, it comes beore the
483484
// default platform path that's based on the SDK.

Sources/SwiftDriver/Toolchains/GenericUnixToolchain.swift

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -150,7 +150,8 @@ public final class GenericUnixToolchain: Toolchain {
150150
commandLine: inout [Job.ArgTemplate],
151151
inputs: inout [TypedVirtualPath],
152152
frontendTargetInfo: FrontendTargetInfo,
153-
driver: inout Driver
153+
driver: inout Driver,
154+
skipMacroOptions: Bool
154155
) throws {
155156
if let sysroot = driver.parsedOptions.getLastArgument(.sysroot)?.asSingle {
156157
commandLine.appendFlag("-sysroot")

Sources/SwiftDriver/Toolchains/Toolchain.swift

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -154,7 +154,8 @@ public protocol Toolchain {
154154
commandLine: inout [Job.ArgTemplate],
155155
inputs: inout [TypedVirtualPath],
156156
frontendTargetInfo: FrontendTargetInfo,
157-
driver: inout Driver
157+
driver: inout Driver,
158+
skipMacroOptions: Bool
158159
) throws
159160

160161
var dummyForTestingObjectFormat: Triple.ObjectFormat {get}
@@ -326,7 +327,8 @@ extension Toolchain {
326327
commandLine: inout [Job.ArgTemplate],
327328
inputs: inout [TypedVirtualPath],
328329
frontendTargetInfo: FrontendTargetInfo,
329-
driver: inout Driver
330+
driver: inout Driver,
331+
skipMacroOptions: Bool
330332
) throws {}
331333

332334
/// Resolves the path to the given tool and whether or not it supports response files so that it

0 commit comments

Comments
 (0)