Skip to content

Commit f6f1a89

Browse files
committed
Moving files around
1 parent 4267736 commit f6f1a89

File tree

70 files changed

+540
-290
lines changed

Some content is hidden

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

70 files changed

+540
-290
lines changed

Package.swift

Lines changed: 114 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3,28 +3,136 @@
33

44
import PackageDescription
55

6+
private extension String {
7+
static var core: Self { "CoreModule" }
8+
static var fileHandling: Self { "FileHandlingModule" }
9+
static var shell: Self { "ShellModule" }
10+
static var git: Self { "GitModule" }
11+
static var logging: Self { "LoggingModule" }
12+
static var outputGenerator: Self { "OutputGeneratorModule" }
13+
static var swiftInterfaceAnalyzerModule: Self { "SwiftInterfaceAnalyzerModule" }
14+
static var projectSetupModule: Self { "ProjectSetupModule" }
15+
static var swiftInterfaceProducerModule: Self { "SwiftInterfaceProducerModule" }
16+
static var swiftPackageFileHelperModule: Self { "SwiftPackageFileHelperModule" }
17+
static var swiftPackageFileAnalyzerModule: Self { "SwiftPackageFileAnalyzerModule" }
18+
19+
}
20+
21+
extension Target.Dependency {
22+
static var core: Self { .byName(name: .core) }
23+
static var fileHandling: Self { .byName(name: .fileHandling) }
24+
static var shell: Self { .byName(name: .shell) }
25+
static var git: Self { .byName(name: .git) }
26+
static var logging: Self { .byName(name: .logging) }
27+
static var outputGenerator: Self { .byName(name: .outputGenerator) }
28+
static var swiftInterfaceAnalyzerModule: Self { .byName(name: .swiftInterfaceAnalyzerModule) }
29+
static var projectSetupModule: Self { .byName(name: .projectSetupModule) }
30+
static var swiftInterfaceProducerModule: Self { .byName(name: .swiftInterfaceProducerModule) }
31+
static var swiftPackageFileHelperModule: Self { .byName(name: .swiftPackageFileHelperModule) }
32+
static var swiftPackageFileAnalyzerModule: Self { .byName(name: .swiftPackageFileAnalyzerModule) }
33+
}
34+
635
let package = Package(
736
name: "public-api-diff",
837
platforms: [
938
.macOS(.v13)
1039
],
40+
products: [
41+
.executable(
42+
name: "public-api-diff",
43+
targets: ["public-api-diff"]
44+
),
45+
.library(
46+
name: "SwiftInterfaceDiff",
47+
targets: [.swiftInterfaceAnalyzerModule]
48+
)
49+
],
1150
dependencies: [
1251
.package(url: "https://github.com/apple/swift-argument-parser", from: "1.5.0"),
1352
.package(url: "https://github.com/swiftlang/swift-syntax", from: "600.0.0"),
1453
.package(url: "https://github.com/nicklockwood/SwiftFormat", from: "0.54.6")
1554
],
1655
targets: [
17-
// Targets are the basic building blocks of a package, defining a module or a test suite.
18-
// Targets can depend on other targets in this package and products from dependencies.
1956
.executableTarget(
2057
name: "public-api-diff",
2158
dependencies: [
22-
.product(name: "ArgumentParser", package: "swift-argument-parser"),
23-
.product(name: "SwiftSyntax", package: "swift-syntax"),
24-
.product(name: "SwiftParser", package: "swift-syntax"),
59+
.core,
60+
.logging,
61+
.shell,
62+
.git,
63+
.outputGenerator,
64+
.fileHandling,
65+
.projectSetupModule,
66+
.swiftInterfaceProducerModule,
67+
.swiftInterfaceAnalyzerModule,
68+
.swiftPackageFileHelperModule,
69+
.swiftPackageFileAnalyzerModule,
70+
"ProjectBuilderModule",
71+
.product(name: "ArgumentParser", package: "swift-argument-parser")
2572
],
26-
path: "Sources"
73+
path: "Sources/CommandLineTool"
2774
),
75+
76+
// MARK: - Modules
77+
78+
.target(name: .core),
79+
.target(name: .shell, dependencies: [
80+
.core
81+
]),
82+
.target(name: .logging, dependencies: [
83+
.core,
84+
.fileHandling
85+
]),
86+
.target(name: .git, dependencies: [
87+
.core,
88+
.shell,
89+
.fileHandling,
90+
.logging
91+
]),
92+
.target(name: .outputGenerator, dependencies: [
93+
.core
94+
]),
95+
.target(name: .fileHandling, dependencies: [
96+
.core
97+
]),
98+
.target(name: .swiftInterfaceAnalyzerModule, dependencies: [
99+
.core,
100+
.product(name: "SwiftSyntax", package: "swift-syntax"),
101+
.product(name: "SwiftParser", package: "swift-syntax"),
102+
]),
103+
.target(name: .swiftInterfaceProducerModule, dependencies: [
104+
.core,
105+
.fileHandling,
106+
.logging,
107+
.swiftPackageFileHelperModule
108+
]),
109+
.target(name: .projectSetupModule, dependencies: [
110+
.shell,
111+
.fileHandling,
112+
.logging,
113+
.git
114+
]),
115+
.target(name: .swiftPackageFileHelperModule, dependencies: [
116+
.core,
117+
.fileHandling,
118+
.logging
119+
]),
120+
.target(name: .swiftPackageFileAnalyzerModule, dependencies: [
121+
.core,
122+
.fileHandling,
123+
.shell,
124+
.logging,
125+
.swiftPackageFileHelperModule
126+
]),
127+
.target(name: "ProjectBuilderModule", dependencies: [
128+
.swiftPackageFileAnalyzerModule,
129+
.swiftPackageFileHelperModule,
130+
.fileHandling,
131+
.logging
132+
]),
133+
134+
// MARK: - Test Targets
135+
28136
.testTarget(
29137
name: "UnitTests",
30138
dependencies: [

Sources/public-api-diff.swift renamed to Sources/CommandLineTool/public-api-diff.swift

Lines changed: 23 additions & 57 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,16 @@
77
import ArgumentParser
88
import Foundation
99

10+
import LoggingModule
11+
import FileHandlingModule
12+
import CoreModule
13+
import ProjectSetupModule
14+
import ShellModule
15+
import SwiftInterfaceProducerModule
16+
import SwiftInterfaceAnalyzerModule
17+
import OutputGeneratorModule
18+
import ProjectBuilderModule
19+
1020
@main
1121
struct PublicApiDiff: AsyncParsableCommand {
1222

@@ -42,80 +52,36 @@ struct PublicApiDiff: AsyncParsableCommand {
4252
var warnings = [String]()
4353
var changes = [String: [Change]]()
4454

45-
// MARK: START: BUILD PROJECT RELATED
46-
4755
let oldSource: ProjectSource = try ProjectSource.from(old, fileHandler: fileHandler)
4856
let newSource: ProjectSource = try ProjectSource.from(new, fileHandler: fileHandler)
4957

5058
let oldVersionName = oldSource.description
51-
let newVersionName = oldSource.description
52-
53-
logger.log("Comparing `\(newVersionName)` to `\(oldVersionName)`", from: "Main")
59+
let newVersionName = newSource.description
5460

55-
let currentDirectory = fileHandler.currentDirectoryPath
56-
let workingDirectoryPath = currentDirectory.appending("/tmp-public-api-diff")
61+
// MARK: - Producing .swiftinterface files
5762

58-
// MARK: - Setup projects
59-
60-
let projectSetupHelper = ProjectSetupHelper(
61-
workingDirectoryPath: workingDirectoryPath,
62-
shell: shell,
63-
fileHandler: fileHandler,
63+
let projectBuilder = ProjectBuilder(
64+
projectType: projectType,
65+
swiftInterfaceType: swiftInterfaceType,
6466
logger: logger
6567
)
6668

67-
let projectDirectories = try await projectSetupHelper.setupProjects(
69+
let projectBuilderResult = try await projectBuilder.build(
6870
oldSource: oldSource,
69-
newSource: newSource,
70-
projectType: projectType
71+
newSource: newSource
7172
)
7273

73-
// MARK: - Analyze Package.swift (optional)
74-
75-
switch projectType {
76-
case .swiftPackage:
77-
let swiftPackageFileAnalyzer = SwiftPackageFileAnalyzer(fileHandler: fileHandler, shell: shell, logger: logger)
78-
let swiftPackageAnalysis = try swiftPackageFileAnalyzer.analyze(
79-
oldProjectUrl: projectDirectories.old,
80-
newProjectUrl: projectDirectories.new
81-
)
82-
83-
warnings = swiftPackageAnalysis.warnings
84-
if !swiftPackageAnalysis.changes.isEmpty {
85-
changes["Package.swift"] = swiftPackageAnalysis.changes
86-
}
87-
case .xcodeProject:
88-
warnings = []
89-
break // Nothing to do
74+
warnings += projectBuilderResult.warnings
75+
if !projectBuilderResult.packageFileChanges.isEmpty {
76+
changes["Package.swift"] = projectBuilderResult.packageFileChanges
9077
}
9178

92-
// MARK: - Produce .swiftinterface files
93-
94-
let producer = SwiftInterfaceProducer(
95-
workingDirectoryPath: workingDirectoryPath,
96-
projectType: projectType,
97-
swiftInterfaceType: swiftInterfaceType,
98-
fileHandler: fileHandler,
99-
shell: shell,
100-
logger: logger
101-
)
102-
103-
let swiftInterfaceFiles = try await producer.produceInterfaceFiles(
104-
oldProjectDirectory: projectDirectories.old,
105-
newProjectDirectory: projectDirectories.new
106-
)
107-
10879
// MARK: - Analyze .swiftinterface files
10980

110-
let pipeline = SwiftInterfacePipeline(
111-
fileHandler: fileHandler,
112-
swiftInterfaceParser: SwiftInterfaceParser(),
113-
swiftInterfaceAnalyzer: SwiftInterfaceAnalyzer(),
114-
logger: logger
115-
)
81+
let pipeline = SwiftInterfacePipeline(logger: logger)
11682

11783
let pipelineOutput = try await pipeline.run(
118-
with: swiftInterfaceFiles
84+
with: projectBuilderResult.swiftInterfaceFiles
11985
)
12086

12187
// Merging pipeline output into existing changes - making sure we're not overriding any keys
@@ -133,7 +99,7 @@ struct PublicApiDiff: AsyncParsableCommand {
13399

134100
let generatedOutput = try outputGenerator.generate(
135101
from: changes,
136-
allTargets: swiftInterfaceFiles.map(\.name).sorted(),
102+
allTargets: projectBuilderResult.swiftInterfaceFiles.map(\.name).sorted(),
137103
oldVersionName: oldVersionName,
138104
newVersionName: newVersionName,
139105
warnings: warnings

Sources/Helpers/Models/Change.swift renamed to Sources/CoreModule/Change.swift

Lines changed: 19 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -7,22 +7,32 @@
77
import Foundation
88

99
/// A change indicating an `addition`, `removal` or genuine `change` of an element
10-
struct Change: Equatable {
11-
enum ChangeType: Equatable {
10+
public struct Change: Equatable {
11+
public enum ChangeType: Equatable {
1212
case addition(description: String)
1313
case removal(description: String)
1414
case change(oldDescription: String, newDescription: String)
1515
}
1616

17-
var changeType: ChangeType
18-
var parentPath: String?
17+
public private(set) var changeType: ChangeType
18+
public private(set) var parentPath: String?
1919

20-
var listOfChanges: [String] = []
20+
public private(set) var listOfChanges: [String] = []
21+
22+
public init(
23+
changeType: ChangeType,
24+
parentPath: String? = nil,
25+
listOfChanges: [String] = []
26+
) {
27+
self.changeType = changeType
28+
self.parentPath = parentPath
29+
self.listOfChanges = listOfChanges
30+
}
2131
}
2232

2333
extension Change.ChangeType {
2434

25-
var isAddition: Bool {
35+
public var isAddition: Bool {
2636
switch self {
2737
case .addition:
2838
return true
@@ -33,7 +43,7 @@ extension Change.ChangeType {
3343
}
3444
}
3545

36-
var isRemoval: Bool {
46+
public var isRemoval: Bool {
3747
switch self {
3848
case .addition:
3949
return false
@@ -44,7 +54,7 @@ extension Change.ChangeType {
4454
}
4555
}
4656

47-
var isChange: Bool {
57+
public var isChange: Bool {
4858
switch self {
4959
case .addition:
5060
return false
@@ -56,7 +66,7 @@ extension Change.ChangeType {
5666
}
5767
}
5868

59-
extension [String: [Change]] {
69+
public extension [String: [Change]] {
6070

6171
var totalChangeCount: Int {
6272
var totalChangeCount = 0
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
import Foundation
2+
3+
public enum ProjectType {
4+
case swiftPackage
5+
case xcodeProject(scheme: String)
6+
}

Sources/Helpers/RandomStringGenerating.swift renamed to Sources/CoreModule/RandomStringGenerating.swift

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,14 +6,16 @@
66

77
import Foundation
88

9-
protocol RandomStringGenerating {
9+
public protocol RandomStringGenerating {
1010

1111
func generateRandomString() -> String
1212
}
1313

14-
struct RandomStringGenerator: RandomStringGenerating {
14+
public struct RandomStringGenerator: RandomStringGenerating {
1515

16-
func generateRandomString() -> String {
16+
public init() {}
17+
18+
public func generateRandomString() -> String {
1719
UUID().uuidString
1820
}
1921
}
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
import Foundation
2+
3+
public struct SwiftInterfaceFile {
4+
public let name: String
5+
public let oldFilePath: String
6+
public let newFilePath: String
7+
8+
public init(name: String, oldFilePath: String, newFilePath: String) {
9+
self.name = name
10+
self.oldFilePath = oldFilePath
11+
self.newFilePath = newFilePath
12+
}
13+
}

Sources/Helpers/FileHandling/FileHandling+Convenience.swift renamed to Sources/FileHandlingModule/FileHandling+Convenience.swift

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,9 @@
55
//
66

77
import Foundation
8+
import CoreModule
89

9-
enum FileHandlerError: LocalizedError, Equatable {
10+
public enum FileHandlerError: LocalizedError, Equatable {
1011
/// Could not encode the output string into data
1112
case couldNotEncodeOutput
1213
/// Could not persist output at the specified `outputFilePath`
@@ -16,7 +17,7 @@ enum FileHandlerError: LocalizedError, Equatable {
1617
/// File/Directory does not exist at `path`
1718
case pathDoesNotExist(path: String)
1819

19-
var errorDescription: String? {
20+
public var errorDescription: String? {
2021
switch self {
2122
case .couldNotEncodeOutput:
2223
"Could not encode the output string into data"
@@ -32,7 +33,7 @@ enum FileHandlerError: LocalizedError, Equatable {
3233

3334
// MARK: - Convenience
3435

35-
extension FileHandling {
36+
public extension FileHandling {
3637

3738
/// Creates a directory at the specified path and deletes any old directory if existing
3839
///

0 commit comments

Comments
 (0)