Skip to content

Commit 1758095

Browse files
committed
[Explicit Module Builds] Add isFramework flag to the dependency graph and swift module info.
Ensure the flag is propagated from a given swift module's dependency graph details to its swift module info passed in as an explicit module map to frontend jobs.
1 parent 777a4bb commit 1758095

File tree

6 files changed

+32
-4
lines changed

6 files changed

+32
-4
lines changed

Sources/SwiftDriver/Explicit Module Builds/ExplicitModuleBuildHandler.swift

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -351,11 +351,15 @@ public typealias ExternalDependencyArtifactMap =
351351
let dependencyInfo = try dependencyGraph.moduleInfo(of: dependencyId)
352352

353353
let swiftModulePath: TypedVirtualPath
354+
let isFramework: Bool
354355
if case .swift(let details) = dependencyInfo.details,
355356
let compiledModulePath = details.explicitCompiledModulePath {
356357
// If an already-compiled module is available, use it.
357358
swiftModulePath = .init(file: try VirtualPath(path: compiledModulePath),
358359
type: .swiftModule)
360+
// Since this module has already been built, it is no longer relevant
361+
// whether it is a framework or not.
362+
isFramework = false
359363
} else {
360364
// Generate a build job for the dependency module, if not already generated
361365
if swiftModuleBuildCache[dependencyId] == nil {
@@ -364,13 +368,15 @@ public typealias ExternalDependencyArtifactMap =
364368
}
365369
swiftModulePath = .init(file: try VirtualPath(path: dependencyInfo.modulePath),
366370
type: .swiftModule)
371+
isFramework = try dependencyGraph.swiftModuleDetails(of: dependencyId).isFramework
367372
}
368373

369374
// Collect the required information about this module
370375
// TODO: add .swiftdoc and .swiftsourceinfo for this module.
371376
swiftDependencyArtifacts.append(
372377
SwiftModuleArtifactInfo(name: dependencyId.moduleName,
373-
modulePath: swiftModulePath.file.description))
378+
modulePath: swiftModulePath.file.description,
379+
isFramework: isFramework))
374380

