Skip to content

Commit 70f502b

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 0a5cd34 commit 70f502b

File tree

5 files changed

+23
-4
lines changed

5 files changed

+23
-4
lines changed

Sources/SwiftDriver/Explicit Module Builds/ExplicitModuleBuildHandler.swift

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

344344
let swiftModulePath: TypedVirtualPath
345+
let isFramework: Bool
345346
if case .swift(let details) = dependencyInfo.details,
346347
let compiledModulePath = details.explicitCompiledModulePath {
347348
// If an already-compiled module is available, use it.
348349
swiftModulePath = .init(file: try VirtualPath(path: compiledModulePath),
349350
type: .swiftModule)
351+
// Since this module has already been built, it is no longer relevant
352+
// whether it is a framework or not.
353+
isFramework = false
350354
} else {
351355
// Generate a build job for the dependency module, if not already generated
352356
if swiftModuleBuildCache[dependencyId] == nil {
@@ -355,13 +359,15 @@ public typealias ExternalDependencyArtifactMap =
355359
}
356360
swiftModulePath = .init(file: try VirtualPath(path: dependencyInfo.modulePath),
357361
type: .swiftModule)
362+
isFramework = try dependencyGraph.swiftModuleDetails(of: dependencyId).isFramework
358363
}
359364

360365
// Collect the required information about this module
361366
// TODO: add .swiftdoc and .swiftsourceinfo for this module.
362367
swiftDependencyArtifacts.append(
363368
SwiftModuleArtifactInfo(name: dependencyId.moduleName,
364-
modulePath: swiftModulePath.file.description))
369+
modulePath: swiftModulePath.file.description,
370+
isFramework: isFramework))
365371

366372
// Process all transitive dependencies as direct
367373
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
@@ -167,5 +167,6 @@ private extension SwiftModuleDetails {
167167
self.bridgingSourceFiles = nil
168168
self.commandLine = nil
169169
self.extraPcmArgs = extraPcmArgs
170+
self.isFramework = false
170171
}
171172
}

Tests/SwiftDriverTests/ExplicitModuleBuildTests.swift

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -90,6 +90,7 @@ private func checkExplicitModuleBuildJobDependencies(job: Job,
9090
let dependencyArtifacts =
9191
dependencyInfoList.first(where:{ $0.moduleName == dependencyId.moduleName })
9292
XCTAssertEqual(dependencyArtifacts!.modulePath, swiftDetails.explicitCompiledModulePath ?? dependencyInfo.modulePath)
93+
XCTAssertEqual(dependencyArtifacts!.isFramework, swiftDetails.isFramework)
9394
case .clang(let clangDependencyDetails):
9495
let clangDependencyModulePathString =
9596
try ExplicitModuleBuildHandler.targetEncodedClangModuleFilePath(
@@ -386,13 +387,15 @@ final class ExplicitModuleBuildTests: XCTestCase {
386387
"moduleName": "A",
387388
"modulePath": "A.swiftmodule",
388389
"docPath": "A.swiftdoc",
389-
"sourceInfoPath": "A.swiftsourceinfo"
390+
"sourceInfoPath": "A.swiftsourceinfo",
391+
"isFramework": true
390392
},
391393
{
392394
"moduleName": "B",
393395
"modulePath": "B.swiftmodule",
394396
"docPath": "B.swiftdoc",
395-
"sourceInfoPath": "B.swiftsourceinfo"
397+
"sourceInfoPath": "B.swiftsourceinfo",
398+
"isFramework": false
396399
}
397400
]
398401
"""
@@ -403,9 +406,11 @@ final class ExplicitModuleBuildTests: XCTestCase {
403406
XCTAssertEqual(moduleMap[0].modulePath, "A.swiftmodule")
404407
XCTAssertEqual(moduleMap[0].docPath, "A.swiftdoc")
405408
XCTAssertEqual(moduleMap[0].sourceInfoPath, "A.swiftsourceinfo")
409+
XCTAssertEqual(moduleMap[0].isFramework, true)
406410
XCTAssertEqual(moduleMap[1].moduleName, "B")
407411
XCTAssertEqual(moduleMap[1].modulePath, "B.swiftmodule")
408412
XCTAssertEqual(moduleMap[1].docPath, "B.swiftdoc")
409413
XCTAssertEqual(moduleMap[1].sourceInfoPath, "B.swiftsourceinfo")
414+
XCTAssertEqual(moduleMap[1].isFramework, false)
410415
}
411416
}

0 commit comments

Comments
 (0)