Skip to content

Commit 38078ac

Browse files
committed
PrebuiltModuleGen: add additional framework search paths
1 parent 2ed97d4 commit 38078ac

File tree

7 files changed

+71
-4
lines changed

7 files changed

+71
-4
lines changed

Sources/SwiftDriver/Driver/Driver.swift

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -349,13 +349,20 @@ public struct Driver {
349349
return VirtualPath.lookup(rawSdkPath)
350350
} ()
351351

352-
lazy var iosMacFrameworksSearchPath: VirtualPath = {
352+
lazy var iosMacFrameworksBase: VirtualPath = {
353353
sdkPath!
354354
.appending(component: "System")
355355
.appending(component: "iOSSupport")
356356
.appending(component: "System")
357357
.appending(component: "Library")
358-
.appending(component: "Frameworks")
358+
} ()
359+
360+
lazy var iosMacFrameworksSearchPath: VirtualPath = {
361+
iosMacFrameworksBase.appending(component: "Frameworks")
362+
} ()
363+
364+
lazy var iosMacPrivateFrameworksSearchPath: VirtualPath = {
365+
iosMacFrameworksBase.appending(component: "PrivateFrameworks")
359366
} ()
360367

361368
lazy var abiDescriptorPath: TypedVirtualPath? = {

Sources/SwiftDriver/Jobs/PrebuiltModulesJob.swift

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -248,7 +248,9 @@ public struct SDKPrebuiltModuleInputsCollector {
248248
let nonFrameworkDirs = [RelativePath("usr/lib/swift"),
249249
RelativePath("System/iOSSupport/usr/lib/swift")]
250250
let frameworkDirs = [RelativePath("System/Library/Frameworks"),
251-
RelativePath("System/iOSSupport/System/Library/Frameworks")]
251+
RelativePath("System/Library/PrivateFrameworks"),
252+
RelativePath("System/iOSSupport/System/Library/Frameworks"),
253+
RelativePath("System/iOSSupport/System/Library/PrivateFrameworks")]
252254
let sdkInfo: DarwinToolchain.DarwinSDKInfo
253255
let diagEngine: DiagnosticsEngine
254256
public init(_ sdkPath: AbsolutePath, _ diagEngine: DiagnosticsEngine) {
@@ -448,10 +450,12 @@ extension Driver {
448450
_ dependencies: [TypedVirtualPath], _ currentABIDir: AbsolutePath?,
449451
_ baselineABIDir: AbsolutePath?) throws -> [Job] {
450452
assert(inputPath.path.file.basenameWithoutExt == outputPath.path.file.basenameWithoutExt)
453+
let sdkPath = sdkPath!
454+
let isInternal = sdkPath.basename.hasSuffix(".Internal.sdk")
451455
var commandLine: [Job.ArgTemplate] = []
452456
commandLine.appendFlag(.compileModuleFromInterface)
453457
commandLine.appendFlag(.sdk)
454-
commandLine.append(.path(sdkPath!))
458+
commandLine.append(.path(sdkPath))
455459
commandLine.appendFlag(.prebuiltModuleCachePath)
456460
commandLine.appendPath(prebuiltModuleDir)
457461
commandLine.appendFlag(.moduleName)
@@ -467,6 +471,16 @@ extension Driver {
467471
if try isIosMacInterface(inputPath.path.file) {
468472
commandLine.appendFlag(.Fsystem)
469473
commandLine.append(.path(iosMacFrameworksSearchPath))
474+
if isInternal {
475+
commandLine.appendFlag(.Fsystem)
476+
commandLine.append(.path(iosMacPrivateFrameworksSearchPath))
477+
}
478+
}
479+
if isInternal {
480+
commandLine.appendFlag(.Fsystem)
481+
commandLine.append(.path(sdkPath.appending(component: "System")
482+
.appending(component: "Library")
483+
.appending(component: "PrivateFrameworks")))
470484
}
471485
// Use the specified module cache dir
472486
if let mcp = parsedOptions.getLastArgument(.moduleCachePath)?.asSingle {
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
{
2+
"Version": "10.15",
3+
"VersionMap": {
4+
"macOS_iOSMac": {},
5+
"iOSMac_macOS": {}
6+
},
7+
"CanonicalName": "macosx10.15"
8+
}
Lines changed: 4 additions & 0 deletions
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 A
3+
import Swift
4+
public func FuncA() { }
Lines changed: 4 additions & 0 deletions
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 A
3+
import Swift
4+
public func FuncA() { }
Lines changed: 4 additions & 0 deletions
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 A
3+
import Swift
4+
public func FuncA() { }

Tests/SwiftDriverTests/ExplicitModuleBuildTests.swift

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1510,5 +1510,31 @@ final class ExplicitModuleBuildTests: XCTestCase {
15101510
try abiCheckJobs.forEach { try checkABICheckingJob($0) }
15111511
}
15121512
}
1513+
func testPrebuiltModuleIntenralSDK() throws {
1514+
let mockSDKPath = testInputsPath.appending(component: "mock-sdk.Internal.sdk")
1515+
let mockSDKPathStr: String = mockSDKPath.pathString
1516+
let collector = try SDKPrebuiltModuleInputsCollector(VirtualPath(path: mockSDKPathStr).absolutePath!, DiagnosticsEngine())
1517+
let interfaceMap = try collector.collectSwiftInterfaceMap()
1518+
try withTemporaryDirectory { path in
1519+
let main = path.appending(component: "testPrebuiltModuleGenerationJobs.swift")
1520+
try localFileSystem.writeFileContents(main) {
1521+
$0 <<< "import A\n"
1522+
}
1523+
let moduleCachePath = "/tmp/module-cache"
1524+
var driver = try Driver(args: ["swiftc", main.pathString,
1525+
"-sdk", mockSDKPathStr,
1526+
"-module-cache-path", moduleCachePath
1527+
])
1528+
let (jobs, _) = try driver.generatePrebuitModuleGenerationJobs(with: interfaceMap,
1529+
into: path,
1530+
exhaustive: true)
1531+
let compileJobs = jobs.filter {$0.kind == .compile}
1532+
XCTAssertTrue(!compileJobs.isEmpty)
1533+
XCTAssertTrue(compileJobs.allSatisfy { $0.commandLine.contains(.flag("-suppress-warnings")) })
1534+
let PFPath = mockSDKPath.appending(component: "System").appending(component: "Library")
1535+
.appending(component: "PrivateFrameworks")
1536+
XCTAssertTrue(compileJobs.allSatisfy { $0.commandLine.contains(.path(VirtualPath.absolute(PFPath))) })
1537+
}
1538+
}
15131539
#endif
15141540
}

0 commit comments

Comments
 (0)