@@ -33,6 +33,7 @@ struct PrebuiltRepos: Identifiable {
3333 let tag : String
3434 let manifest : Workspace . PrebuiltsManifest
3535 let cModulePaths : [ String : [ String ] ]
36+ let addProduct : ( Workspace . PrebuiltsManifest . Library , AbsolutePath ) async throws -> ( )
3637
3738 var id : String { tag }
3839 }
@@ -70,7 +71,53 @@ var prebuiltRepos: IdentifiableSet<PrebuiltRepos> = [
7071 ] ) ,
7172 cModulePaths: [
7273 " _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+ }
74121 ) ,
75122 ]
76123 ) ,
@@ -183,8 +230,7 @@ struct BuildPrebuilts: AsyncParsableCommand {
183230 var newLibraries : IdentifiableSet < Workspace . PrebuiltsManifest . Library > = [ ]
184231
185232 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)
188234
189235 for platform in Workspace . PrebuiltsManifest. Platform. allCases {
190236 guard canBuild ( platform) else {
@@ -386,34 +432,35 @@ struct BuildPrebuilts: AsyncParsableCommand {
386432 . appending ( RelativePath ( validating: path) )
387433 }
388434
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)
391439
392440#if os(Windows)
393- let arguments = [ " C: \\ Windows \\ System32 \\ cmd.exe " , " /c " , command]
441+ let arguments = [ " C: \\ Windows \\ System32 \\ cmd.exe " , " /c " , command]
394442#else
395- let arguments = [ " /bin/bash " , " -c " , command]
443+ let arguments = [ " /bin/bash " , " -c " , command]
396444#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+ }
409457#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) " )
412460#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) " )
415463#endif
416- }
417464 }
418465}
419466
0 commit comments