@@ -4,9 +4,7 @@ import Foundation
4
4
5
5
enum PathKey : String {
6
6
case emitModulePath = " -emit-module-path "
7
- case emitObjCHeaderPath = " -emit-objc-header-path "
8
7
case emitModuleSourceInfoPath = " -emit-module-source-info-path "
9
- case serializeDiagnosticsPath = " -serialize-diagnostics-path "
10
8
case emitDependenciesPath = " -emit-dependencies-path "
11
9
case emitABIDescriptorPath = " -emit-abi-descriptor-path "
12
10
case emitModuleDocPath = " -emit-module-doc-path "
@@ -19,18 +17,23 @@ func processArgs(
19
17
) async throws -> (
20
18
isPreviewThunk: Bool ,
21
19
isWMO: Bool ,
22
- paths: [ PathKey : URL ]
20
+ paths: [ PathKey : [ URL ] ]
23
21
) {
24
22
var isPreviewThunk = false
25
23
var isWMO = false
26
- var paths : [ PathKey : URL ] = [ : ]
24
+ var paths : [ PathKey : [ URL ] ] = [ : ]
27
25
28
26
var previousArg : String ?
29
27
func processArg( _ arg: String ) {
30
28
if let rawPathKey = previousArg,
31
29
let key = PathKey ( rawValue: rawPathKey)
32
30
{
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
+ }
34
37
previousArg = nil
35
38
return
36
39
}
@@ -80,17 +83,22 @@ extension URL {
80
83
}
81
84
}
82
85
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
+
83
94
/// 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 }
86
97
87
98
if isWMO {
88
99
let pathNoExtension = String ( outputFileMapPath. path. dropLast ( " -OutputFileMap.json " . count) )
89
100
var masterDFilePath = URL ( fileURLWithPath: pathNoExtension + " -master.d " )
90
101
try masterDFilePath. touch ( )
91
-
92
- var dFilePath = URL ( fileURLWithPath: pathNoExtension + " .d " )
93
- try dFilePath. touch ( )
94
102
} else {
95
103
let data = try Data ( contentsOf: outputFileMapPath)
96
104
let outputFileMapRaw = try JSONSerialization . jsonObject (
@@ -107,57 +115,49 @@ func touchDepsFiles(isWMO: Bool, paths: [PathKey: URL]) throws {
107
115
var url = URL ( fileURLWithPath: dPath)
108
116
try url. touch ( )
109
117
}
110
- if let dPath = entry [ " emit-module-dependencies " ] as? String {
111
- var url = URL ( fileURLWithPath: dPath)
112
- try url. touch ( )
113
- }
114
118
continue
115
119
}
116
120
}
117
121
}
118
122
119
123
/// 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
+ }
142
140
}
143
141
144
- if var path = paths [ PathKey . serializeDiagnosticsPath ] {
145
- try path . touch ( )
142
+ if var modulePaths = paths [ PathKey . emitModuleSourceInfoPath ] {
143
+ try modulePaths . touch ( )
146
144
}
147
145
148
- if var path = paths [ PathKey . emitDependenciesPath] {
149
- try path . touch ( )
146
+ if var dependencyPaths = paths [ PathKey . emitDependenciesPath] {
147
+ try dependencyPaths . touch ( )
150
148
}
151
149
152
- if var path = paths [ PathKey . emitABIDescriptorPath] {
153
- try path . touch ( )
150
+ if var abiPaths = paths [ PathKey . emitABIDescriptorPath] {
151
+ try abiPaths . touch ( )
154
152
}
155
153
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
+ }
161
161
}
162
162
}
163
163
@@ -170,8 +170,8 @@ func runSubProcess(executable: String, args: [String]) throws -> Int32 {
170
170
return task. terminationStatus
171
171
}
172
172
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 {
175
175
fputs (
176
176
" error: No such argument '-sdk'. Using /usr/bin/swiftc. " ,
177
177
stderr
0 commit comments