Skip to content

Commit 9171fbb

Browse files
authored
Revert "[Explicit Module Builds] Re-scan all clang modules against all targets against which they will be built."
1 parent 0a5cd34 commit 9171fbb

21 files changed

+94
-383
lines changed

Sources/SwiftDriver/Driver/Driver.swift

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -205,7 +205,7 @@ public struct Driver {
205205
/// A collection describing external dependencies for the current main module that may be invisible to
206206
/// the driver itself, but visible to its clients (e.g. build systems like SwiftPM). Along with the external dependencies'
207207
/// module dependency graphs.
208-
@_spi(Testing) public var externalDependencyArtifactMap: ExternalDependencyArtifactMap? = nil
208+
internal var externalDependencyArtifactMap: ExternalDependencyArtifactMap? = nil
209209

210210
/// Handler for emitting diagnostics to stderr.
211211
public static let stderrDiagnosticsHandler: DiagnosticsEngine.DiagnosticsHandler = { diagnostic in
@@ -1005,9 +1005,6 @@ extension Driver {
10051005
case .scanDependencies:
10061006
compilerOutputType = .jsonDependencies
10071007

1008-
case .scanClangDependencies:
1009-
compilerOutputType = .jsonClangDependencies
1010-
10111008
default:
10121009
fatalError("unhandled output mode option \(outputOption)")
10131010
}

Sources/SwiftDriver/Explicit Module Builds/ClangVersionedDependencyResolution.swift

Lines changed: 0 additions & 120 deletions
This file was deleted.

Sources/SwiftDriver/Explicit Module Builds/ExplicitModuleBuildHandler.swift

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,9 @@ public typealias ExternalDependencyArtifactMap =
3434
/// The toolchain to be used for frontend job generation.
3535
private let toolchain: Toolchain
3636

37+
/// A collection of external dependency modules, and their binary module file paths and dependency graph.
38+
internal let externalDependencyArtifactMap: ExternalDependencyArtifactMap
39+
3740
/// The file system which we should interact with.
3841
/// FIXME: Our end goal is to not have any direct filesystem manipulation in here, but that's dependent on getting the
3942
/// dependency scanner/dependency job generation moved into a Job.
@@ -45,11 +48,12 @@ public typealias ExternalDependencyArtifactMap =
4548
/// dependency scanner/dependency job generation moved into a Job.
4649
private let temporaryDirectory: AbsolutePath
4750

48-
public init(dependencyGraph: InterModuleDependencyGraph,
49-
toolchain: Toolchain,
50-
fileSystem: FileSystem) throws {
51+
public init(dependencyGraph: InterModuleDependencyGraph, toolchain: Toolchain,
52+
fileSystem: FileSystem,
53+
externalDependencyArtifactMap: ExternalDependencyArtifactMap) throws {
5154
self.dependencyGraph = dependencyGraph
5255
self.toolchain = toolchain
56+
self.externalDependencyArtifactMap = externalDependencyArtifactMap
5357
self.fileSystem = fileSystem
5458
self.temporaryDirectory = try determineTempDirectory()
5559
}
@@ -115,6 +119,11 @@ public typealias ExternalDependencyArtifactMap =
115119
/// - Generate Job: S1
116120
///
117121
mutating public func generateExplicitModuleDependenciesBuildJobs() throws -> [Job] {
122+
// Resolve placeholder dependencies in the dependency graph, if any.
123+
if (!externalDependencyArtifactMap.isEmpty) {
124+
try resolvePlaceholderDependencies()
125+
}
126+
118127
// Compute jobs for all main module dependencies
119128
var mainModuleInputs: [TypedVirtualPath] = []
120129
var mainModuleCommandLine: [Job.ArgTemplate] = []
@@ -435,7 +444,7 @@ extension ExplicitModuleBuildHandler {
435444

436445
/// Encapsulates some of the common queries of the ExplicitModuleBuildeHandler with error-checking
437446
/// on the dependency graph's structure.
438-
internal extension InterModuleDependencyGraph {
447+
private extension InterModuleDependencyGraph {
439448
func moduleInfo(of moduleId: ModuleDependencyId) throws -> ModuleInfo {
440449
guard let moduleInfo = modules[moduleId] else {
441450
throw Driver.Error.missingModuleDependency(moduleId.moduleName)

Sources/SwiftDriver/Explicit Module Builds/ModuleDependencyScanning.swift

Lines changed: 1 addition & 64 deletions
Original file line numberDiff line numberDiff line change
@@ -11,11 +11,10 @@
1111
//===----------------------------------------------------------------------===//
1212
import Foundation
1313
import TSCBasic
14-
import SwiftOptions
1514

1615
extension Driver {
1716
/// Precompute the dependencies for a given Swift compilation, producing a
18-
/// dependency graph including all Swift and C module files and
17+
/// complete dependency graph including all Swift and C module files and
1918
/// source files.
2019
mutating func dependencyScanningJob() throws -> Job {
2120
var inputs: [TypedVirtualPath] = []
@@ -74,66 +73,4 @@ extension Driver {
7473
try fileSystem.writeFileContents(placeholderMapFilePath, bytes: ByteString(contents))
7574
return placeholderMapFilePath
7675
}
77-
78-
/// Compute the dependencies for a given Clang module, by invoking the Clang dependency scanning action
79-
/// with the given module's name and a set of arguments (including the target version)
80-
mutating func clangDependencyScanningJob(moduleId: ModuleDependencyId,
81-
pcmArgs: [String]) throws -> Job {
82-
var inputs: [TypedVirtualPath] = []
83-
84-
// Aggregate the fast dependency scanner arguments
85-
var commandLine: [Job.ArgTemplate] = swiftCompilerPrefixArgs.map { Job.ArgTemplate.flag($0) }
86-
commandLine.appendFlag("-frontend")
87-
commandLine.appendFlag("-scan-clang-dependencies")
88-
89-
try addCommonFrontendOptions(commandLine: &commandLine, inputs: &inputs,
90-
bridgingHeaderHandling: .precompiled,
91-
moduleDependencyGraphUse: .dependencyScan)
92-
93-
// Ensure the `-target` option is inherited from the dependent Swift module's PCM args
94-
if let targetOptionIndex = pcmArgs.firstIndex(of: Option.target.spelling) {
95-
// PCM args are formulated as Clang command line options specified with:
96-
// -Xcc <option> -Xcc <option_value>
97-
assert(pcmArgs.count > targetOptionIndex + 1 && pcmArgs[targetOptionIndex + 1] == "-Xcc")
98-
let pcmArgTriple = Triple(pcmArgs[targetOptionIndex + 2])
99-
// Override the invocation's default target argument by appending the one extracted from
100-
// the pcmArgs
101-
commandLine.appendFlag(.target)
102-
commandLine.appendFlag(pcmArgTriple.triple)
103-
}
104-
105-
// Add the PCM args specific to this scan
106-
pcmArgs.forEach { commandLine.appendFlags($0) }
107-
108-
// This action does not require any input files, but all frontend actions require
109-
// at least one input so pick any input of the current compilation.
110-
let inputFile = inputFiles.first { $0.type == .swift }
111-
commandLine.appendPath(inputFile!.file)
112-
inputs.append(inputFile!)
113-
114-
commandLine.appendFlags("-module-name", moduleId.moduleName)
115-
// Construct the scanning job.
116-
return Job(moduleName: moduleOutputInfo.name,
117-
kind: .scanClangDependencies,
118-
tool: VirtualPath.absolute(try toolchain.getToolPath(.swiftCompiler)),
119-
commandLine: commandLine,
120-
displayInputs: inputs,
121-
inputs: inputs,
122-
outputs: [TypedVirtualPath(file: .standardOutput, type: .jsonDependencies)],
123-
supportsResponseFiles: true)
124-
}
125-
126-
mutating func scanClangModule(moduleId: ModuleDependencyId, pcmArgs: [String])
127-
throws -> InterModuleDependencyGraph {
128-
let clangDependencyScannerJob = try clangDependencyScanningJob(moduleId: moduleId,
129-
pcmArgs: pcmArgs)
130-
let forceResponseFiles = parsedOptions.hasArgument(.driverForceResponseFiles)
131-
132-
let dependencyGraph =
133-
try self.executor.execute(job: clangDependencyScannerJob,
134-
capturingJSONOutputAs: InterModuleDependencyGraph.self,
135-
forceResponseFiles: forceResponseFiles,
136-
recordedInputModificationDates: recordedInputModificationDates)
137-
return dependencyGraph
138-
}
13976
}

0 commit comments

Comments
 (0)