Skip to content

Commit 424a001

Browse files
authored
Merge pull request #1041 from nkcsgexi/hasprivate-interface
AdopterAnalysis: keep track of whether private interfaces are discovered
2 parents f6ea53e + 53550b2 commit 424a001

File tree

6 files changed

+32
-7
lines changed

6 files changed

+32
-7
lines changed

Sources/SwiftDriver/Jobs/PrebuiltModulesJob.swift

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -246,14 +246,16 @@ public class SwiftAdopter: Codable {
246246
public let name: String
247247
public let moduleDir: String
248248
public let hasInterface: Bool
249+
public let hasPrivateInterface: Bool
249250
public let hasModule: Bool
250251
public let isFramework: Bool
251252
public let isPrivate: Bool
252-
init(_ name: String, _ moduleDir: AbsolutePath, _ hasInterface: AbsolutePath?, _ hasModule: AbsolutePath?) {
253+
init(_ name: String, _ moduleDir: AbsolutePath, _ hasInterface: [AbsolutePath], _ hasModule: [AbsolutePath]) {
253254
self.name = name
254255
self.moduleDir = SwiftAdopter.relativeToSDK(moduleDir)
255-
self.hasInterface = hasInterface != nil
256-
self.hasModule = hasModule != nil
256+
self.hasInterface = !hasInterface.isEmpty
257+
self.hasPrivateInterface = hasInterface.contains { $0.basename.hasSuffix(".private.swiftinterface") }
258+
self.hasModule = !hasModule.isEmpty
257259
self.isFramework = self.moduleDir.contains("\(name).framework")
258260
self.isPrivate = self.moduleDir.contains("PrivateFrameworks")
259261
}
@@ -349,8 +351,8 @@ public struct SDKPrebuiltModuleInputsCollector {
349351
if results[moduleName] == nil {
350352
results[moduleName] = []
351353
}
352-
var hasInterface: AbsolutePath?
353-
var hasModule: AbsolutePath?
354+
var hasInterface: [AbsolutePath] = []
355+
var hasModule: [AbsolutePath] = []
354356
// Search inside a .swiftmodule directory for any .swiftinterface file, and
355357
// add the files into the dictionary.
356358
// Duplicate entries are discarded, otherwise llbuild will complain.
@@ -363,11 +365,11 @@ public struct SDKPrebuiltModuleInputsCollector {
363365
if !results[moduleName]!.contains(where: { $0.path.file.basenameWithoutExt == currentBaseName }) {
364366
results[moduleName]!.append(PrebuiltModuleInput(interfacePath))
365367
}
366-
hasInterface = currentFile
368+
hasInterface.append(currentFile)
367369
}
368370
if currentFile.extension == "swiftmodule" {
369371
diagEngine.emit(warning: "found \(currentFile)")
370-
hasModule = currentFile
372+
hasModule.append(currentFile)
371373
}
372374
}
373375
allSwiftAdopters.append(SwiftAdopter(moduleName, dir, hasInterface, hasModule))
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
// swift-interface-format-version: 1.0
2+
// swift-module-flags: -module-name E
3+
import Swift
4+
public func FuncE() { }
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
// swift-interface-format-version: 1.0
2+
// swift-module-flags: -module-name E
3+
import Swift
4+
public func FuncE() { }
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
// swift-interface-format-version: 1.0
2+
// swift-module-flags: -module-name E
3+
import Swift
4+
public func FuncE() { }
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
// swift-interface-format-version: 1.0
2+
// swift-module-flags: -module-name E
3+
import Swift
4+
public func FuncE() { }

Tests/SwiftDriverTests/ExplicitModuleBuildTests.swift

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1546,7 +1546,14 @@ final class ExplicitModuleBuildTests: XCTestCase {
15461546
XCTAssertFalse(A.isFramework)
15471547
XCTAssertFalse(A.isPrivate)
15481548
XCTAssertFalse(A.hasModule)
1549+
XCTAssertFalse(A.hasPrivateInterface)
15491550
XCTAssertTrue(A.hasInterface)
1551+
1552+
let B = adopters.first {$0.name == "B"}!
1553+
XCTAssertTrue(B.isFramework)
1554+
XCTAssertFalse(B.isPrivate)
1555+
XCTAssertFalse(B.hasModule)
1556+
XCTAssertTrue(B.hasPrivateInterface)
15501557
}
15511558
#endif
15521559
}

0 commit comments

Comments
 (0)