Skip to content

Implement diagnose-api-breaking-changes support with --build-system swiftbuild #8857

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
Jul 2, 2025

Conversation

owenv
Copy link
Contributor

@owenv owenv commented Jun 22, 2025

depends on swiftlang/swift-build#601
closes #8847

Swift Build has builtin support for generating and comparing to API/ABI baselines. Wire this up to the diagnose-api-breaking-changes command. Notably, we now have a mechanism for running a Swift Build based build and collecting serialized diagnostics, which should be reusable in the implementation of the migrate command.

@owenv
Copy link
Contributor Author

owenv commented Jun 23, 2025

@swift-ci test

// The opt-in/opt-out mechanism doesn't seem to be used.
// It is kept around for abundance of caution. If "why is it needed"
// not identified by March 2025, then it is OK to remove it.
try XCTSkipIf(
Copy link
Contributor

Choose a reason for hiding this comment

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

issue (possibly-blocking): The converted test does not appear to add support for skipping tests if SWIFTPM_TEST_API_DIFF_OUTPUT environment is set to 0. Do we still need to support this?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I'm fairly confident this was only needed several years ago before we had a fully featured api digester tool available everywhere

Copy link
Contributor

Choose a reason for hiding this comment

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

This was added by @yyvch about 5 months ago in #8196

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Before then these tests were skipped entirely for many years, I believe unnecessarily, so I don't think we need this control any longer

}
}

private func generateAPIBaselineUsingIntegratedAPIDigesterSupport(_ swiftCommandState: SwiftCommandState, baselineRevision: Revision, baselineDir: Basics.AbsolutePath, modulesNeedingBaselines: Set<String>) async throws -> Set<String> {
Copy link
Contributor

Choose a reason for hiding this comment

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

suggestion: Consider created automated tests that validate this function in isolation with happy path, and also fault injection, and more.

@@ -173,39 +194,180 @@ struct APIDiff: AsyncSwiftCommand {
}
}

private func determineModulesToDiff(packageGraph: ModulesGraph, observabilityScope: ObservabilityScope) throws -> Set<String> {
private func runWithIntegratedAPIDigesterSupport(_ swiftCommandState: SwiftCommandState, baselineRevision: Revision, baselineDir: Basics.AbsolutePath, modulesToDiff: Set<String>) async throws {
Copy link
Contributor

Choose a reason for hiding this comment

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

suggestion: Consider created automated tests that validate this function in isolation with happy path, and also fault injection, and more.

}
}

private func generateAPIBaselineUsingIntegratedAPIDigesterSupport(_ swiftCommandState: SwiftCommandState, baselineRevision: Revision, baselineDir: Basics.AbsolutePath, modulesNeedingBaselines: Set<String>) async throws -> Set<String> {
Copy link
Contributor

Choose a reason for hiding this comment

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

suggestion: consider type aliasing, or creating more specific type, for the return value to aid in code readability. For example, instead of String, create a type alias which represents what the string is. e.g.: typealias ModuleName = String

@@ -173,39 +194,180 @@ struct APIDiff: AsyncSwiftCommand {
}
}

private func determineModulesToDiff(packageGraph: ModulesGraph, observabilityScope: ObservabilityScope) throws -> Set<String> {
private func runWithIntegratedAPIDigesterSupport(_ swiftCommandState: SwiftCommandState, baselineRevision: Revision, baselineDir: Basics.AbsolutePath, modulesToDiff: Set<String>) async throws {
Copy link
Contributor

Choose a reason for hiding this comment

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

suggestion: consider type aliasing, or creating more specific type, for the modulesToDiff argument to aid in code readability. For example, instead of String, create a type alias which represents what the string is. e.g.: typealias ModuleName = String, and then modulesToDiff: Set<ModuleName>

@@ -687,6 +723,32 @@ public final class SwiftBuildSystem: SPMBuildCore.BuildSystem {
return settings
}

private static func constructAPIDigesterSettingsOverrides(from digesterMode: BuildParameters.APIDigesterMode?) -> [String: String] {
Copy link
Contributor

Choose a reason for hiding this comment

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

suggestion: although this function is straightforward, consider writing automated tests to values the expected return value.

@owenv
Copy link
Contributor Author

owenv commented Jun 24, 2025

Looks like we need to fix looking up the api digester relative to the compiler that was used

@owenv owenv force-pushed the owenv/digester branch 2 times, most recently from 90a764e to 7da6b4f Compare June 25, 2025 01:20
@owenv
Copy link
Contributor Author

owenv commented Jun 25, 2025

@swift-ci test

@owenv
Copy link
Contributor Author

owenv commented Jun 25, 2025

@swift-ci test

@owenv
Copy link
Contributor Author

owenv commented Jun 30, 2025

@swift-ci test

@owenv owenv force-pushed the owenv/digester branch from 579dbe0 to 861aa0e Compare July 1, 2025 00:18
@owenv
Copy link
Contributor Author

owenv commented Jul 1, 2025

@swift-ci test

@owenv owenv force-pushed the owenv/digester branch from 861aa0e to 06bcade Compare July 1, 2025 04:13
@owenv
Copy link
Contributor Author

owenv commented Jul 1, 2025

@swift-ci test

@owenv owenv force-pushed the owenv/digester branch from 06bcade to 13c2c76 Compare July 1, 2025 16:14
@owenv
Copy link
Contributor Author

owenv commented Jul 1, 2025

@swift-ci test

@owenv
Copy link
Contributor Author

owenv commented Jul 1, 2025

@swift-ci test Windows

1 similar comment
@owenv
Copy link
Contributor Author

owenv commented Jul 1, 2025

@swift-ci test Windows

@owenv owenv merged commit adf14cf into swiftlang:main Jul 2, 2025
6 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

diagnose-api-breaking-changes command doesn't support swiftbuild build system
3 participants