@@ -162,33 +162,11 @@ public typealias ExternalTargetModuleDetailsMap = [ModuleDependencyId: ExternalT
162
162
// Add precompiled module candidates, if present
163
163
if let compiledCandidateList = moduleDetails. compiledModuleCandidates {
164
164
for compiledCandidate in compiledCandidateList {
165
- commandLine. appendFlag ( " -candidate-module-file " )
166
- let compiledCandidatePath = compiledCandidate
167
- commandLine. appendPath ( VirtualPath . lookup ( compiledCandidatePath. path) )
168
- inputs. append ( TypedVirtualPath ( file: compiledCandidatePath. path,
165
+ inputs. append ( TypedVirtualPath ( file: compiledCandidate. path,
169
166
type: . swiftModule) )
170
167
}
171
168
}
172
169
173
- if supportsExplicitInterfaceBuild {
174
- // Ensure the compiler flags specified in the interface are ignored
175
- // because they are already captured in the dependency scanner output
176
- commandLine. appendFlag ( . explicitInterfaceModuleBuild)
177
- }
178
-
179
- // FIXME: This is a temporary measure meant to be deleted once supported toolchains'
180
- // scanners always output commands with '-o'.
181
- //
182
- // If the dependency scanner did not append its own "-o", add it here.
183
- // This is temporary and is meant to handle both: the scanner that
184
- // appends '-o' and one that doesn't, until we have a toolchain snapshot with the scanner
185
- // that appends '-o' always.
186
- let outputFlagIndeces = commandLine. enumerated ( ) . compactMap { $1 == . flag( " -o " ) ? $0 : nil }
187
- if outputFlagIndeces. isEmpty {
188
- commandLine. appendFlag ( . o)
189
- commandLine. appendPath ( VirtualPath . lookup ( moduleInfo. modulePath. path) )
190
- }
191
-
192
170
jobs. append ( Job (
193
171
moduleName: moduleId. moduleName,
194
172
kind: . compileModuleFromInterface,
@@ -241,23 +219,6 @@ public typealias ExternalTargetModuleDetailsMap = [ModuleDependencyId: ExternalT
241
219
let moduleMapPath = moduleDetails. moduleMapPath. path
242
220
let modulePCMPath = moduleInfo. modulePath
243
221
outputs. append ( TypedVirtualPath ( file: modulePCMPath. path, type: . pcm) )
244
-
245
- // TODO: Remove this once toolchain is updated
246
- // If the dependency scanner did not append its own "-o", add it here.
247
- // This is temporary and is meant to handle both: the scanner that
248
- // appends '-o' and one that doesn't, until we have a toolchain snapshot with the scanner
249
- // that appends '-o' always.
250
- let outputFlagIndeces = commandLine. enumerated ( ) . compactMap { $1 == . flag( " -o " ) ? $0 : nil }
251
- // One '-o' is expected as an `-Xcc` flag.
252
- if outputFlagIndeces. count <= 1 {
253
- commandLine. appendFlags ( " -o " , modulePCMPath. path. description)
254
- }
255
-
256
- // TODO: Remove this once toolchain is updated
257
- // Fixup "-o -Xcc '<replace-me>'"
258
- if let outputIndex = commandLine. firstIndex ( of: . flag( " <replace-me> " ) ) {
259
- commandLine [ outputIndex] = . path( VirtualPath . lookup ( modulePCMPath. path) )
260
- }
261
222
262
223
// The only required input is the .modulemap for this module.
263
224
// Command line options in the dependency scanner output will include the
@@ -285,53 +246,42 @@ public typealias ExternalTargetModuleDetailsMap = [ModuleDependencyId: ExternalT
285
246
inputs: inout [ TypedVirtualPath ] ,
286
247
commandLine: inout [ Job . ArgTemplate ] ) throws {
287
248
// Prohibit the frontend from implicitly building textual modules into binary modules.
288
- commandLine. appendFlags ( " -disable-implicit-swift-modules " ,
289
- " -Xcc " , " -fno-implicit-modules " ,
290
- " -Xcc " , " -fno-implicit-module-maps " )
291
249
var swiftDependencyArtifacts : [ SwiftModuleArtifactInfo ] = [ ]
292
250
var clangDependencyArtifacts : [ ClangModuleArtifactInfo ] = [ ]
293
251
try addModuleDependencies ( moduleId: moduleId, pcmArgs: pcmArgs,
294
252
clangDependencyArtifacts: & clangDependencyArtifacts,
295
253
swiftDependencyArtifacts: & swiftDependencyArtifacts)
296
254
297
- // Swift Module dependencies are passed encoded in a JSON file as described by
298
- // SwiftModuleArtifactInfo
299
- if !swiftDependencyArtifacts. isEmpty {
300
- let dependencyFile =
301
- try serializeModuleDependencies ( for: moduleId, dependencyArtifacts: swiftDependencyArtifacts)
302
- commandLine. appendFlag ( " -explicit-swift-module-map-file " )
303
- commandLine. appendPath ( dependencyFile)
304
- inputs. append ( TypedVirtualPath ( file: dependencyFile. intern ( ) ,
305
- type: . jsonSwiftArtifacts) )
306
- // Each individual module binary is still an "input" to ensure the build system gets the
307
- // order correctly.
308
- for dependencyModule in swiftDependencyArtifacts {
309
- inputs. append ( TypedVirtualPath ( file: dependencyModule. modulePath. path,
310
- type: . swiftModule) )
311
- }
255
+ // Each individual module binary is still an "input" to ensure the build system gets the
256
+ // order correctly.
257
+ for dependencyModule in swiftDependencyArtifacts {
258
+ inputs. append ( TypedVirtualPath ( file: dependencyModule. modulePath. path,
259
+ type: . swiftModule) )
312
260
}
261
+
313
262
// Clang module dependencies are specified on the command line explicitly
314
263
for moduleArtifactInfo in clangDependencyArtifacts {
315
264
let clangModulePath =
316
- TypedVirtualPath ( file: moduleArtifactInfo. modulePath . path,
265
+ TypedVirtualPath ( file: moduleArtifactInfo. clangModulePath . path,
317
266
type: . pcm)
318
267
let clangModuleMapPath =
319
- TypedVirtualPath ( file: moduleArtifactInfo. moduleMapPath . path,
268
+ TypedVirtualPath ( file: moduleArtifactInfo. clangModuleMapPath . path,
320
269
type: . clangModuleMap)
321
270
inputs. append ( clangModulePath)
322
271
inputs. append ( clangModuleMapPath)
272
+ }
323
273
324
- // If an existing dependency module path stub exists, replace it.
325
- if let existingIndex = commandLine . firstIndex ( of : . flag ( " -fmodule-file= " + moduleArtifactInfo . moduleName + " =<replace-me> " ) ) {
326
- commandLine [ existingIndex ] = . flag ( " -fmodule-file= \( moduleArtifactInfo . moduleName) = \( clangModulePath . file . description ) " )
327
- } else if case . swift ( _ ) = moduleId {
328
- commandLine . appendFlags ( " -Xcc " ,
329
- " -fmodule-file= \( moduleArtifactInfo . moduleName ) = \( clangModulePath . file . description ) " )
330
- }
331
- if case . swift ( _ ) = moduleId {
332
- commandLine. appendFlags ( " -Xcc " ,
333
- " -fmodule-map-file= \( clangModuleMapPath . file. description ) " )
334
- }
274
+ // Swift Main Module dependencies are passed encoded in a JSON file as described by
275
+ // SwiftModuleArtifactInfo
276
+ if moduleId . moduleName == mainModuleName {
277
+ let dependencyFile =
278
+ try serializeModuleDependencies ( for : moduleId ,
279
+ swiftDependencyArtifacts : swiftDependencyArtifacts ,
280
+ clangDependencyArtifacts : clangDependencyArtifacts )
281
+ commandLine . appendFlag ( " -explicit-swift-module-map-file " )
282
+ commandLine. appendPath ( dependencyFile )
283
+ inputs . append ( TypedVirtualPath ( file: dependencyFile . intern ( ) ,
284
+ type : . jsonSwiftArtifacts ) )
335
285
}
336
286
}
337
287
@@ -410,6 +360,9 @@ public typealias ExternalTargetModuleDetailsMap = [ModuleDependencyId: ExternalT
410
360
public mutating func resolveMainModuleDependencies( inputs: inout [ TypedVirtualPath ] ,
411
361
commandLine: inout [ Job . ArgTemplate ] ) throws {
412
362
let mainModuleId : ModuleDependencyId = . swift( dependencyGraph. mainModuleName)
363
+ commandLine. appendFlags ( " -disable-implicit-swift-modules " ,
364
+ " -Xcc " , " -fno-implicit-modules " ,
365
+ " -Xcc " , " -fno-implicit-module-maps " )
413
366
try resolveExplicitModuleDependencies ( moduleId: mainModuleId,
414
367
pcmArgs:
415
368
try dependencyGraph. swiftModulePCMArgs ( of: mainModuleId) ,
@@ -419,11 +372,15 @@ public typealias ExternalTargetModuleDetailsMap = [ModuleDependencyId: ExternalT
419
372
420
373
/// Store the output file artifacts for a given module in a JSON file, return the file's path.
421
374
private func serializeModuleDependencies( for moduleId: ModuleDependencyId ,
422
- dependencyArtifacts: [ SwiftModuleArtifactInfo ]
375
+ swiftDependencyArtifacts: [ SwiftModuleArtifactInfo ] ,
376
+ clangDependencyArtifacts: [ ClangModuleArtifactInfo ]
423
377
) throws -> VirtualPath {
378
+ let allDependencyArtifacts : [ ModuleDependencyArtifactInfo ] =
379
+ swiftDependencyArtifacts. map { ModuleDependencyArtifactInfo . swift ( $0) } +
380
+ clangDependencyArtifacts. map { ModuleDependencyArtifactInfo . clang ( $0) }
424
381
let encoder = JSONEncoder ( )
425
382
encoder. outputFormatting = [ . prettyPrinted]
426
- let contents = try encoder. encode ( dependencyArtifacts )
383
+ let contents = try encoder. encode ( allDependencyArtifacts )
427
384
return VirtualPath . createUniqueTemporaryFileWithKnownContents ( . init( " \( moduleId. moduleName) -dependencies.json " ) , contents)
428
385
}
429
386
0 commit comments