Skip to content

Commit ab90dce

Browse files
committed
Fix experimental-api-diff command
1 parent 86e4882 commit ab90dce

File tree

5 files changed

+35
-6
lines changed

5 files changed

+35
-6
lines changed

Sources/Build/BuildPlan.swift

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1853,11 +1853,22 @@ public class BuildPlan {
18531853
}
18541854
}
18551855

1856-
public func createAPIDigesterArgs() -> [String] {
1856+
public func createAPIToolCommonArgs(includeLibrarySearchPaths: Bool) -> [String] {
18571857
let buildPath = buildParameters.buildPath.pathString
18581858
var arguments = ["-I", buildPath]
18591859

1860-
arguments += buildParameters.toolchain.extraSwiftCFlags
1860+
var extraSwiftCFlags = buildParameters.toolchain.extraSwiftCFlags
1861+
if !includeLibrarySearchPaths {
1862+
for index in extraSwiftCFlags.indices.dropLast().reversed() {
1863+
if extraSwiftCFlags[index] == "-L" {
1864+
// Remove the flag
1865+
extraSwiftCFlags.remove(at: index)
1866+
// Remove the argument
1867+
extraSwiftCFlags.remove(at: index)
1868+
}
1869+
}
1870+
}
1871+
arguments += extraSwiftCFlags
18611872

18621873
// Add the search path to the directory containing the modulemap file.
18631874
for target in targets {

Sources/Commands/APIDigester.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -125,7 +125,7 @@ struct APIDigesterBaselineDumper {
125125
try apiDigesterTool.dumpSDKJSON(
126126
at: sdkJSON,
127127
modules: graph.apiDigesterModules,
128-
additionalArgs: buildOp.buildPlan!.createAPIDigesterArgs()
128+
additionalArgs: buildOp.buildPlan!.createAPIToolCommonArgs(includeLibrarySearchPaths: false)
129129
)
130130

131131
return sdkJSON

Sources/Commands/SwiftPackageTool.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -311,7 +311,7 @@ extension SwiftPackageTool {
311311
try apiDigesterTool.dumpSDKJSON(
312312
at: currentSDKJSON,
313313
modules: packageGraph.apiDigesterModules,
314-
additionalArgs: buildOp.buildPlan!.createAPIDigesterArgs()
314+
additionalArgs: buildOp.buildPlan!.createAPIToolCommonArgs(includeLibrarySearchPaths: false)
315315
)
316316

317317
// Dump JSON for the baseline package.

Sources/Commands/SymbolGraphExtract.swift

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -42,8 +42,7 @@ public struct SymbolGraphExtract {
4242
args += ["-module-name", target.c99name]
4343
args += buildParameters.targetTripleArgs(for: target)
4444

45-
// FIXME: We should rename this to common Swift tools args or something.
46-
args += buildPlan.createAPIDigesterArgs()
45+
args += buildPlan.createAPIToolCommonArgs(includeLibrarySearchPaths: true)
4746
args += ["-module-cache-path", buildParameters.moduleCache.pathString]
4847

4948
args += ["-output-dir", symbolGraphDirectory.pathString]

Tests/CommandsTests/PackageToolTests.swift

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -982,6 +982,25 @@ final class PackageToolTests: XCTestCase {
982982
#endif
983983
}
984984

985+
func testAPIDiff() throws {
986+
#if os(macOS)
987+
guard (try? Resources.default.toolchain.getSwiftAPIDigester()) != nil else {
988+
throw XCTSkip("swift-api-digester not available")
989+
}
990+
fixture(name: "DependencyResolution/External/Simple") { prefix in
991+
let packageRoot = prefix.appending(component: "Foo")
992+
// Overwrite the existing decl.
993+
try localFileSystem.writeFileContents(packageRoot.appending(component: "Foo.swift")) {
994+
$0 <<< "public let foo = 42"
995+
}
996+
let (_, stderr) = try execute(["experimental-api-diff", "1.2.3"], packagePath: packageRoot)
997+
XCTAssertTrue(stderr.contains("Func foo() has been removed"))
998+
}
999+
#else
1000+
throw XCTSkip("Test unsupported on current platform")
1001+
#endif
1002+
}
1003+
9851004
func testArchiveSource() throws {
9861005
fixture(name: "DependencyResolution/External/Simple") { prefix in
9871006
let packageRoot = prefix.appending(component: "Bar")

0 commit comments

Comments
 (0)