@@ -33,6 +33,7 @@ struct PrebuiltRepos: Identifiable {
33
33
let tag : String
34
34
let manifest : Workspace . PrebuiltsManifest
35
35
let cModulePaths : [ String : [ String ] ]
36
+ let addProduct : ( Workspace . PrebuiltsManifest . Library , AbsolutePath ) async throws -> ( )
36
37
37
38
var id : String { tag }
38
39
}
@@ -70,7 +71,53 @@ var prebuiltRepos: IdentifiableSet<PrebuiltRepos> = [
70
71
] ) ,
71
72
cModulePaths: [
72
73
" _SwiftSyntaxCShims " : [ " Sources " , " _SwiftSyntaxCShims " ]
73
- ]
74
+ ] ,
75
+ addProduct: { library, repoDir in
76
+ try await shell ( " swift package add-product \( library. name) --type static-library --targets \( library. products. joined ( separator: " " ) ) " , cwd: repoDir)
77
+ }
78
+ ) ,
79
+ . init(
80
+ tag: " 601.0.1 " ,
81
+ manifest: . init( libraries: [
82
+ . init(
83
+ name: " MacroSupport " ,
84
+ products: [
85
+ " SwiftBasicFormat " ,
86
+ " SwiftCompilerPlugin " ,
87
+ " SwiftDiagnostics " ,
88
+ " SwiftIDEUtils " ,
89
+ " SwiftOperators " ,
90
+ " SwiftParser " ,
91
+ " SwiftParserDiagnostics " ,
92
+ " SwiftRefactor " ,
93
+ " SwiftSyntax " ,
94
+ " SwiftSyntaxMacros " ,
95
+ " SwiftSyntaxMacroExpansion " ,
96
+ " SwiftSyntaxMacrosTestSupport " ,
97
+ " SwiftSyntaxMacrosGenericTestSupport " ,
98
+ ] ,
99
+ cModules: [
100
+ " _SwiftSyntaxCShims " ,
101
+ ]
102
+ ) ,
103
+
104
+ ] ) ,
105
+ cModulePaths: [
106
+ " _SwiftSyntaxCShims " : [ " Sources " , " _SwiftSyntaxCShims " ]
107
+ ] ,
108
+ addProduct: { library, repoDir in
109
+ // swift package add-product doesn't work here since it's now computed
110
+ let packageFile = repoDir. appending ( component: " Package.swift " )
111
+ var package = try String ( contentsOf: packageFile. asURL)
112
+ package . replace ( " products: products, " , with: """
113
+ products: products + [
114
+ .library(name: " \( library. name) " , type: .static, targets: [
115
+ \( library. products. map ( { " \" \( $0) \" " } ) . joined ( separator: " , " ) )
116
+ ])
117
+ ],
118
+ """ )
119
+ try package . write ( to: packageFile. asURL, atomically: true , encoding: . utf8)
120
+ }
74
121
) ,
75
122
]
76
123
) ,
@@ -183,8 +230,7 @@ struct BuildPrebuilts: AsyncParsableCommand {
183
230
var newLibraries : IdentifiableSet < Workspace . PrebuiltsManifest . Library > = [ ]
184
231
185
232
for library in version. manifest. libraries {
186
- // TODO: this is assuming products map to target names which is not always true
187
- try await shell ( " swift package add-product \( library. name) --type static-library --targets \( library. products. joined ( separator: " " ) ) " , cwd: repoDir)
233
+ try await version. addProduct ( library, repoDir)
188
234
189
235
for platform in Workspace . PrebuiltsManifest. Platform. allCases {
190
236
guard canBuild ( platform) else {
@@ -386,34 +432,35 @@ struct BuildPrebuilts: AsyncParsableCommand {
386
432
. appending ( RelativePath ( validating: path) )
387
433
}
388
434
389
- func shell( _ command: String , cwd: AbsolutePath ) async throws {
390
- _ = FileManager . default. changeCurrentDirectoryPath ( cwd. pathString)
435
+ }
436
+
437
+ func shell( _ command: String , cwd: AbsolutePath ) async throws {
438
+ _ = FileManager . default. changeCurrentDirectoryPath ( cwd. pathString)
391
439
392
440
#if os(Windows)
393
- let arguments = [ " C: \\ Windows \\ System32 \\ cmd.exe " , " /c " , command]
441
+ let arguments = [ " C: \\ Windows \\ System32 \\ cmd.exe " , " /c " , command]
394
442
#else
395
- let arguments = [ " /bin/bash " , " -c " , command]
443
+ let arguments = [ " /bin/bash " , " -c " , command]
396
444
#endif
397
- let process = AsyncProcess (
398
- arguments: arguments,
399
- outputRedirection: . none
400
- )
401
- print ( " Running: " , command)
402
- try process. launch ( )
403
- let result = try await process. waitUntilExit ( )
404
- switch result. exitStatus {
405
- case . terminated( code: let code) :
406
- if code != 0 {
407
- throw StringError ( " Command exited with code \( code) : \( command) " )
408
- }
445
+ let process = AsyncProcess (
446
+ arguments: arguments,
447
+ outputRedirection: . none
448
+ )
449
+ print ( " Running: " , command)
450
+ try process. launch ( )
451
+ let result = try await process. waitUntilExit ( )
452
+ switch result. exitStatus {
453
+ case . terminated( code: let code) :
454
+ if code != 0 {
455
+ throw StringError ( " Command exited with code \( code) : \( command) " )
456
+ }
409
457
#if os(Windows)
410
- case . abnormal( exception: let exception) :
411
- throw StringError ( " Command threw exception \( exception) : \( command) " )
458
+ case . abnormal( exception: let exception) :
459
+ throw StringError ( " Command threw exception \( exception) : \( command) " )
412
460
#else
413
- case . signalled( signal: let signal) :
414
- throw StringError ( " Command exited on signal \( signal) : \( command) " )
461
+ case . signalled( signal: let signal) :
462
+ throw StringError ( " Command exited on signal \( signal) : \( command) " )
415
463
#endif
416
- }
417
464
}
418
465
}
419
466
0 commit comments