@@ -78,13 +78,14 @@ public func runProgram(_ args: String..., quiet: Bool = false) throws {
78
78
}
79
79
80
80
public func runProgramOutput( _ program: String , _ args: String ... ) async throws -> String ? {
81
+ print ( " \( program) \( args. joined ( separator: " " ) ) " )
82
+
81
83
let process = Process ( )
82
84
process. executableURL = URL ( fileURLWithPath: " /usr/bin/env " )
83
85
process. arguments = [ program] + args
84
86
85
87
let outPipe = Pipe ( )
86
88
process. standardInput = FileHandle . nullDevice
87
- process. standardError = FileHandle . nullDevice
88
89
process. standardOutput = outPipe
89
90
90
91
try process. run ( )
@@ -98,6 +99,7 @@ public func runProgramOutput(_ program: String, _ args: String...) async throws
98
99
process. waitUntilExit ( )
99
100
100
101
guard process. terminationStatus == 0 else {
102
+ print ( " \( args. first!) exited with non-zero status: \( process. terminationStatus) " )
101
103
throw Error ( message: " \( args. first!) exited with non-zero status: \( process. terminationStatus) " )
102
104
}
103
105
@@ -406,6 +408,10 @@ struct BuildSwiftlyRelease: AsyncParsableCommand {
406
408
try ? FileManager . default. createDirectory ( atPath: swiftlyLicenseDir, withIntermediateDirectories: true )
407
409
try await self . collectLicenses ( swiftlyLicenseDir)
408
410
411
+ let cwd = FileManager . default. currentDirectoryPath
412
+
413
+ let pkgFile = URL ( fileURLWithPath: cwd + " /.build/release/swiftly- \( self . version) .pkg " )
414
+
409
415
if let cert {
410
416
try runProgram (
411
417
pkgbuild,
@@ -435,5 +441,25 @@ struct BuildSwiftlyRelease: AsyncParsableCommand {
435
441
" .build/release/swiftly- \( self . version) .pkg "
436
442
)
437
443
}
444
+
445
+ // Re-configure the pkg to prefer installs into the current user's home directory with the help of productbuild.
446
+ // Note that command-line installs can override this preference, but the GUI install will limit the choices.
447
+
448
+ let pkgFileReconfigured = URL ( fileURLWithPath: cwd + " /.build/release/swiftly- \( self . version) -reconfigured.pkg " )
449
+ let distFile = URL ( fileURLWithPath: cwd + " /.build/release/distribution.plist " )
450
+
451
+ try runProgram ( " productbuild " , " --synthesize " , " --package " , pkgFile. path, distFile. path)
452
+
453
+ var distFileContents = try String ( contentsOf: distFile, encoding: . utf8)
454
+ distFileContents = distFileContents. replacingOccurrences ( of: " <choices-outline> " , with: " <domains enable_anywhere= \" false \" enable_currentUserHome= \" true \" enable_localSystem= \" false \" /><choices-outline> " )
455
+ try distFileContents. write ( to: distFile, atomically: true , encoding: . utf8)
456
+
457
+ if let cert = cert {
458
+ try runProgram ( " productbuild " , " --distribution " , distFile. path, " --package-path " , pkgFile. path, " --sign " , cert, pkgFileReconfigured. path)
459
+ } else {
460
+ try runProgram ( " productbuild " , " --distribution " , distFile. path, " --package-path " , pkgFile. path, pkgFileReconfigured. path)
461
+ }
462
+ try FileManager . default. removeItem ( at: pkgFile)
463
+ try FileManager . default. copyItem ( atPath: pkgFileReconfigured. path, toPath: pkgFile. path)
438
464
}
439
465
}
0 commit comments