Skip to content
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

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

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
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
Expand Up @@ -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
Expand All @@ -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
Expand All @@ -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.
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
24 changes: 15 additions & 9 deletions Sources/SwiftDriver/Jobs/FrontendJobHelpers.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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) {
Expand Down Expand Up @@ -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)
}

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

return try explicitDependencyBuildPlanner!.generateExplicitModuleDependenciesBuildJobs()
}
Expand Down
5 changes: 3 additions & 2 deletions Sources/SwiftDriver/Toolchains/DarwinToolchain.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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 }
Expand Down Expand Up @@ -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.
Expand Down
3 changes: 2 additions & 1 deletion Sources/SwiftDriver/Toolchains/GenericUnixToolchain.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand Down
6 changes: 4 additions & 2 deletions Sources/SwiftDriver/Toolchains/Toolchain.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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}
Expand Down Expand Up @@ -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
Expand Down
Loading