Skip to content

ABIChecking: use the always-generated-abi-descriptor to diagnose ABI breakages #885

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Oct 27, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 12 additions & 1 deletion Sources/SwiftDriver/Driver/Driver.swift
Original file line number Diff line number Diff line change
Expand Up @@ -356,6 +356,17 @@ public struct Driver {
.appending(component: "Frameworks")
} ()

lazy var abiDescriptorPath: TypedVirtualPath? = {
guard isFeatureSupported(.emit_abi_descriptor) else {
return nil
}
guard let moduleOutput = moduleOutputInfo.output else {
return nil
}
return TypedVirtualPath(file: VirtualPath.lookup(moduleOutput.outputPath)
.replacingExtension(with: .jsonABIBaseline).intern(), type: .jsonABIBaseline)
}()

public func isFrontendArgSupported(_ opt: Option) -> Bool {
var current = opt.spelling
while(true) {
Expand Down Expand Up @@ -694,6 +705,7 @@ public struct Driver {
compilerMode: compilerMode,
outputFileMap: self.outputFileMap,
moduleName: moduleOutputInfo.name)

let projectDirectory = Self.computeProjectDirectoryPath(
moduleOutputPath: self.moduleOutputInfo.output?.outputPath,
fileSystem: self.fileSystem)
Expand Down Expand Up @@ -721,7 +733,6 @@ public struct Driver {
compilerMode: compilerMode,
outputFileMap: self.outputFileMap,
moduleName: moduleOutputInfo.name)

self.swiftPrivateInterfacePath = try Self.computeSupplementaryOutputPath(
&parsedOptions, type: .privateSwiftInterface, isOutputOptions: [],
outputPath: .emitPrivateModuleInterfacePath,
Expand Down
44 changes: 44 additions & 0 deletions Sources/SwiftDriver/Jobs/APIDigesterJobs.swift
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,50 @@ extension Driver {
)
}

mutating func digesterDiagnosticsJob(modulePath: VirtualPath.Handle, baselinePath:
VirtualPath.Handle, mode: DigesterMode) throws -> Job {
func getDescriptorPath(for mode: DigesterMode) -> TypedVirtualPath? {
switch mode {
case .api:
return nil
case .abi:
return abiDescriptorPath
}
}
guard let currentABI = getDescriptorPath(for: mode) else {
// we don't have existing descriptor to use so we have to load the module from interface/swiftmodule
return try digesterCompareToBaselineJob(modulePath: modulePath, baselinePath: baselinePath, mode: digesterMode)
}
var commandLine = [Job.ArgTemplate]()
commandLine.appendFlag("-diagnose-sdk")
commandLine.appendFlag("-input-paths")
commandLine.appendPath(VirtualPath.lookup(baselinePath))
commandLine.appendFlag("-input-paths")
commandLine.appendPath(currentABI.file)
if mode == .abi {
commandLine.appendFlag("-abi")
}
if let arg = parsedOptions.getLastArgument(.digesterBreakageAllowlistPath)?.asSingle {
let path = try VirtualPath(path: arg)
commandLine.appendFlag("-breakage-allowlist-path")
commandLine.appendPath(path)
}
commandLine.appendFlag("-serialize-diagnostics-path")
let diag = TypedVirtualPath(file: currentABI.file.parentDirectory.appending(component: currentABI.file.basename + ".dia").intern(), type: .diagnostics)
commandLine.appendPath(diag.file)
let inputs: [TypedVirtualPath] = [currentABI]
return Job(
moduleName: moduleOutputInfo.name,
kind: .compareABIBaseline,
tool: .absolute(try toolchain.getToolPath(.swiftAPIDigester)),
commandLine: commandLine,
inputs: inputs,
primaryInputs: [],
outputs: [diag],
supportsResponseFiles: true
)
}

mutating func digesterCompareToBaselineJob(modulePath: VirtualPath.Handle, baselinePath: VirtualPath.Handle, mode: DigesterMode) throws -> Job {
var commandLine = [Job.ArgTemplate]()
commandLine.appendFlag("-diagnose-sdk")
Expand Down
7 changes: 3 additions & 4 deletions Sources/SwiftDriver/Jobs/EmitModuleJob.swift
Original file line number Diff line number Diff line change
Expand Up @@ -92,11 +92,10 @@ extension Driver {
let outputPath = VirtualPath.lookup(moduleOutputPath)
commandLine.appendFlag(.o)
commandLine.appendPath(outputPath)
if isFeatureSupported(.emit_abi_descriptor) {
if let abiPath = abiDescriptorPath {
commandLine.appendFlag(.emitAbiDescriptorPath)
let abiOutput = outputPath.replacingExtension(with: .jsonABIBaseline)
commandLine.appendPath(abiOutput)
outputs.append(TypedVirtualPath(file: abiOutput.intern(), type: .jsonABIBaseline))
commandLine.appendPath(abiPath.file)
outputs.append(abiPath)
}
return Job(
moduleName: moduleOutputInfo.name,
Expand Down
2 changes: 1 addition & 1 deletion Sources/SwiftDriver/Jobs/Job.swift
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ public struct Job: Codable, Equatable, Hashable {
case generateAPIBaseline = "generate-api-baseline"
case generateABIBaseline = "generate-abi-baseline"
case compareAPIBaseline = "compare-api-baseline"
case compareABIBaseline = "compare-abi-baseline"
case compareABIBaseline = "Check ABI stability"
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: this seems to now stand out from the surrounding raw value style, what's the reason for this change?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This shows up in the build log in a way that's quite different from other task descriptions. We may look into updating other raw values as well.

}

public enum ArgTemplate: Equatable, Hashable {
Expand Down
7 changes: 3 additions & 4 deletions Sources/SwiftDriver/Jobs/MergeModuleJob.swift
Original file line number Diff line number Diff line change
Expand Up @@ -76,11 +76,10 @@ extension Driver {
commandLine.appendFlag(.o)
commandLine.appendPath(outputPath)

if isFeatureSupported(.emit_abi_descriptor) {
if let abiPath = abiDescriptorPath {
commandLine.appendFlag(.emitAbiDescriptorPath)
let abiOutput = outputPath.replacingExtension(with: .jsonABIBaseline)
commandLine.appendPath(abiOutput)
outputs.append(TypedVirtualPath(file: abiOutput.intern(), type: .jsonABIBaseline))
commandLine.appendPath(abiPath.file)
outputs.append(abiPath)
}
return Job(
moduleName: moduleOutputInfo.name,
Expand Down
2 changes: 1 addition & 1 deletion Sources/SwiftDriver/Jobs/Planning.swift
Original file line number Diff line number Diff line change
Expand Up @@ -510,7 +510,7 @@ extension Driver {
}
if let baselineArg = parsedOptions.getLastArgument(.compareToBaselinePath)?.asSingle,
let baselinePath = try? VirtualPath.intern(path: baselineArg) {
addJob(try digesterCompareToBaselineJob(modulePath: moduleOutputPath, baselinePath: baselinePath, mode: digesterMode))
addJob(try digesterDiagnosticsJob(modulePath: moduleOutputPath, baselinePath: baselinePath, mode: digesterMode))
}
}

Expand Down
11 changes: 2 additions & 9 deletions Tests/SwiftDriverTests/APIDigesterTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -252,18 +252,11 @@ class APIDigesterTests: XCTestCase {
"-digester-breakage-allowlist-path", "allowlist/path"])
let digesterJob = try XCTUnwrap(driver.planBuild().first { $0.kind == .compareABIBaseline })
XCTAssertTrue(digesterJob.commandLine.contains("-diagnose-sdk"))
XCTAssertTrue(digesterJob.commandLine.contains(subsequence: ["-module", "foo"]))
XCTAssertTrue(digesterJob.commandLine.contains(subsequence: ["-baseline-path", .path(.absolute(.init("/baseline/path")))]))
XCTAssertTrue(digesterJob.commandLine.contains(subsequence: ["-I", .path(.relative(.init(".")))]))
XCTAssertTrue(digesterJob.commandLine.contains(subsequence: ["-sdk", .path(.absolute(.init("/path/to/sdk")))]))
XCTAssertTrue(digesterJob.commandLine.contains(subsequence: ["-I", .path(.absolute(.init("/some/path")))]))
XCTAssertTrue(digesterJob.commandLine.contains(subsequence: ["-F", .path(.relative(.init("framework/path")))]))
XCTAssertTrue(digesterJob.commandLine.contains(subsequence: ["-serialize-diagnostics-path",
.path(.relative(.init("breaking-changes.dia")))]))
XCTAssertTrue(digesterJob.commandLine.contains(subsequence: ["-input-paths", .path(.absolute(.init("/baseline/path")))]))
XCTAssertTrue(digesterJob.commandLine.contains(subsequence: ["-breakage-allowlist-path",
.path(.relative(.init("allowlist/path")))]))

XCTAssertTrue(digesterJob.commandLine.contains("-abi"))
XCTAssertTrue(digesterJob.commandLine.contains("-serialize-diagnostics-path"))
}
}

Expand Down