@@ -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