Skip to content

Commit 07fc160

Browse files
committed
Better modularization
1 parent f6f1a89 commit 07fc160

Some content is hidden

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

41 files changed

+71
-145
lines changed

Package.swift

Lines changed: 21 additions & 89 deletions
Original file line numberDiff line numberDiff line change
@@ -3,35 +3,6 @@
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-
356
let package = Package(
367
name: "public-api-diff",
378
platforms: [
@@ -44,7 +15,7 @@ let package = Package(
4415
),
4516
.library(
4617
name: "SwiftInterfaceDiff",
47-
targets: [.swiftInterfaceAnalyzerModule]
18+
targets: ["SwiftInterfaceAnalyzerModule"]
4819
)
4920
],
5021
dependencies: [
@@ -56,79 +27,40 @@ let package = Package(
5627
.executableTarget(
5728
name: "public-api-diff",
5829
dependencies: [
59-
.core,
60-
.logging,
61-
.shell,
62-
.git,
63-
.outputGenerator,
64-
.fileHandling,
65-
.projectSetupModule,
66-
.swiftInterfaceProducerModule,
67-
.swiftInterfaceAnalyzerModule,
68-
.swiftPackageFileHelperModule,
69-
.swiftPackageFileAnalyzerModule,
30+
"CoreModule",
31+
"LoggingModule",
32+
"OutputGeneratorModule",
33+
"FileHandlingModule",
7034
"ProjectBuilderModule",
35+
"SwiftInterfaceAnalyzerModule",
7136
.product(name: "ArgumentParser", package: "swift-argument-parser")
7237
],
7338
path: "Sources/CommandLineTool"
7439
),
7540

7641
// MARK: - Modules
7742

78-
.target(name: .core),
79-
.target(name: .shell, dependencies: [
80-
.core
81-
]),
82-
.target(name: .logging, dependencies: [
83-
.core,
84-
.fileHandling
43+
.target(name: "CoreModule"),
44+
.target(name: "FileHandlingModule", dependencies: []),
45+
.target(name: "ShellModule"),
46+
.target(name: "LoggingModule", dependencies: [
47+
"FileHandlingModule"
8548
]),
86-
.target(name: .git, dependencies: [
87-
.core,
88-
.shell,
89-
.fileHandling,
90-
.logging
49+
.target(name: "OutputGeneratorModule", dependencies: [
50+
"CoreModule"
9151
]),
92-
.target(name: .outputGenerator, dependencies: [
93-
.core
94-
]),
95-
.target(name: .fileHandling, dependencies: [
96-
.core
97-
]),
98-
.target(name: .swiftInterfaceAnalyzerModule, dependencies: [
99-
.core,
52+
.target(name: "SwiftInterfaceAnalyzerModule", dependencies: [
53+
"CoreModule",
10054
.product(name: "SwiftSyntax", package: "swift-syntax"),
10155
.product(name: "SwiftParser", package: "swift-syntax"),
10256
]),
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-
]),
12757
.target(name: "ProjectBuilderModule", dependencies: [
128-
.swiftPackageFileAnalyzerModule,
129-
.swiftPackageFileHelperModule,
130-
.fileHandling,
131-
.logging
58+
"CoreModule",
59+
"FileHandlingModule",
60+
"LoggingModule",
61+
"ShellModule",
62+
.product(name: "SwiftSyntax", package: "swift-syntax"),
63+
.product(name: "SwiftParser", package: "swift-syntax"),
13264
]),
13365

13466
// MARK: - Test Targets

Sources/CommandLineTool/public-api-diff.swift

Lines changed: 14 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -7,15 +7,12 @@
77
import ArgumentParser
88
import Foundation
99

10-
import LoggingModule
11-
import FileHandlingModule
1210
import CoreModule
13-
import ProjectSetupModule
14-
import ShellModule
15-
import SwiftInterfaceProducerModule
11+
import LoggingModule
12+
1613
import SwiftInterfaceAnalyzerModule
17-
import OutputGeneratorModule
1814
import ProjectBuilderModule
15+
import OutputGeneratorModule
1916

2017
@main
2118
struct PublicApiDiff: AsyncParsableCommand {
@@ -44,22 +41,20 @@ struct PublicApiDiff: AsyncParsableCommand {
4441
}()
4542
let swiftInterfaceType: SwiftInterfaceType = .public // Only needed when we have to produce the .swiftinterface files
4643

47-
let fileHandler: FileHandling = FileManager.default
48-
let shell: any ShellHandling = Shell()
49-
let logger = Self.logger(with: logLevel, logOutputFilePath: logOutput, fileHandler: fileHandler)
44+
let logger = Self.logger(with: logLevel, logOutputFilePath: logOutput)
5045

5146
do {
5247
var warnings = [String]()
5348
var changes = [String: [Change]]()
5449

55-
let oldSource: ProjectSource = try ProjectSource.from(old, fileHandler: fileHandler)
56-
let newSource: ProjectSource = try ProjectSource.from(new, fileHandler: fileHandler)
50+
// MARK: - Producing .swiftinterface files
51+
52+
let oldSource: ProjectSource = try ProjectSource.from(old)
53+
let newSource: ProjectSource = try ProjectSource.from(new)
5754

5855
let oldVersionName = oldSource.description
5956
let newVersionName = newSource.description
6057

61-
// MARK: - Producing .swiftinterface files
62-
6358
let projectBuilder = ProjectBuilder(
6459
projectType: projectType,
6560
swiftInterfaceType: swiftInterfaceType,
@@ -106,7 +101,7 @@ struct PublicApiDiff: AsyncParsableCommand {
106101
)
107102

108103
if let output {
109-
try fileHandler.write(generatedOutput, to: output)
104+
try FileManager.default.write(generatedOutput, to: output)
110105
} else {
111106
// We're not using a logger here as we always want to have it printed if no output was specified
112107
print(generatedOutput)
@@ -121,10 +116,13 @@ struct PublicApiDiff: AsyncParsableCommand {
121116

122117
private extension PublicApiDiff {
123118

124-
static func logger(with logLevel: LogLevel, logOutputFilePath: String?, fileHandler: any FileHandling) -> any Logging {
119+
static func logger(
120+
with logLevel: LogLevel,
121+
logOutputFilePath: String?
122+
) -> any Logging {
125123
var loggers = [any Logging]()
126124
if let logOutputFilePath {
127-
loggers += [LogFileLogger(fileHandler: fileHandler, outputFilePath: logOutputFilePath)]
125+
loggers += [LogFileLogger(outputFilePath: logOutputFilePath)]
128126
}
129127
loggers += [SystemLogger().withLogLevel(logLevel)]
130128

Sources/FileHandlingModule/FileHandling+Convenience.swift

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@
55
//
66

77
import Foundation
8-
import CoreModule
98

109
public enum FileHandlerError: LocalizedError, Equatable {
1110
/// Could not encode the output string into data

Sources/FileHandlingModule/FileManager+FileHandling.swift

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@
55
//
66

77
import Foundation
8-
import CoreModule
98

109
extension FileManager: FileHandling {
1110

Sources/LoggingModule/LogFileLogger.swift

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
import Foundation
2-
import CoreModule
32
import FileHandlingModule
43

54
public class LogFileLogger: Logging {
@@ -14,7 +13,7 @@ public class LogFileLogger: Logging {
1413
}
1514
}
1615

17-
public init(fileHandler: any FileHandling, outputFilePath: String) {
16+
public init(fileHandler: any FileHandling = FileManager.default, outputFilePath: String) {
1817
self.fileHandler = fileHandler
1918
self.outputFilePath = outputFilePath
2019
}

Sources/LoggingModule/LogLevelLogger.swift

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
import Foundation
22
import OSLog
3-
import CoreModule
43

54
public enum LogLevel {
65
/// No logs

Sources/LoggingModule/LoggingGroup.swift

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
import Foundation
2-
import CoreModule
32

43
public struct LoggingGroup: Logging {
54

Sources/LoggingModule/SystemLogger.swift

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
import Foundation
22
import OSLog
3-
import CoreModule
43

54
public struct SystemLogger: Logging {
65

Sources/ProjectBuilderModule/ProjectBuilder.swift

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,12 +8,9 @@
88
import Foundation
99

1010
import FileHandlingModule
11-
import ProjectSetupModule
1211
import LoggingModule
1312
import CoreModule
1413
import ShellModule
15-
import SwiftPackageFileAnalyzerModule
16-
import SwiftInterfaceProducerModule
1714

1815
public struct ProjectBuilder {
1916

File renamed without changes.

0 commit comments

Comments
 (0)