Skip to content

Commit 5b63d6c

Browse files
authored
fix: Make manifest Swift 6 Language Mode compatible (#1774)
1 parent f20ede5 commit 5b63d6c

File tree

9 files changed

+355
-450
lines changed

9 files changed

+355
-450
lines changed

AWSSDKSwiftCLI/Package.swift

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,8 @@ let package = Package(
2424
.product(name: "Algorithms", package: "swift-algorithms"),
2525
],
2626
resources: [
27-
.process("Resources/Package.Base.swift"),
27+
.process("Resources/Package.Prefix.txt"),
28+
.process("Resources/Package.Base.txt"),
2829
.process("Resources/DocIndex.Base.md")
2930
]
3031
),

AWSSDKSwiftCLI/Sources/AWSSDKSwiftCLI/Commands/AWSSDKSwiftCLI/Subcommands/GeneratePackageManifest.swift

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -32,9 +32,6 @@ struct GeneratePackageManifestCommand: ParsableCommand {
3232
@Option(help: "The names of the services to include in the package manifest. This defaults to all services located in aws-sdk-swift/Sources/Services")
3333
var services: [String] = []
3434

35-
@Flag(help: "If the package manifest should exclude AWS services.")
36-
var excludeAWSServices = false
37-
3835
@Flag(help: "If the package manifest should exclude runtime tests.")
3936
var excludeRuntimeTests = false
4037

@@ -45,7 +42,6 @@ struct GeneratePackageManifestCommand: ParsableCommand {
4542
clientRuntimeVersion: clientRuntimeVersion,
4643
crtVersion: crtVersion,
4744
services: services.isEmpty ? nil : services,
48-
excludeAWSServices: excludeAWSServices,
4945
excludeRuntimeTests: excludeRuntimeTests
5046
)
5147
try generatePackageManifest.run()
@@ -69,8 +65,6 @@ struct GeneratePackageManifest {
6965
/// The list of services to include as products
7066
/// If `nil` then the list is populated with the names of all items within the `Sources/Services` directory
7167
let services: [String]?
72-
/// If the package manifest should exclude the AWS services.
73-
let excludeAWSServices: Bool
7468
/// If the package manifest should exclude runtime unit tests.
7569
let excludeRuntimeTests: Bool
7670

@@ -213,14 +207,12 @@ extension GeneratePackageManifest {
213207
clientRuntimeVersion: clientRuntimeVersion,
214208
crtVersion: crtVersion,
215209
services: services,
216-
excludeAWSServices: excludeAWSServices,
217210
excludeRuntimeTests: excludeRuntimeTests
218211
) { _clientRuntimeVersion, _crtVersion, _services in
219212
let builder = PackageManifestBuilder(
220213
clientRuntimeVersion: _clientRuntimeVersion,
221214
crtVersion: _crtVersion,
222215
services: _services,
223-
excludeAWSServices: excludeAWSServices,
224216
excludeRuntimeTests: excludeRuntimeTests
225217
)
226218
return try builder.build()

AWSSDKSwiftCLI/Sources/AWSSDKSwiftCLI/Models/PackageManifestBuilder.swift

Lines changed: 30 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -17,62 +17,69 @@ struct PackageManifestBuilder {
1717
let clientRuntimeVersion: Version
1818
let crtVersion: Version
1919
let services: [Service]
20-
let excludeAWSServices: Bool
2120
let excludeRuntimeTests: Bool
21+
let prefixContents: () throws -> String
2222
let basePackageContents: () throws -> String
2323

2424
init(
2525
clientRuntimeVersion: Version,
2626
crtVersion: Version,
2727
services: [Service],
28-
excludeAWSServices: Bool,
2928
excludeRuntimeTests: Bool,
29+
prefixContents: @escaping () throws -> String,
3030
basePackageContents: @escaping () throws -> String
3131
) {
3232
self.clientRuntimeVersion = clientRuntimeVersion
3333
self.crtVersion = crtVersion
3434
self.services = services
35-
self.excludeAWSServices = excludeAWSServices
36-
self.basePackageContents = basePackageContents
3735
self.excludeRuntimeTests = excludeRuntimeTests
36+
self.prefixContents = prefixContents
37+
self.basePackageContents = basePackageContents
3838
}
3939

4040
init(
4141
clientRuntimeVersion: Version,
4242
crtVersion: Version,
4343
services: [Service],
44-
excludeAWSServices: Bool,
4544
excludeRuntimeTests: Bool
4645
) {
47-
self.init(clientRuntimeVersion: clientRuntimeVersion, crtVersion: crtVersion, services: services, excludeAWSServices: excludeAWSServices, excludeRuntimeTests: excludeRuntimeTests) {
48-
// Returns the contents of the base package manifest stored in the bundle at `Resources/Package.Base.swift`
49-
let basePackageName = "Package.Base"
50-
51-
// Get the url for the base package manifest that is stored in the bundle
52-
guard let url = Bundle.module.url(forResource: basePackageName, withExtension: "swift") else {
53-
throw Error("Could not find \(basePackageName).swift in bundle")
46+
self.init(
47+
clientRuntimeVersion: clientRuntimeVersion,
48+
crtVersion: crtVersion,
49+
services: services,
50+
excludeRuntimeTests: excludeRuntimeTests,
51+
prefixContents: Self.contentReader(filename: "Package.Prefix"),
52+
basePackageContents: Self.contentReader(filename: "Package.Base")
53+
)
54+
}
55+
56+
static func contentReader(filename: String) -> () throws -> String {
57+
return {
58+
// Get the url for the file that is stored in the bundle
59+
guard let url = Bundle.module.url(forResource: filename, withExtension: "txt") else {
60+
throw Error("Could not find \(filename).txt in bundle")
5461
}
55-
62+
5663
// Load the contents of the base package manifest
5764
let fileContents = try FileManager.default.loadContents(atPath: url.path)
58-
65+
5966
// Convert the base package manifest data to a string
6067
guard let fileText = String(data: fileContents, encoding: .utf8) else {
61-
throw Error("Failed to create string from contents of file \(basePackageName).swift")
68+
throw Error("Failed to create string from contents of file \(filename).txt")
6269
}
63-
70+
6471
return fileText
6572
}
6673
}
67-
74+
6875
// MARK: - Build
6976

7077
/// Builds the contents of the package manifest file.
7178
func build() throws-> String {
7279
let contents = try [
80+
prefixContents(),
81+
buildGeneratedContent(),
7382
basePackageContents(),
74-
"",
75-
buildGeneratedContent()
7683
]
7784
return contents.joined(separator: .newline)
7885
}
@@ -92,8 +99,6 @@ struct PackageManifestBuilder {
9299
// Add the generated content that defines the list of services to include
93100
buildServiceTargets(),
94101
"",
95-
buildResolvedServices(),
96-
"\n"
97102
]
98103
return contents.joined(separator: .newline)
99104
}
@@ -102,25 +107,20 @@ struct PackageManifestBuilder {
102107
///
103108
/// - Returns: A pragma mark comment to provide separation between the non-generated (base) and generated content
104109
private func buildPragmaMark() -> String {
105-
"// MARK: - Generated"
110+
"// MARK: - Dynamic Content"
106111
}
107112

108113

109114
/// Builds the dependencies versions
110115
private func buildDependencies() -> String {
111116
"""
112-
addDependencies(
113-
clientRuntimeVersion: \(clientRuntimeVersion.description.wrappedInQuotes()),
114-
crtVersion: \(crtVersion.description.wrappedInQuotes())
115-
)
117+
let clientRuntimeVersion: Version = \(clientRuntimeVersion.description.wrappedInQuotes())
118+
let crtVersion: Version = \(crtVersion.description.wrappedInQuotes())
116119
"""
117120
}
118121

119122
private func buildRuntimeTests() -> String {
120-
return [
121-
"// Uncomment this line to exclude runtime unit tests",
122-
(excludeRuntimeTests ? "" : "// ") + "excludeRuntimeUnitTests()"
123-
].joined(separator: .newline)
123+
"let excludeRuntimeUnitTests = \(excludeRuntimeTests)"
124124
}
125125

126126
/// Builds the list of services to include.
@@ -131,14 +131,6 @@ struct PackageManifestBuilder {
131131
lines += ["let serviceTargets: [String] = ["]
132132
lines += services.map { " \($0.name.wrappedInQuotes())," }
133133
lines += ["]"]
134-
lines += [""]
135-
lines += ["// Uncomment this line to enable all services"]
136-
lines += ["\(excludeAWSServices ? "// " : "")addAllServices()"]
137-
138134
return lines.joined(separator: .newline)
139135
}
140-
141-
private func buildResolvedServices() -> String {
142-
"addResolvedTargets()"
143-
}
144136
}

0 commit comments

Comments
 (0)