Skip to content

Commit c138ff1

Browse files
authored
.swiftinterface file support (#21)
1 parent 661743d commit c138ff1

File tree

143 files changed

+5624
-157701
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

143 files changed

+5624
-157701
lines changed

Info.plist

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
//
2+
// File.swift
3+
// public-api-diff
4+
//
5+
// Created by Alexander Guretzki on 11/10/2024.
6+
//
7+
8+
import Foundation

Package.resolved

Lines changed: 29 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Package.swift

Lines changed: 111 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -8,29 +8,131 @@ let package = Package(
88
platforms: [
99
.macOS(.v13)
1010
],
11+
products: [
12+
.executable(
13+
name: "public-api-diff",
14+
targets: ["public-api-diff"]
15+
),
16+
.library(
17+
name: "SwiftInterfaceDiff",
18+
targets: [
19+
"PADSwiftInterfaceDiff",
20+
"PADOutputGenerator"
21+
]
22+
),
23+
.library(
24+
name: "PublicApiDiff",
25+
targets: [
26+
"PADProjectBuilder",
27+
"PADPackageFileAnalyzer",
28+
"PADSwiftInterfaceDiff",
29+
"PADOutputGenerator"
30+
]
31+
)
32+
],
1133
dependencies: [
1234
.package(url: "https://github.com/apple/swift-argument-parser", from: "1.5.0"),
13-
.package(url: "https://github.com/nicklockwood/SwiftFormat", from: "0.54.6")
35+
.package(url: "https://github.com/swiftlang/swift-syntax", from: "600.0.0"),
36+
.package(url: "https://github.com/nicklockwood/SwiftFormat", from: "0.54.6"),
37+
.package(url: "https://github.com/apple/swift-docc-plugin", from: "1.0.0")
1438
],
1539
targets: [
16-
// Targets are the basic building blocks of a package, defining a module or a test suite.
17-
// Targets can depend on other targets in this package and products from dependencies.
40+
41+
// MARK: - Executable Targets
42+
1843
.executableTarget(
1944
name: "public-api-diff",
2045
dependencies: [
46+
"PADProjectBuilder",
47+
"PADSwiftInterfaceDiff",
48+
"PADOutputGenerator",
49+
"PADPackageFileAnalyzer",
2150
.product(name: "ArgumentParser", package: "swift-argument-parser")
2251
],
23-
path: "Sources"
52+
path: "Sources/ExecutableTargets/CommandLineTool"
2453
),
54+
55+
// MARK: - Public Modules
56+
57+
.target(
58+
name: "PADSwiftInterfaceDiff",
59+
dependencies: [
60+
"PADCore",
61+
"PADLogging",
62+
"FileHandlingModule",
63+
.product(name: "SwiftSyntax", package: "swift-syntax"),
64+
.product(name: "SwiftParser", package: "swift-syntax"),
65+
],
66+
path: "Sources/PublicModules/PADSwiftInterfaceDiff"
67+
),
68+
.target(
69+
name: "PADPackageFileAnalyzer",
70+
dependencies: [
71+
"PADCore",
72+
"PADLogging",
73+
"FileHandlingModule",
74+
"ShellModule",
75+
"SwiftPackageFileHelperModule"
76+
],
77+
path: "Sources/PublicModules/PADPackageFileAnalyzer"
78+
),
79+
.target(
80+
name: "PADProjectBuilder",
81+
dependencies: [
82+
"PADCore",
83+
"PADLogging",
84+
"FileHandlingModule",
85+
"ShellModule",
86+
"SwiftPackageFileHelperModule"
87+
],
88+
path: "Sources/PublicModules/PADProjectBuilder"
89+
),
90+
.target(
91+
name: "PADOutputGenerator",
92+
dependencies: ["PADCore"],
93+
path: "Sources/PublicModules/PADOutputGenerator"
94+
),
95+
96+
// MARK: - Shared/Public
97+
98+
.target(
99+
name: "PADCore",
100+
path: "Sources/Shared/Public/PADCore"
101+
),
102+
.target(
103+
name: "PADLogging",
104+
dependencies: ["FileHandlingModule"],
105+
path: "Sources/Shared/Public/PADLogging"
106+
),
107+
108+
// MARK: - Shared/Package
109+
110+
.target(
111+
name: "FileHandlingModule",
112+
path: "Sources/Shared/Package/FileHandlingModule"
113+
),
114+
.target(
115+
name: "ShellModule",
116+
path: "Sources/Shared/Package/ShellModule"
117+
),
118+
.target(
119+
name: "SwiftPackageFileHelperModule",
120+
dependencies: ["FileHandlingModule", "ShellModule", "PADLogging"],
121+
path: "Sources/Shared/Package/SwiftPackageFileHelperModule"
122+
),
123+
124+
// MARK: - Test Targets
125+
25126
.testTarget(
26127
name: "UnitTests",
27-
dependencies: ["public-api-diff"],
128+
dependencies: [
129+
"public-api-diff"
130+
],
28131
resources: [
29132
// Copy Tests/ExampleTests/Resources directories as-is.
30133
// Use to retain directory structure.
31134
// Will be at top level in bundle.
32-
.copy("Resources/dummy.abi.json"),
33-
.copy("Resources/dummi-abi-flat-definition.md")
135+
.copy("Resources/expected-reference-changes.md")
34136
]
35137
),
36138
.testTarget(
@@ -40,7 +142,8 @@ let package = Package(
40142
// Copy Tests/ExampleTests/Resources directories as-is.
41143
// Use to retain directory structure.
42144
// Will be at top level in bundle.
43-
.copy("Resources/expected-reference-changes.md")
145+
.copy("Resources/expected-reference-changes-swift-interface-private.md"),
146+
.copy("Resources/expected-reference-changes-swift-interface-public.md")
44147
]
45148
)
46149
]

README.md

Lines changed: 52 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -1,44 +1,52 @@
1-
# Swift Public API diff
2-
3-
This tool allows comparing 2 versions of a swift package project and lists all changes in a human readable way.
4-
5-
It makes use of `xcrun swift-api-digester -dump-sdk` to create a dump of the public api of your swift package and then runs it through a custom parser to process them.
6-
7-
Alternatively you could use `xcrun swift-api-digester -diagnose-sdk` and pass the abi dumps into it.
8-
9-
## How it works
10-
11-
![image](https://github.com/user-attachments/assets/cc04d21a-06f6-42bc-8e73-4aef7af21d7a)
12-
13-
14-
### Project Builder
15-
16-
Builds the swift package project which is required for the next step to run the `xcrun swift-api-digester -dump-sdk`
17-
18-
### ABIGenerator
19-
20-
Makes use of `xcrun swift-api-digester -dump-sdk` to "dump" the public interface into an abi.json file.
21-
22-
### SDKDumpGenerator
23-
24-
Parses the abi.json files into an `SDKDump` object
25-
26-
### SDKDumpAnalyzer
27-
28-
Analyzes 2 `SDKDump` objects and detects `addition`s & `removal`s.
29-
30-
### ChangeConsolidator
31-
32-
The `ChangeConsolidator` takes 2 independent changes (`addition` & `removal`) and tries to match them based on the name, declKind and parent.
33-
34-
| Match |
35-
| --- |
36-
| ![image](https://github.com/user-attachments/assets/f057c160-f85d-45af-b08f-203b89e43b41) |
37-
38-
| No Match | Potentially false positive |
39-
| --- | --- |
40-
| ![image](https://github.com/user-attachments/assets/5ae3b624-b32a-41cc-9026-8ba0117cec57) | ![image](https://github.com/user-attachments/assets/a7e60605-fc1c-49ef-a203-d6a5466a6fda) |
41-
42-
### OutputGenerator
43-
44-
Receives a list of `Change`s and processes them into a human readable format.
1+
[![🧪 Run Tests](https://github.com/Adyen/adyen-swift-public-api-diff/actions/workflows/run-tests.yml/badge.svg)](https://github.com/Adyen/adyen-swift-public-api-diff/actions/workflows/run-tests.yml)
2+
3+
# Swift Public API diff
4+
5+
This tool allows comparing 2 versions of a swift (sdk) project and lists all changes in a human readable way.
6+
7+
It makes use of `.swiftinterface` files that get produced during the archiving of a swift project and parses them using [`swift-syntax`](https://github.com/swiftlang/swift-syntax).
8+
9+
## Usage
10+
11+
```
12+
USAGE: public-api-diff --new <new> --old <old> [--output <output>] [--log-output <log-output>] [--scheme <scheme>]
13+
14+
OPTIONS:
15+
--new <new> Specify the updated version to compare to
16+
--old <old> Specify the old version to compare to
17+
--output <output> Where to output the result (File path)
18+
--log-output <log-output>
19+
Where to output the logs (File path)
20+
--scheme <scheme> Which scheme to build (Needed when comparing 2 xcode projects)
21+
-h, --help Show help information.
22+
```
23+
24+
### Run as debug build
25+
```
26+
swift run public-api-diff
27+
--new "some/local/path"
28+
--old "develop~https://github.com/some/repository"
29+
--output "path/to/output.md"
30+
```
31+
32+
### How to create a release build
33+
```
34+
swift build --configuration release
35+
```
36+
37+
### Run release build
38+
```
39+
./public-api-diff
40+
--new "some/local/path"
41+
--old "develop~https://github.com/some/repository"
42+
--output "path/to/output.md"
43+
```
44+
45+
# Alternatives
46+
- **swift-api-digester**
47+
- `xcrun swift-api-digester -dump-sdk`
48+
- `xcrun swift-api-digester -diagnose-sdk`
49+
50+
# Inspiration
51+
- https://github.com/sdidla/Hatch/blob/main/Sources/Hatch/SymbolParser.swift
52+
- For parsing swift files using [swift-syntax](https://github.com/swiftlang/swift-syntax)'s [`SyntaxVisitor`](https://github.com/swiftlang/swift-syntax/blob/main/Sources/SwiftSyntax/generated/SyntaxVisitor.swift)

0 commit comments

Comments
 (0)