Skip to content

Commit 6206c02

Browse files
committed
Infer baseline output paths from swiftsourceinfo output file map entries
1 parent eac3fd5 commit 6206c02

File tree

2 files changed

+55
-0
lines changed

2 files changed

+55
-0
lines changed

Sources/SwiftDriver/Driver/OutputFileMap.swift

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,13 @@ public struct OutputFileMap: Hashable, Codable {
5454
}
5555
return VirtualPath.lookup(path).replacingExtension(with: outputType).intern()
5656

57+
case .jsonAPIBaseline, .jsonABIBaseline:
58+
// Infer paths for these entities using .swiftsourceinfo path.
59+
guard let path = entries[inputFile]?[.swiftSourceInfoFile] else {
60+
return nil
61+
}
62+
return VirtualPath.lookup(path).replacingExtension(with: outputType).intern()
63+
5764
case .object:
5865
// We may generate .o files from bitcode .bc files, but the output file map
5966
// uses .swift file as the key for .o file paths. So we need to dig further.

Tests/SwiftDriverTests/APIDigesterTests.swift

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -92,6 +92,54 @@ class APIDigesterTests: XCTestCase {
9292
XCTAssertTrue(digesterJob.commandLine.contains(subsequence: ["-o", .path(.absolute(projectDirPath.appending(component: "foo.abi.json")))]))
9393
}
9494
}
95+
do {
96+
try withTemporaryDirectory { path in
97+
let ofmPath = path.appending(component: "ofm.json")
98+
try localFileSystem.writeFileContents(ofmPath) {
99+
$0 <<< """
100+
{
101+
"": {
102+
"abi-baseline-json": "/path/to/baseline.abi.json"
103+
}
104+
}
105+
"""
106+
}
107+
var driver = try Driver(args: ["swiftc", "-wmo", "-emit-module",
108+
"-emit-module-interface", "-enable-library-evolution",
109+
path.appending(component: "foo.swift").pathString,
110+
"-emit-digester-baseline",
111+
"-digester-mode", "abi",
112+
"-o", path.appending(component: "foo.swiftmodule").pathString,
113+
"-output-file-map", ofmPath.pathString,
114+
])
115+
let digesterJob = try XCTUnwrap(driver.planBuild().first { $0.kind == .generateABIBaseline })
116+
XCTAssertTrue(digesterJob.commandLine.contains(subsequence: ["-o", .path(.absolute(.init("/path/to/baseline.abi.json")))]))
117+
}
118+
}
119+
do {
120+
try withTemporaryDirectory { path in
121+
let ofmPath = path.appending(component: "ofm.json")
122+
try localFileSystem.writeFileContents(ofmPath) {
123+
$0 <<< """
124+
{
125+
"": {
126+
"swiftsourceinfo": "/path/to/sourceinfo"
127+
}
128+
}
129+
"""
130+
}
131+
var driver = try Driver(args: ["swiftc", "-wmo", "-emit-module",
132+
"-emit-module-interface", "-enable-library-evolution",
133+
path.appending(component: "foo.swift").pathString,
134+
"-emit-digester-baseline",
135+
"-digester-mode", "abi",
136+
"-o", path.appending(component: "foo.swiftmodule").pathString,
137+
"-output-file-map", ofmPath.pathString,
138+
])
139+
let digesterJob = try XCTUnwrap(driver.planBuild().first { $0.kind == .generateABIBaseline })
140+
XCTAssertTrue(digesterJob.commandLine.contains(subsequence: ["-o", .path(.absolute(.init("/path/to/sourceinfo.abi.json")))]))
141+
}
142+
}
95143
}
96144

97145
func testBaselineGenerationJobFlags() throws {

0 commit comments

Comments
 (0)