@@ -83,7 +83,8 @@ public protocol ManifestLoaderProtocol {
83
83
baseURL: String ,
84
84
version: Version ? ,
85
85
manifestVersion: ManifestVersion ,
86
- fileSystem: FileSystem ?
86
+ fileSystem: FileSystem ? ,
87
+ diagnostics: DiagnosticsEngine ?
87
88
) throws -> Manifest
88
89
}
89
90
@@ -100,14 +101,17 @@ extension ManifestLoaderProtocol {
100
101
baseURL: String ,
101
102
version: Version ? = nil ,
102
103
manifestVersion: ManifestVersion ,
103
- fileSystem: FileSystem ? = nil
104
+ fileSystem: FileSystem ? = nil ,
105
+ diagnostics: DiagnosticsEngine ? = nil
104
106
) throws -> Manifest {
105
107
return try load (
106
108
packagePath: path,
107
109
baseURL: baseURL,
108
110
version: version,
109
111
manifestVersion: manifestVersion,
110
- fileSystem: fileSystem)
112
+ fileSystem: fileSystem,
113
+ diagnostics: diagnostics
114
+ )
111
115
}
112
116
}
113
117
@@ -163,14 +167,17 @@ public final class ManifestLoader: ManifestLoaderProtocol {
163
167
baseURL: String ,
164
168
version: Version ? ,
165
169
manifestVersion: ManifestVersion ,
166
- fileSystem: FileSystem ? = nil
170
+ fileSystem: FileSystem ? = nil ,
171
+ diagnostics: DiagnosticsEngine ? = nil
167
172
) throws -> Manifest {
168
173
return try loadFile (
169
174
path: Manifest . path ( atPackagePath: path, fileSystem: fileSystem ?? localFileSystem) ,
170
175
baseURL: baseURL,
171
176
version: version,
172
177
manifestVersion: manifestVersion,
173
- fileSystem: fileSystem)
178
+ fileSystem: fileSystem,
179
+ diagnostics: diagnostics
180
+ )
174
181
}
175
182
176
183
/// Create a manifest by loading a specific manifest file from the given `path`.
@@ -185,7 +192,8 @@ public final class ManifestLoader: ManifestLoaderProtocol {
185
192
baseURL: String ,
186
193
version: Version ? ,
187
194
manifestVersion: ManifestVersion ,
188
- fileSystem: FileSystem ? = nil
195
+ fileSystem: FileSystem ? = nil ,
196
+ diagnostics: DiagnosticsEngine ? = nil
189
197
) throws -> Manifest {
190
198
191
199
// Inform the delegate.
@@ -201,7 +209,8 @@ public final class ManifestLoader: ManifestLoaderProtocol {
201
209
let jsonString : String
202
210
do {
203
211
jsonString = try loadJSONString (
204
- path: inputPath, manifestVersion: manifestVersion, fs: fileSystem)
212
+ path: inputPath, manifestVersion: manifestVersion,
213
+ fs: fileSystem, diagnostics: diagnostics)
205
214
} catch let error as StringError {
206
215
throw ManifestParseError . invalidManifestFormat ( error. description)
207
216
}
@@ -248,19 +257,20 @@ public final class ManifestLoader: ManifestLoaderProtocol {
248
257
func loadJSONString(
249
258
path inputPath: AbsolutePath ,
250
259
manifestVersion: ManifestVersion ,
251
- fs: FileSystem ? = nil
260
+ fs: FileSystem ? = nil ,
261
+ diagnostics: DiagnosticsEngine ? = nil
252
262
) throws -> String {
253
263
// If we were given a filesystem, load via a temporary file.
254
264
if let fs = fs {
255
265
let contents = try fs. readFileContents ( inputPath)
256
266
let tmpFile = try TemporaryFile ( suffix: " .swift " )
257
267
try localFileSystem. writeFileContents ( tmpFile. path, bytes: contents)
258
- return try parse ( path: tmpFile. path, manifestVersion: manifestVersion)
268
+ return try parse ( path: tmpFile. path, manifestVersion: manifestVersion, diagnostics : diagnostics )
259
269
}
260
270
261
271
// Load directly if manifest caching is not enabled.
262
272
if !self . isManifestCachingEnabled {
263
- return try parse ( path: inputPath, manifestVersion: manifestVersion)
273
+ return try parse ( path: inputPath, manifestVersion: manifestVersion, diagnostics : diagnostics )
264
274
}
265
275
266
276
// Otherwise load via llbuild.
@@ -274,7 +284,8 @@ public final class ManifestLoader: ManifestLoaderProtocol {
274
284
/// Parse the manifest at the given path to JSON.
275
285
func parse(
276
286
path manifestPath: AbsolutePath ,
277
- manifestVersion: ManifestVersion
287
+ manifestVersion: ManifestVersion ,
288
+ diagnostics: DiagnosticsEngine ? = nil
278
289
) throws -> String {
279
290
self . delegate? . willParse ( manifest: manifestPath)
280
291
@@ -304,7 +315,7 @@ public final class ManifestLoader: ManifestLoaderProtocol {
304
315
cmd += [ resources. swiftCompiler. asString]
305
316
cmd += [ " --driver-mode=swift " ]
306
317
cmd += verbosity. ccArgs
307
- cmd += [ " -L " , runtimePath, " -lPackageDescription " , " -suppress-warnings " ]
318
+ cmd += [ " -L " , runtimePath, " -lPackageDescription " ]
308
319
cmd += interpreterFlags
309
320
cmd += [ manifestPath. asString]
310
321
@@ -317,10 +328,13 @@ public final class ManifestLoader: ManifestLoaderProtocol {
317
328
let result = try Process . popen ( arguments: cmd)
318
329
let output = try ( result. utf8Output ( ) + result. utf8stderrOutput ( ) ) . chuzzle ( )
319
330
320
- // We expect output from interpreter to be empty, if something was emitted
321
- // throw and report it.
322
- if let output = output {
323
- throw StringError ( output)
331
+ // Throw an error if there was a non-zero exit or emit the output
332
+ // produced by the process. A process output will usually mean there
333
+ // was a warning emitted by the Swift compiler.
334
+ if result. exitStatus != . terminated( code: 0 ) {
335
+ throw StringError ( output ?? " <unknown> " )
336
+ } else if let output = output {
337
+ diagnostics? . emit ( data: ManifestLoadingDiagnostic ( output: output) )
324
338
}
325
339
326
340
guard let json = try localFileSystem. readFileContents ( file. path) . asString else {
0 commit comments