@@ -4,9 +4,7 @@ import Foundation
44
55enum PathKey : String {
66 case emitModulePath = " -emit-module-path "
7- case emitObjCHeaderPath = " -emit-objc-header-path "
87 case emitModuleSourceInfoPath = " -emit-module-source-info-path "
9- case serializeDiagnosticsPath = " -serialize-diagnostics-path "
108 case emitDependenciesPath = " -emit-dependencies-path "
119 case emitABIDescriptorPath = " -emit-abi-descriptor-path "
1210 case emitModuleDocPath = " -emit-module-doc-path "
@@ -19,18 +17,23 @@ func processArgs(
1917) async throws -> (
2018 isPreviewThunk: Bool ,
2119 isWMO: Bool ,
22- paths: [ PathKey : URL ]
20+ paths: [ PathKey : [ URL ] ]
2321) {
2422 var isPreviewThunk = false
2523 var isWMO = false
26- var paths : [ PathKey : URL ] = [ : ]
24+ var paths : [ PathKey : [ URL ] ] = [ : ]
2725
2826 var previousArg : String ?
2927 func processArg( _ arg: String ) {
3028 if let rawPathKey = previousArg,
3129 let key = PathKey ( rawValue: rawPathKey)
3230 {
33- paths [ key] = URL ( fileURLWithPath: arg)
31+ let url = URL ( fileURLWithPath: arg)
32+ if paths [ key] != nil {
33+ paths [ key] ? . append ( url)
34+ } else {
35+ paths [ key] = [ url]
36+ }
3437 previousArg = nil
3538 return
3639 }
@@ -80,17 +83,22 @@ extension URL {
8083 }
8184}
8285
86+ extension Array where Element == URL {
87+ mutating func touch( ) throws {
88+ for var url in self {
89+ try url. touch ( )
90+ }
91+ }
92+ }
93+
8394/// Touch the Xcode-required `.d` and `-master-emit-module.d` files
84- func touchDepsFiles( isWMO: Bool , paths: [ PathKey : URL ] ) throws {
85- guard let outputFileMapPath = paths [ PathKey . outputFileMap] else { return }
95+ func touchDepsFiles( isWMO: Bool , paths: [ PathKey : [ URL ] ] ) throws {
96+ guard let outputFileMapPaths = paths [ PathKey . outputFileMap] , let outputFileMapPath = outputFileMapPaths . first else { return }
8697
8798 if isWMO {
8899 let pathNoExtension = String ( outputFileMapPath. path. dropLast ( " -OutputFileMap.json " . count) )
89100 var masterDFilePath = URL ( fileURLWithPath: pathNoExtension + " -master.d " )
90101 try masterDFilePath. touch ( )
91-
92- var dFilePath = URL ( fileURLWithPath: pathNoExtension + " .d " )
93- try dFilePath. touch ( )
94102 } else {
95103 let data = try Data ( contentsOf: outputFileMapPath)
96104 let outputFileMapRaw = try JSONSerialization . jsonObject (
@@ -107,57 +115,49 @@ func touchDepsFiles(isWMO: Bool, paths: [PathKey: URL]) throws {
107115 var url = URL ( fileURLWithPath: dPath)
108116 try url. touch ( )
109117 }
110- if let dPath = entry [ " emit-module-dependencies " ] as? String {
111- var url = URL ( fileURLWithPath: dPath)
112- try url. touch ( )
113- }
114118 continue
115119 }
116120 }
117121}
118122
119123/// Touch the Xcode-required `-master-emit-module.d`, `.{d,abi.json}` and `.swift{module,doc,sourceinfo}` files
120- func touchSwiftmoduleArtifacts( paths: [ PathKey : URL ] ) throws {
121- if var swiftmodulePath = paths [ PathKey . emitModulePath] {
122- let pathNoExtension = swiftmodulePath. deletingPathExtension ( )
123- var swiftdocPath = pathNoExtension
124- . appendingPathExtension ( " swiftdoc " )
125- var swiftsourceinfoPath = pathNoExtension
126- . appendingPathExtension ( " swiftsourceinfo " )
127- var swiftinterfacePath = pathNoExtension
128- . appendingPathExtension ( " swiftinterface " )
129-
130- try swiftmodulePath. touch ( )
131- try swiftdocPath. touch ( )
132- try swiftsourceinfoPath. touch ( )
133- try swiftinterfacePath. touch ( )
134- }
135-
136- if var generatedHeaderPath = paths [ PathKey . emitObjCHeaderPath] {
137- try generatedHeaderPath. touch ( )
138- }
139-
140- if var path = paths [ PathKey . emitModuleSourceInfoPath] {
141- try path. touch ( )
124+ func touchSwiftmoduleArtifacts( paths: [ PathKey : [ URL ] ] ) throws {
125+ if let swiftmodulePaths = paths [ PathKey . emitModulePath] {
126+ for var swiftmodulePath in swiftmodulePaths {
127+ let pathNoExtension = swiftmodulePath. deletingPathExtension ( )
128+ var swiftdocPath = pathNoExtension
129+ . appendingPathExtension ( " swiftdoc " )
130+ var swiftsourceinfoPath = pathNoExtension
131+ . appendingPathExtension ( " swiftsourceinfo " )
132+ var swiftinterfacePath = pathNoExtension
133+ . appendingPathExtension ( " swiftinterface " )
134+
135+ try swiftmodulePath. touch ( )
136+ try swiftdocPath. touch ( )
137+ try swiftsourceinfoPath. touch ( )
138+ try swiftinterfacePath. touch ( )
139+ }
142140 }
143141
144- if var path = paths [ PathKey . serializeDiagnosticsPath ] {
145- try path . touch ( )
142+ if var modulePaths = paths [ PathKey . emitModuleSourceInfoPath ] {
143+ try modulePaths . touch ( )
146144 }
147145
148- if var path = paths [ PathKey . emitDependenciesPath] {
149- try path . touch ( )
146+ if var dependencyPaths = paths [ PathKey . emitDependenciesPath] {
147+ try dependencyPaths . touch ( )
150148 }
151149
152- if var path = paths [ PathKey . emitABIDescriptorPath] {
153- try path . touch ( )
150+ if var abiPaths = paths [ PathKey . emitABIDescriptorPath] {
151+ try abiPaths . touch ( )
154152 }
155153
156- if var path = paths [ PathKey . emitModuleDocPath] {
157- var swiftModulePath = path. deletingPathExtension ( )
158- . appendingPathExtension ( " swiftmodule " )
159- try swiftModulePath. touch ( )
160- try path. touch ( )
154+ if let docPaths = paths [ PathKey . emitModuleDocPath] {
155+ for var path in docPaths {
156+ var swiftModulePath = path. deletingPathExtension ( )
157+ . appendingPathExtension ( " swiftmodule " )
158+ try swiftModulePath. touch ( )
159+ try path. touch ( )
160+ }
161161 }
162162}
163163
@@ -170,8 +170,8 @@ func runSubProcess(executable: String, args: [String]) throws -> Int32 {
170170 return task. terminationStatus
171171}
172172
173- func handleXcodePreviewThunk( args: [ String ] , paths: [ PathKey : URL ] ) throws -> Never {
174- guard let sdkPath = paths [ PathKey . sdk] ? . path else {
173+ func handleXcodePreviewThunk( args: [ String ] , paths: [ PathKey : [ URL ] ] ) throws -> Never {
174+ guard let sdkPath = paths [ PathKey . sdk] ? . first ? . path else {
175175 fputs (
176176 " error: No such argument '-sdk'. Using /usr/bin/swiftc. " ,
177177 stderr
0 commit comments