@@ -368,14 +368,20 @@ public final class Package {
368
368
private func registerExitHandler( ) {
369
369
// Add a custom exit handler to cause the package's JSON representation
370
370
// to be dumped at exit, if requested. Emitting it to a separate file
371
- // keeps any of the manifest's stdout output from interfering with it.
371
+ // descriptor from stdout keeps any of the manifest's stdout output from
372
+ // interfering with it.
372
373
//
373
374
// FIXME: This doesn't belong here, but for now is the mechanism we use
374
375
// to get the interpreter to dump the package when attempting to load a
375
376
// manifest.
376
- if let optIdx = CommandLine . arguments. firstIndex ( of: " -json-output-file " ) {
377
- let jsonOutputFilePath = CommandLine . arguments [ optIdx + 1 ]
378
- dumpPackageAtExit ( self , to: jsonOutputFilePath)
377
+ //
378
+ // Warning: The `-fileno` flag is a contract between PackageDescription
379
+ // and libSwiftPM, and since different versions of the two can be used
380
+ // together, it isn't safe to rename or remove it.
381
+ if let optIdx = CommandLine . arguments. firstIndex ( of: " -fileno " ) {
382
+ if let jsonOutputFileDesc = Int32 ( CommandLine . arguments [ optIdx + 1 ] ) {
383
+ dumpPackageAtExit ( self , to: jsonOutputFileDesc)
384
+ }
379
385
}
380
386
}
381
387
}
@@ -621,14 +627,14 @@ func manifestToJSON(_ package: Package) -> String {
621
627
}
622
628
623
629
var errors : [ String ] = [ ]
624
- private var dumpInfo : ( package : Package , path : String ) ?
625
- private func dumpPackageAtExit( _ package : Package , to path : String ) {
630
+ private var dumpInfo : ( package : Package , fileDesc : Int32 ) ?
631
+ private func dumpPackageAtExit( _ package : Package , to fileDesc : Int32 ) {
626
632
func dump( ) {
627
633
guard let dumpInfo = dumpInfo else { return }
628
- guard let fd = fopen ( dumpInfo. path , " w " ) else { return }
634
+ guard let fd = fdopen ( dumpInfo. fileDesc , " w " ) else { return }
629
635
fputs ( manifestToJSON ( dumpInfo. package ) , fd)
630
636
fclose ( fd)
631
637
}
632
- dumpInfo = ( package , path )
638
+ dumpInfo = ( package , fileDesc )
633
639
atexit ( dump)
634
640
}
0 commit comments