@@ -76,7 +76,6 @@ var prebuiltRepos: IdentifiableSet<PrebuiltRepos> = [
76
76
) ,
77
77
]
78
78
79
- let manifestHost = URL ( string: " https://github.com/dschaefer2/swift-syntax/releases/download " ) !
80
79
let swiftVersion = " \( SwiftVersion . current. major) . \( SwiftVersion . current. minor) "
81
80
let dockerImageRoot = " swiftlang/swift:nightly-6.1- "
82
81
@@ -102,33 +101,36 @@ struct BuildPrebuilts: AsyncParsableCommand {
102
101
try fm. removeItem ( atPath: stageDir. pathString)
103
102
}
104
103
try fm. createDirectory ( atPath: stageDir. pathString, withIntermediateDirectories: true )
105
- _ = fm. changeCurrentDirectoryPath ( stageDir. pathString)
104
+
105
+ let srcDir = stageDir. appending ( " src " )
106
+ try fm. createDirectory ( atPath: srcDir. pathString, withIntermediateDirectories: true )
107
+
108
+ let libDir = stageDir. appending ( " lib " )
109
+ let modulesDir = stageDir. appending ( " modules " )
110
+ let includesDir = stageDir. appending ( " include " )
106
111
107
112
for repo in prebuiltRepos. values {
108
- let repoDir = stageDir. appending ( repo. url. lastPathComponent)
109
- let libDir = stageDir. appending ( " lib " )
110
- let modulesDir = stageDir. appending ( " modules " )
111
- let includesDir = stageDir. appending ( " include " )
113
+ let repoDir = srcDir. appending ( repo. url. lastPathComponent)
112
114
let scratchDir = repoDir. appending ( " .build " )
113
115
let buildDir = scratchDir. appending ( " release " )
114
116
let srcModulesDir = buildDir. appending ( " Modules " )
117
+ let prebuiltDir = stageDir. appending ( repo. url. lastPathComponent)
115
118
116
- try await shell ( " git clone \( repo. url) " )
119
+ try await shell ( " git clone \( repo. url) " , cwd : srcDir )
117
120
118
121
for version in repo. versions {
119
- let versionDir = stageDir . appending ( version. tag)
122
+ let versionDir = prebuiltDir . appending ( version. tag)
120
123
if !fm. fileExists ( atPath: versionDir. pathString) {
121
124
try fm. createDirectory ( atPath: versionDir. pathString, withIntermediateDirectories: true )
122
125
}
123
126
124
- _ = fm. changeCurrentDirectoryPath ( repoDir. pathString)
125
- try await shell ( " git checkout \( version. tag) " )
127
+ try await shell ( " git checkout \( version. tag) " , cwd: repoDir)
126
128
127
129
var newLibraries : IdentifiableSet < Workspace . PrebuiltsManifest . Library > = [ ]
128
130
129
131
for library in version. manifest. libraries {
130
132
// TODO: this is assuming products map to target names which is not always true
131
- try await shell ( " swift package add-product \( library. name) --type static-library --targets \( library. products. joined ( separator: " " ) ) " )
133
+ try await shell ( " swift package add-product \( library. name) --type static-library --targets \( library. products. joined ( separator: " " ) ) " , cwd : repoDir )
132
134
133
135
var newArtifacts : [ Workspace . PrebuiltsManifest . Library . Artifact ] = [ ]
134
136
@@ -152,7 +154,7 @@ struct BuildPrebuilts: AsyncParsableCommand {
152
154
cmd += " \( dockerCommand) run --rm --platform \( dockerPlatform) -v \( repoDir) : \( repoDir) -w \( repoDir) \( dockerImageRoot) \( dockerTag) "
153
155
}
154
156
cmd += " swift build -c release -debug-info-format none --arch \( platform. arch) --product \( library. name) "
155
- try await shell ( cmd)
157
+ try await shell ( cmd, cwd : repoDir )
156
158
157
159
// Copy the library to staging
158
160
let lib = " lib \( library. name) .a "
@@ -175,16 +177,14 @@ struct BuildPrebuilts: AsyncParsableCommand {
175
177
}
176
178
177
179
// Zip it up
178
- _ = fm. changeCurrentDirectoryPath ( stageDir. pathString)
179
180
let zipFile = versionDir. appending ( " \( swiftVersion) - \( library. name) - \( platform) .zip " )
180
181
let contentDirs = [ " lib " , " Modules " ] + ( library. cModules. isEmpty ? [ ] : [ " include " ] )
181
182
#if os(Windows)
182
- try await shell ( " tar -acf \( zipFile. pathString) \( contentDirs. joined ( separator: " " ) ) " )
183
+ try await shell ( " tar -acf \( zipFile. pathString) \( contentDirs. joined ( separator: " " ) ) " , cwd : stageDir )
183
184
#else
184
- try await shell ( " zip -r \( zipFile. pathString) \( contentDirs. joined ( separator: " " ) ) " )
185
+ try await shell ( " zip -r \( zipFile. pathString) \( contentDirs. joined ( separator: " " ) ) " , cwd : stageDir )
185
186
#endif
186
187
187
- _ = fm. changeCurrentDirectoryPath ( repoDir. pathString)
188
188
let contents = try ByteString ( Data ( contentsOf: zipFile. asURL) )
189
189
let checksum = SHA256 ( ) . hash ( contents) . hexadecimalRepresentation
190
190
@@ -203,35 +203,20 @@ struct BuildPrebuilts: AsyncParsableCommand {
203
203
)
204
204
newLibraries. insert ( newLibrary)
205
205
206
- try await shell ( " git reset --hard " )
207
- }
208
-
209
- if let oldManifest = try await downloadManifest ( version: version) {
210
- // Add in elements from the old manifest we haven't generated
211
- for library in oldManifest. libraries {
212
- if var newLibrary = newLibraries [ library. name] {
213
- var newArtifacts = IdentifiableSet < Workspace . PrebuiltsManifest . Library . Artifact > ( newLibrary. artifacts)
214
- for oldArtifact in library. artifacts {
215
- if !newArtifacts. contains ( id: oldArtifact. id) {
216
- newArtifacts. insert ( oldArtifact)
217
- }
218
- }
219
- newLibrary. artifacts = . init( newArtifacts. values)
220
- newLibraries. insert ( newLibrary)
221
- } else {
222
- newLibraries. insert ( library)
223
- }
224
- }
206
+ try await shell ( " git reset --hard " , cwd: repoDir)
225
207
}
226
- let newManifest = Workspace . PrebuiltsManifest ( libraries: . init( newLibraries. values) )
227
208
209
+ let manifest = Workspace . PrebuiltsManifest ( libraries: . init( newLibraries. values) )
228
210
let encoder = JSONEncoder ( )
229
211
encoder. outputFormatting = . prettyPrinted
230
- let manifestData = try encoder. encode ( newManifest )
212
+ let manifestData = try encoder. encode ( manifest )
231
213
let manifestFile = versionDir. appending ( " \( swiftVersion) -manifest.json " )
232
214
try manifestData. write ( to: manifestFile. asURL)
233
215
}
234
216
}
217
+
218
+ _ = FileManager . default. changeCurrentDirectoryPath ( stageDir. pathString)
219
+ try fm. removeItem ( atPath: srcDir. pathString)
235
220
}
236
221
237
222
func canBuild( _ platform: Workspace . PrebuiltsManifest . Platform ) -> Bool {
@@ -250,7 +235,9 @@ struct BuildPrebuilts: AsyncParsableCommand {
250
235
return docker && platform. os == . linux
251
236
}
252
237
253
- func shell( _ command: String) async throws {
238
+ func shell( _ command: String , cwd: AbsolutePath ) async throws {
239
+ _ = FileManager . default. changeCurrentDirectoryPath ( cwd. pathString)
240
+
254
241
#if os(Windows)
255
242
let arguments = [ " C: \\ Windows \\ System32 \\ cmd.exe " , " /c " , command]
256
243
#else
@@ -277,40 +264,6 @@ struct BuildPrebuilts: AsyncParsableCommand {
277
264
#endif
278
265
}
279
266
}
280
-
281
- func downloadManifest( version: PrebuiltRepos . Version) async throws -> Workspace. PrebuiltsManifest ? {
282
- let fm = FileManager . default
283
- let manifestFile = swiftVersion + " -manifest.json "
284
- let destination = stageDir. appending ( components: version. tag, manifestFile)
285
- if fm. fileExists ( atPath: destination. pathString) {
286
- do {
287
- return try JSONDecoder ( ) . decode (
288
- Workspace . PrebuiltsManifest. self,
289
- from: Data ( contentsOf: destination. asURL)
290
- )
291
- } catch {
292
- // redownload it
293
- try fm. removeItem ( atPath: destination. pathString)
294
- }
295
- }
296
- let manifestURL = manifestHost. appending ( components: version. tag, manifestFile)
297
- print ( " Downloading: " , manifestURL. absoluteString)
298
- let httpClient = HTTPClient ( )
299
- var headers = HTTPClientHeaders ( )
300
- headers. add ( name: " Accept " , value: " application/json " )
301
- var request = HTTPClient . Request ( kind: . generic( . get) , url: manifestURL)
302
- request. options. validResponseCodes = [ 200 ]
303
-
304
- let response = try ? await httpClient. execute ( request) { _, _ in }
305
- if let body = response? . body {
306
- return try JSONDecoder ( ) . decode (
307
- Workspace . PrebuiltsManifest. self,
308
- from: body
309
- )
310
- }
311
-
312
- return nil
313
- }
314
267
}
315
268
316
269
extension Workspace . PrebuiltsManifest . Platform {
0 commit comments