Skip to content

Commit 61937a8

Browse files
committed
[Explicit Module Builds] Remove logic for Swift-client-specific Clang module dependency jobs
We have moved towards a build model where the output of the dependency scanner is the canonical collection of modules that must be built. The driver's logic to generate potentially multiple examples of a given Clang dependency, with different command sets, as required per Swift client module in the build graph, is no longer valid - even module output paths are no longer determined by the driver. Remaining logic that is removed in this PR may result in mistakenly producing duplicate jobs for the same Clang PCM build job.
1 parent 2810937 commit 61937a8

File tree

1 file changed

+43
-67
lines changed

1 file changed

+43
-67
lines changed

Sources/SwiftDriver/ExplicitModuleBuilds/ExplicitDependencyBuildPlanner.swift

Lines changed: 43 additions & 67 deletions
Original file line numberDiff line numberDiff line change
@@ -102,26 +102,18 @@ public typealias ExternalTargetModuleDetailsMap = [ModuleDependencyId: ExternalT
102102
guard let mainModuleDependencies = reachabilityMap[mainModuleId] else {
103103
fatalError("Expected reachability information for the main module.")
104104
}
105-
// A collection of PCM Args that Clang modules must be built against
106-
var clangPCMSetMap: [ModuleDependencyId : Set<[String]>] = [:]
107105
let swiftDependenciesJobs =
108-
try generateSwiftDependenciesBuildJobs(for: mainModuleDependencies,
109-
clangPCMSetMap: &clangPCMSetMap)
110-
// Also take into account the PCMArgs of the main module
111-
try updateClangPCMArgSetMap(for: mainModuleId, clangPCMSetMap: &clangPCMSetMap)
106+
try generateSwiftDependenciesBuildJobs(for: mainModuleDependencies)
112107

113108
// Generate build jobs for all Clang modules
114109
let clangDependenciesJobs =
115-
try generateClangDependenciesBuildJobs(for: mainModuleDependencies,
116-
using: clangPCMSetMap)
110+
try generateClangDependenciesBuildJobs(for: mainModuleDependencies)
117111

118112
return swiftDependenciesJobs + clangDependenciesJobs
119113
}
120114

