Skip to content

[Caching] Support -resolved-plugin-validation #1862

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -53,6 +53,7 @@ public typealias ExternalTargetModuleDetailsMap = [ModuleDependencyId: ExternalT
private let mainModuleName: String?
private let cas: SwiftScanCAS?
private let swiftScanOracle: InterModuleDependencyOracle
private let prefixMap: [(AbsolutePath, AbsolutePath)]

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

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

// Add prefix mapping. The option is cache invariant so it can be added without affecting cache key.
for (key, value) in prefixMap {
commandLine.appendFlag("-cache-replay-prefix-map")
commandLine.appendFlag(value.pathString + "=" + key.pathString)
}

jobs.append(Job(
moduleName: moduleId.moduleName,
kind: .compileModuleFromInterface,
@@ -238,6 +247,12 @@ public typealias ExternalTargetModuleDetailsMap = [ModuleDependencyId: ExternalT
cacheKeys = [:]
}

// Add prefix mapping. The option is cache invariant so it can be added without affecting cache key.
for (key, value) in prefixMap {
commandLine.appendFlag("-cache-replay-prefix-map")
commandLine.appendFlag(value.pathString + "=" + key.pathString)
}

jobs.append(Job(
moduleName: moduleId.moduleName,
kind: .generatePCM,
Original file line number Diff line number Diff line change
@@ -195,6 +195,10 @@ public extension Driver {
}
}

if isFrontendArgSupported(.resolvedPluginVerification) {
commandLine.appendFlag(.resolvedPluginVerification)
}

// Pass on the input files
commandLine.append(contentsOf: inputFiles.filter { $0.type == .swift }.map { .path($0.file) })
return (inputs, commandLine)
24 changes: 15 additions & 9 deletions Sources/SwiftDriver/Jobs/FrontendJobHelpers.swift
Original file line number Diff line number Diff line change
@@ -84,12 +84,13 @@ extension Driver {
break
}

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

// Emit user-provided plugin paths, in order.
if isFrontendArgSupported(.externalPluginPath) {
try commandLine.appendAll(.pluginPath, .externalPluginPath, .loadPluginLibrary, .loadPluginExecutable, from: &parsedOptions)
} else if isFrontendArgSupported(.pluginPath) {
try commandLine.appendAll(.pluginPath, .loadPluginLibrary, from: &parsedOptions)
if !isPlanJobForExplicitModule {
if isFrontendArgSupported(.externalPluginPath) {
try commandLine.appendAll(.pluginPath, .externalPluginPath, .loadPluginLibrary, .loadPluginExecutable, from: &parsedOptions)
} else if isFrontendArgSupported(.pluginPath) {
try commandLine.appendAll(.pluginPath, .loadPluginLibrary, from: &parsedOptions)
}
}

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

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

try toolchain.addPlatformSpecificCommonFrontendOptions(commandLine: &commandLine,
inputs: &inputs,
frontendTargetInfo: frontendTargetInfo,
driver: &self)
driver: &self,
skipMacroOptions: skipMacroOptions)

// Otherwise, prefer the platform's plugins.
if !hasToolchainStdlib {
if !hasToolchainStdlib, !skipMacroOptions {
try addPluginPathArguments(commandLine: &commandLine)
}

3 changes: 2 additions & 1 deletion Sources/SwiftDriver/Jobs/Planning.swift
Original file line number Diff line number Diff line change
@@ -688,7 +688,8 @@ extension Driver {
integratedDriver: integratedDriver,
supportsExplicitInterfaceBuild:
isFrontendArgSupported(.explicitInterfaceModuleBuild),
cas: cas)
cas: cas,
prefixMap: prefixMapping)

return try explicitDependencyBuildPlanner!.generateExplicitModuleDependenciesBuildJobs()
}
5 changes: 3 additions & 2 deletions Sources/SwiftDriver/Toolchains/DarwinToolchain.swift
Original file line number Diff line number Diff line change
@@ -392,7 +392,8 @@ public final class DarwinToolchain: Toolchain {
commandLine: inout [Job.ArgTemplate],
inputs: inout [TypedVirtualPath],
frontendTargetInfo: FrontendTargetInfo,
driver: inout Driver
driver: inout Driver,
skipMacroOptions: Bool
) throws {
guard let sdkPath = frontendTargetInfo.sdkPath?.path,
let sdkInfo = getTargetSDKInfo(sdkPath: sdkPath) else { return }
@@ -477,7 +478,7 @@ public final class DarwinToolchain: Toolchain {
}
}

if driver.isFrontendArgSupported(.externalPluginPath) {
if driver.isFrontendArgSupported(.externalPluginPath) && !skipMacroOptions {
// If the PLATFORM_DIR environment variable is set, also add plugin
// paths into it. Since this is a user override, it comes beore the
// default platform path that's based on the SDK.
3 changes: 2 additions & 1 deletion Sources/SwiftDriver/Toolchains/GenericUnixToolchain.swift
Original file line number Diff line number Diff line change
@@ -150,7 +150,8 @@ public final class GenericUnixToolchain: Toolchain {
commandLine: inout [Job.ArgTemplate],
inputs: inout [TypedVirtualPath],
frontendTargetInfo: FrontendTargetInfo,
driver: inout Driver
driver: inout Driver,
skipMacroOptions: Bool
) throws {
if let sysroot = driver.parsedOptions.getLastArgument(.sysroot)?.asSingle {
commandLine.appendFlag("-sysroot")
6 changes: 4 additions & 2 deletions Sources/SwiftDriver/Toolchains/Toolchain.swift
Original file line number Diff line number Diff line change
@@ -154,7 +154,8 @@ public protocol Toolchain {
commandLine: inout [Job.ArgTemplate],
inputs: inout [TypedVirtualPath],
frontendTargetInfo: FrontendTargetInfo,
driver: inout Driver
driver: inout Driver,
skipMacroOptions: Bool
) throws

var dummyForTestingObjectFormat: Triple.ObjectFormat {get}
@@ -326,7 +327,8 @@ extension Toolchain {
commandLine: inout [Job.ArgTemplate],
inputs: inout [TypedVirtualPath],
frontendTargetInfo: FrontendTargetInfo,
driver: inout Driver
driver: inout Driver,
skipMacroOptions: Bool
) throws {}

/// Resolves the path to the given tool and whether or not it supports response files so that it
20 changes: 20 additions & 0 deletions Sources/SwiftOptions/Options.swift

Large diffs are not rendered by default.

4 changes: 4 additions & 0 deletions Tests/SwiftDriverTests/CachingBuildTests.swift
Original file line number Diff line number Diff line change
@@ -939,6 +939,10 @@ final class CachingBuildTests: XCTestCase {
XCTAssertFalse(try command.contains {
$0.starts(with: try testInputsPath.description)
})
/// command-line that compiles swift should contains -cache-replay-prefix-map
XCTAssertTrue(command.contains { $0 == "-cache-replay-prefix-map" })
XCTAssertFalse(command.contains { $0 == "-plugin-path" || $0 == "-external-plugin-path" ||
$0 == "-load-plugin-library" || $0 == "-load-plugin-executable" })
}
}
}