375381
// Process all transitive dependencies as direct
376382
try addModuleDependencies(moduleId: dependencyId, pcmArgs: pcmArgs,

Sources/SwiftDriver/Explicit Module Builds/InterModuleDependencyGraph.swift

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -97,6 +97,9 @@ public struct SwiftModuleDetails: Codable {
9797
/// arguments to the generic PCM build arguments reported from the dependency
9898
/// graph.
9999
@_spi(Testing) public var extraPcmArgs: [String]?
100+
101+
/// A flag to indicate whether or not this module is a framework.
102+
@_spi(Testing) public var isFramework: Bool
100103
}
101104

102105
/// Details specific to Swift external modules.

Sources/SwiftDriver/Explicit Module Builds/ModuleArtifacts.swift

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,12 +25,16 @@ public struct SwiftModuleArtifactInfo: Codable {
2525
public let docPath: String?
2626
/// The path for the module's .swiftsourceinfo file
2727
public let sourceInfoPath: String?
28+
/// A flag to indicate whether this module is a framework
29+
public let isFramework: Bool
2830

29-
init(name: String, modulePath: String, docPath: String? = nil, sourceInfoPath: String? = nil) {
31+
init(name: String, modulePath: String, docPath: String? = nil,
32+
sourceInfoPath: String? = nil, isFramework: Bool = false) {
3033
self.moduleName = name
3134
self.modulePath = modulePath
3235
self.docPath = docPath
3336
self.sourceInfoPath = sourceInfoPath
37+
self.isFramework = isFramework
3438
}
3539
}
3640

Sources/SwiftDriver/Explicit Module Builds/PlaceholderDependencyResolution.swift

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -158,5 +158,6 @@ extension SwiftModuleDetails {
158158
self.bridgingSourceFiles = nil
159159
self.commandLine = nil
160160
self.extraPcmArgs = nil
161+
self.isFramework = false
161162
}
162163
}

Tests/SwiftDriverTests/ExplicitModuleBuildTests.swift

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -88,6 +88,7 @@ private func checkExplicitModuleBuildJobDependencies(job: Job,
8888
let dependencyArtifacts =
8989
dependencyInfoList.first(where:{ $0.moduleName == dependencyId.moduleName })
9090
XCTAssertEqual(dependencyArtifacts!.modulePath, swiftDetails.explicitCompiledModulePath ?? dependencyInfo.modulePath)
91+
XCTAssertEqual(dependencyArtifacts!.isFramework, swiftDetails.isFramework)
9192
case .clang(let clangDependencyDetails):
9293
let clangDependencyModulePathString =
9394
try ExplicitModuleBuildHandler.targetEncodedClangModuleFilePath(
@@ -368,13 +369,15 @@ final class ExplicitModuleBuildTests: XCTestCase {
368369
"moduleName": "A",
369370
"modulePath": "A.swiftmodule",
370371
"docPath": "A.swiftdoc",
371-
"sourceInfoPath": "A.swiftsourceinfo"
372+
"sourceInfoPath": "A.swiftsourceinfo",
373+
"isFramework": true
372374
},
373375
{
374376
"moduleName": "B",
375377
"modulePath": "B.swiftmodule",
376378
"docPath": "B.swiftdoc",
377-
"sourceInfoPath": "B.swiftsourceinfo"
379+
"sourceInfoPath": "B.swiftsourceinfo",
380+
"isFramework": false
378381
}
379382
]
380383
"""
@@ -385,9 +388,11 @@ final class ExplicitModuleBuildTests: XCTestCase {
385388
XCTAssertEqual(moduleMap[0].modulePath, "A.swiftmodule")
386389
XCTAssertEqual(moduleMap[0].docPath, "A.swiftdoc")
387390
XCTAssertEqual(moduleMap[0].sourceInfoPath, "A.swiftsourceinfo")
391+
XCTAssertEqual(moduleMap[0].isFramework, true)
388392
XCTAssertEqual(moduleMap[1].moduleName, "B")
389393
XCTAssertEqual(moduleMap[1].modulePath, "B.swiftmodule")
390394
XCTAssertEqual(moduleMap[1].docPath, "B.swiftdoc")
391395
XCTAssertEqual(moduleMap[1].sourceInfoPath, "B.swiftsourceinfo")
396+
XCTAssertEqual(moduleMap[1].isFramework, false)
392397
}
393398
}

Tests/SwiftDriverTests/Inputs/ExplicitModuleDependencyBuildInputs.swift

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@ enum ModuleDependenciesInputs {
3939
],
4040
"details": {
4141
"swift": {
42+
"isFramework": false,
4243
"extraPcmArgs": [
4344
"-Xcc",
4445
"-target",
@@ -123,6 +124,7 @@ enum ModuleDependenciesInputs {
123124
"-module-name",
124125
"Swift"
125126
],
127+
"isFramework": false,
126128
"extraPcmArgs": [
127129
"-Xcc",
128130
"-target",
@@ -187,6 +189,7 @@ enum ModuleDependenciesInputs {
187189
"-module-name",
188190
"SwiftOnoneSupport"
189191
],
192+
"isFramework": true,
190193
"extraPcmArgs": [
191194
"-Xcc",
192195
"-target",
@@ -270,6 +273,7 @@ enum ModuleDependenciesInputs {
270273
],
271274
"details": {
272275
"swift": {
276+
"isFramework": false,
273277
"extraPcmArgs": [
274278
"-Xcc",
275279
"-target",
@@ -316,6 +320,7 @@ enum ModuleDependenciesInputs {
316320
],
317321
"compiledModuleCandidates": [
318322
],
323+
"isFramework": false,
319324
"extraPcmArgs": [
320325
"-Xcc",
321326
"-target",
@@ -343,6 +348,7 @@ enum ModuleDependenciesInputs {
343348
"swift": {
344349
"moduleInterfacePath": "SwiftOnoneSupport.swiftmodule/x86_64-apple-macos.swiftinterface",
345350
"contextHash": "3GKS4RKE3GDZA",
351+
"isFramework": false,
346352
"commandLine": [
347353
"-frontend",
348354
"-compile-module-from-interface",
@@ -384,6 +390,7 @@ enum ModuleDependenciesInputs {
384390
],
385391
"details": {
386392
"swift": {
393+
"isFramework": false,
387394
"extraPcmArgs": [
388395
"-Xcc",
389396
"-target",
@@ -404,6 +411,7 @@ enum ModuleDependenciesInputs {
404411
],
405412
"details" : {
406413
"swift" : {
414+
"isFramework": false,
407415
"explicitCompiledModulePath" : "M/Swift.swiftmodule"
408416
}
409417
}
@@ -420,6 +428,7 @@ enum ModuleDependenciesInputs {
420428
],
421429
"details" : {
422430
"swift" : {
431+
"isFramework": false,
423432
"explicitCompiledModulePath" : "S/SwiftOnoneSupport.swiftmodule"
424433
}
425434
}

0 commit comments

Comments
 (0)