Skip to content

Commit d4cdd22

Browse files
committed
Pivot to a synthesized product build and custom distribution plist
1 parent 8325ebc commit d4cdd22

File tree

2 files changed

+24
-21
lines changed

2 files changed

+24
-21
lines changed

Tools/build-swiftly-release/BuildSwiftlyRelease.swift

Lines changed: 24 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -215,14 +215,14 @@ struct BuildSwiftlyRelease: AsyncParsableCommand {
215215

216216
func checkSwiftRequirement() async throws -> String {
217217
guard !self.skip else {
218-
return try await self.assertTool("swift", message: "Please install swift and make sure that it is added to your path.")
218+
return try await self.assertTool("/usr/bin/swift", message: "Please install swift and make sure that it is added to your path.")
219219
}
220220

221221
guard let requiredSwiftVersion = try? self.findSwiftVersion() else {
222222
throw Error(message: "Unable to determine the required swift version for this version of swiftly. Please make sure that you `cd <swiftly_git_dir>` and there is a .swift-version file there.")
223223
}
224224

225-
let swift = try await self.assertTool("swift", message: "Please install swift \(requiredSwiftVersion) and make sure that it is added to your path.")
225+
let swift = try await self.assertTool("/usr/bin/swift", message: "Please install swift \(requiredSwiftVersion) and make sure that it is added to your path.")
226226

227227
// We also need a swift toolchain with the correct version
228228
guard let swiftVersion = try await runProgramOutput(swift, "--version"), swiftVersion.contains("Swift version \(requiredSwiftVersion)") else {
@@ -408,15 +408,15 @@ struct BuildSwiftlyRelease: AsyncParsableCommand {
408408

409409
let cwd = FileManager.default.currentDirectoryPath
410410

411+
let pkgFile = URL(fileURLWithPath: cwd + "/.build/release/swiftly-\(self.version).pkg")
412+
411413
if let cert {
412414
try runProgram(
413415
pkgbuild,
414416
"--root",
415417
swiftlyBinDir + "/..",
416418
"--install-location",
417419
"usr/local",
418-
"--scripts",
419-
"\(cwd)/scripts/package",
420420
"--version",
421421
self.version,
422422
"--identifier",
@@ -432,14 +432,32 @@ struct BuildSwiftlyRelease: AsyncParsableCommand {
432432
swiftlyBinDir + "/..",
433433
"--install-location",
434434
"usr/local",
435-
"--scripts",
436-
"\(cwd)/scripts/package",
437435
"--version",
438436
self.version,
439437
"--identifier",
440438
identifier,
441439
".build/release/swiftly-\(self.version).pkg"
442440
)
443441
}
442+
443+
// Re-configure the pkg to prefer installs into the current user's home directory with the help of productbuild.
444+
// Note that command-line installs can override this preference, but the GUI install will limit the choices.
445+
446+
let pkgFileReconfigured = URL(fileURLWithPath: cwd + "/.build/release/swiftly-\(self.version)-reconfigured.pkg")
447+
let distFile = URL(fileURLWithPath: cwd + "/.build/release/distribution.plist")
448+
449+
try runProgram("productbuild", "--synthesize", "--package", pkgFile.path, distFile.path)
450+
451+
var distFileContents = try String(contentsOf: distFile, encoding: .utf8)
452+
distFileContents = distFileContents.replacingOccurrences(of: "<choices-outline>", with: "<domains enable_anywhere=\"false\" enable_currentUserHome=\"true\" enable_localSystem=\"false\"/><choices-outline>")
453+
try distFileContents.write(to: distFile, atomically: true, encoding: .utf8)
454+
455+
if let cert = cert {
456+
try runProgram("productbuild", "--distribution", distFile.path, "--package-path", pkgFile.path, "--sign", cert, pkgFileReconfigured.path)
457+
} else {
458+
try runProgram("productbuild", "--distribution", distFile.path, "--package-path", pkgFile.path, pkgFileReconfigured.path)
459+
}
460+
try FileManager.default.removeItem(at: pkgFile)
461+
try FileManager.default.copyItem(atPath: pkgFileReconfigured.path, toPath: pkgFile.path)
444462
}
445463
}

scripts/package/postinstall

Lines changed: 0 additions & 15 deletions
This file was deleted.

0 commit comments

Comments
 (0)