121115
/// Generate a build job for each Swift module in the set of supplied `dependencies`
122-
private mutating func generateSwiftDependenciesBuildJobs(for dependencies: Set<ModuleDependencyId>,
123-
clangPCMSetMap:
124-
inout [ModuleDependencyId : Set<[String]>])
116+
private mutating func generateSwiftDependenciesBuildJobs(for dependencies: Set<ModuleDependencyId>)
125117
throws -> [Job] {
126118
var jobs: [Job] = []
127119
let swiftDependencies = dependencies.filter {
@@ -143,13 +135,10 @@ public typealias ExternalTargetModuleDetailsMap = [ModuleDependencyId: ExternalT
143135
moduleDetails.commandLine?.forEach { commandLine.appendFlags($0) }
144136

145137
// Resolve all dependency module inputs for this Swift module
146-
try resolveExplicitModuleDependencies(moduleId: moduleId, pcmArgs: pcmArgs,
138+
try resolveExplicitModuleDependencies(moduleId: moduleId,
147139
inputs: &inputs,
148140
commandLine: &commandLine)
149141

150-
// Update the clangPCMSetMap for each Clang dependency of this module
151-
try updateClangPCMArgSetMap(for: moduleId, clangPCMSetMap: &clangPCMSetMap)
152-
153142
// Build the .swiftinterfaces file using a list of command line options specified in the
154143
// `details` field.
155144
guard let moduleInterfacePath = moduleDetails.moduleInterfacePath else {
@@ -182,9 +171,7 @@ public typealias ExternalTargetModuleDetailsMap = [ModuleDependencyId: ExternalT
182171

183172
/// Generate a build job for each Clang module in the set of supplied `dependencies`. Once per each required
184173
/// PCMArgSet as queried from the supplied `clangPCMSetMap`
185-
private mutating func generateClangDependenciesBuildJobs(for dependencies: Set<ModuleDependencyId>,
186-
using clangPCMSetMap:
187-
[ModuleDependencyId : Set<[String]>])
174+
private mutating func generateClangDependenciesBuildJobs(for dependencies: Set<ModuleDependencyId>)
188175
throws -> [Job] {
189176
var jobs: [Job] = []
190177
let clangDependencies = dependencies.filter {
@@ -194,61 +181,52 @@ public typealias ExternalTargetModuleDetailsMap = [ModuleDependencyId: ExternalT
194181
return false
195182
}
196183
for moduleId in clangDependencies {
197-
guard let pcmArgSet = clangPCMSetMap[moduleId] else {
198-
fatalError("Expected PCM Argument Set for module: \(moduleId.moduleName)")
199-
}
200184
let moduleInfo = try dependencyGraph.moduleInfo(of: moduleId)
201185
// Generate a distinct job for each required set of PCM Arguments for this module
202-
for pcmArgs in pcmArgSet {
203-
var inputs: [TypedVirtualPath] = []
204-
var outputs: [TypedVirtualPath] = []
205-
var commandLine: [Job.ArgTemplate] = []
206-
207-
// First, take the command line options provided in the dependency information
208-
let moduleDetails = try dependencyGraph.clangModuleDetails(of: moduleId)
209-
moduleDetails.commandLine.forEach { commandLine.appendFlags($0) }
210-
211-
// Add the `-target` option as inherited from the dependent Swift module's PCM args
212-
pcmArgs.forEach { commandLine.appendFlags($0) }
213-
214-
// Resolve all dependency module inputs for this Clang module
215-
try resolveExplicitModuleDependencies(moduleId: moduleId, pcmArgs: pcmArgs,
216-
inputs: &inputs,
217-
commandLine: &commandLine)
218-
219-
let moduleMapPath = moduleDetails.moduleMapPath.path
220-
let modulePCMPath = moduleInfo.modulePath
221-
outputs.append(TypedVirtualPath(file: modulePCMPath.path, type: .pcm))
222-
223-
// The only required input is the .modulemap for this module.
224-
// Command line options in the dependency scanner output will include the
225-
// required modulemap, so here we must only add it to the list of inputs.
226-
inputs.append(TypedVirtualPath(file: moduleMapPath,
227-
type: .clangModuleMap))
228-
229-
jobs.append(Job(
230-
moduleName: moduleId.moduleName,
231-
kind: .generatePCM,
232-
tool: try toolchain.resolvedTool(.swiftCompiler),
233-
commandLine: commandLine,
234-
inputs: inputs,
235-
primaryInputs: [],
236-
outputs: outputs
237-
))
238-
}
186+
var inputs: [TypedVirtualPath] = []
187+
var outputs: [TypedVirtualPath] = []
188+
var commandLine: [Job.ArgTemplate] = []
189+
190+
// First, take the command line options provided in the dependency information
191+
let moduleDetails = try dependencyGraph.clangModuleDetails(of: moduleId)
192+
moduleDetails.commandLine.forEach { commandLine.appendFlags($0) }
193+
194+
// Resolve all dependency module inputs for this Clang module
195+
try resolveExplicitModuleDependencies(moduleId: moduleId, inputs: &inputs,
196+
commandLine: &commandLine)
197+
198+
let moduleMapPath = moduleDetails.moduleMapPath.path
199+
let modulePCMPath = moduleInfo.modulePath
200+
outputs.append(TypedVirtualPath(file: modulePCMPath.path, type: .pcm))
201+
202+
// The only required input is the .modulemap for this module.
203+
// Command line options in the dependency scanner output will include the
204+
// required modulemap, so here we must only add it to the list of inputs.
205+
inputs.append(TypedVirtualPath(file: moduleMapPath,
206+
type: .clangModuleMap))
207+
208+
jobs.append(Job(
209+
moduleName: moduleId.moduleName,
210+
kind: .generatePCM,
211+
tool: try toolchain.resolvedTool(.swiftCompiler),
212+
commandLine: commandLine,
213+
inputs: inputs,
214+
primaryInputs: [],
215+
outputs: outputs
216+
))
239217
}
240218
return jobs
241219
}
242220

243221
/// For the specified module, update the given command line flags and inputs
244222
/// to use explicitly-built module dependencies.
245-
private mutating func resolveExplicitModuleDependencies(moduleId: ModuleDependencyId, pcmArgs: [String],
223+
private mutating func resolveExplicitModuleDependencies(moduleId: ModuleDependencyId,
246224
inputs: inout [TypedVirtualPath],
247225
commandLine: inout [Job.ArgTemplate]) throws {
248226
// Prohibit the frontend from implicitly building textual modules into binary modules.
249227
var swiftDependencyArtifacts: [SwiftModuleArtifactInfo] = []
250228
var clangDependencyArtifacts: [ClangModuleArtifactInfo] = []
251-
try addModuleDependencies(of: moduleId, pcmArgs: pcmArgs,
229+
try addModuleDependencies(of: moduleId,
252230
clangDependencyArtifacts: &clangDependencyArtifacts,
253231
swiftDependencyArtifacts: &swiftDependencyArtifacts)
254232

@@ -286,7 +264,7 @@ public typealias ExternalTargetModuleDetailsMap = [ModuleDependencyId: ExternalT
286264
}
287265

288266
private mutating func addModuleDependency(of moduleId: ModuleDependencyId,
289-
dependencyId: ModuleDependencyId, pcmArgs: [String],
267+
dependencyId: ModuleDependencyId,
290268
clangDependencyArtifacts: inout [ClangModuleArtifactInfo],
291269
swiftDependencyArtifacts: inout [SwiftModuleArtifactInfo]
292270
) throws {
@@ -332,15 +310,15 @@ public typealias ExternalTargetModuleDetailsMap = [ModuleDependencyId: ExternalT
332310

333311
/// Add a specific module dependency as an input and a corresponding command
334312
/// line flag.
335-
private mutating func addModuleDependencies(of moduleId: ModuleDependencyId, pcmArgs: [String],
313+
private mutating func addModuleDependencies(of moduleId: ModuleDependencyId,
336314
clangDependencyArtifacts: inout [ClangModuleArtifactInfo],
337315
swiftDependencyArtifacts: inout [SwiftModuleArtifactInfo]
338316
) throws {
339317
guard let moduleDependencies = reachabilityMap[moduleId] else {
340318
fatalError("Expected reachability information for the module: \(moduleId.moduleName).")
341319
}
342320
for dependencyId in moduleDependencies {
343-
try addModuleDependency(of: moduleId, dependencyId: dependencyId, pcmArgs: pcmArgs,
321+
try addModuleDependency(of: moduleId, dependencyId: dependencyId,
344322
clangDependencyArtifacts: &clangDependencyArtifacts,
345323
swiftDependencyArtifacts: &swiftDependencyArtifacts)
346324
}
@@ -374,8 +352,6 @@ public typealias ExternalTargetModuleDetailsMap = [ModuleDependencyId: ExternalT
374352
"-Xcc", "-fno-implicit-modules",
375353
"-Xcc", "-fno-implicit-module-maps")
376354
try resolveExplicitModuleDependencies(moduleId: mainModuleId,
377-
pcmArgs:
378-
try dependencyGraph.swiftModulePCMArgs(of: mainModuleId),
379355
inputs: &inputs,
380356
commandLine: &commandLine)
381357
}
@@ -405,10 +381,10 @@ public typealias ExternalTargetModuleDetailsMap = [ModuleDependencyId: ExternalT
405381
continue
406382
}
407383
addedDependencies.insert(bridgingHeaderDepID)
408-
try addModuleDependency(of: mainModuleId, dependencyId: bridgingHeaderDepID, pcmArgs: [],
384+
try addModuleDependency(of: mainModuleId, dependencyId: bridgingHeaderDepID,
409385
clangDependencyArtifacts: &clangDependencyArtifacts,
410386
swiftDependencyArtifacts: &swiftDependencyArtifacts)
411-
try addModuleDependencies(of: bridgingHeaderDepID, pcmArgs: [],
387+
try addModuleDependencies(of: bridgingHeaderDepID,
412388
clangDependencyArtifacts: &clangDependencyArtifacts,
413389
swiftDependencyArtifacts: &swiftDependencyArtifacts)
414390
let depInfo = try dependencyGraph.moduleInfo(of: bridgingHeaderDepID)

0 commit comments

Comments
 (0)