Skip to content

Commit 3bbb8a5

Browse files
authored
Merge pull request #325 from nkcsgexi/70562001
Teach swift-driver to emit private interfaces
2 parents 9847c48 + 79db746 commit 3bbb8a5

File tree

4 files changed

+24
-3
lines changed

4 files changed

+24
-3
lines changed

Sources/SwiftDriver/Driver/Driver.swift

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -239,6 +239,9 @@ public struct Driver {
239239
/// Path to the Swift interface file.
240240
let swiftInterfacePath: VirtualPath?
241241

242+
/// Path to the Swift private interface file.
243+
let swiftPrivateInterfacePath: VirtualPath?
244+
242245
/// Path to the optimization record.
243246
let optimizationRecordPath: VirtualPath?
244247

@@ -521,6 +524,14 @@ public struct Driver {
521524
outputFileMap: self.outputFileMap,
522525
moduleName: moduleOutputInfo.name)
523526

527+
self.swiftPrivateInterfacePath = try Self.computeSupplementaryOutputPath(
528+
&parsedOptions, type: .privateSwiftInterface, isOutputOptions: [],
529+
outputPath: .emitPrivateModuleInterfacePath,
530+
compilerOutputType: compilerOutputType,
531+
compilerMode: compilerMode,
532+
outputFileMap: self.outputFileMap,
533+
moduleName: moduleOutputInfo.name)
534+
524535
var optimizationRecordFileType = FileType.yamlOptimizationRecord
525536
if let argument = parsedOptions.getLastArgument(.saveOptimizationRecordEQ)?.asSingle {
526537
switch argument {
@@ -1576,7 +1587,8 @@ extension Driver {
15761587
moduleOutputKind = .auxiliary
15771588
} else if compilerMode != .singleCompile &&
15781589
parsedOptions.hasArgument(.emitObjcHeader, .emitObjcHeaderPath,
1579-
.emitModuleInterface, .emitModuleInterfacePath) {
1590+
.emitModuleInterface, .emitModuleInterfacePath,
1591+
.emitPrivateModuleInterfacePath) {
15801592
// An option has been passed which requires whole-module knowledge, but we
15811593
// don't have that. Generate a module, but treat it as an intermediate
15821594
// output.

Sources/SwiftDriver/Jobs/EmitModuleJob.swift

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ extension Driver {
2929
addSupplementalOutput(path: moduleDocOutputPath, flag: "-emit-module-doc-path", type: .swiftDocumentation)
3030
addSupplementalOutput(path: moduleSourceInfoPath, flag: "-emit-module-source-info-path", type: .swiftSourceInfoFile)
3131
addSupplementalOutput(path: swiftInterfacePath, flag: "-emit-module-interface-path", type: .swiftInterface)
32+
addSupplementalOutput(path: swiftPrivateInterfacePath, flag: "-emit-private-module-interface-path", type: .privateSwiftInterface)
3233
addSupplementalOutput(path: objcGeneratedHeaderPath, flag: "-emit-objc-header-path", type: .objcHeader)
3334
addSupplementalOutput(path: tbdPath, flag: "-emit-tbd-path", type: .tbd)
3435

Sources/SwiftDriver/Jobs/FrontendJobHelpers.swift

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -362,6 +362,12 @@ extension Driver {
362362
input: nil,
363363
flag: "-emit-module-interface-path")
364364

365+
addOutputOfType(
366+
outputType: .privateSwiftInterface,
367+
finalOutputPath: swiftPrivateInterfacePath,
368+
input: nil,
369+
flag: "-emit-private-module-interface-path")
370+
365371
addOutputOfType(
366372
outputType: .tbd,
367373
finalOutputPath: tbdPath,

Tests/SwiftDriverTests/SwiftDriverTests.swift

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1376,16 +1376,18 @@ final class SwiftDriverTests: XCTestCase {
13761376
}
13771377

13781378
func testSingleThreadedWholeModuleOptimizationCompiles() throws {
1379-
var driver1 = try Driver(args: ["swiftc", "-whole-module-optimization", "foo.swift", "bar.swift", "-module-name", "Test", "-target", "x86_64-apple-macosx10.15", "-emit-module-interface", "-emit-objc-header-path", "Test-Swift.h"])
1379+
var driver1 = try Driver(args: ["swiftc", "-whole-module-optimization", "foo.swift", "bar.swift", "-module-name", "Test", "-target", "x86_64-apple-macosx10.15", "-emit-module-interface", "-emit-objc-header-path", "Test-Swift.h", "-emit-private-module-interface-path", "Test.private.swiftinterface"])
13801380
let plannedJobs = try driver1.planBuild()
13811381
XCTAssertEqual(plannedJobs.count, 2)
13821382
XCTAssertEqual(plannedJobs[0].kind, .compile)
1383-
XCTAssertEqual(plannedJobs[0].outputs.count, 3)
1383+
XCTAssertEqual(plannedJobs[0].outputs.count, 4)
13841384
XCTAssertEqual(plannedJobs[0].outputs[0].file, VirtualPath.temporary(RelativePath("Test.o")))
13851385
XCTAssertEqual(plannedJobs[0].outputs[1].file, VirtualPath.relative(RelativePath("Test-Swift.h")))
13861386
XCTAssertEqual(plannedJobs[0].outputs[2].file, VirtualPath.relative(RelativePath("Test.swiftinterface")))
1387+
XCTAssertEqual(plannedJobs[0].outputs[3].file, VirtualPath.relative(RelativePath("Test.private.swiftinterface")))
13871388
XCTAssert(!plannedJobs[0].commandLine.contains(.flag("-primary-file")))
13881389
XCTAssert(plannedJobs[0].commandLine.contains(.flag("-emit-module-interface-path")))
1390+
XCTAssert(plannedJobs[0].commandLine.contains(.flag("-emit-private-module-interface-path")))
13891391

13901392
XCTAssertEqual(plannedJobs[1].kind, .link)
13911393
}

0 commit comments

Comments
 (0)