Skip to content

Commit 2b9167f

Browse files
authored
Add signature cert and package identifier parameters to package script (#174)
When building macOS packages with pkgbuild, a signing certificate needs to be provided up-front, as is the package identifier. Change the package script so that it can accept the location of the certificate and override the package identifier. Add a note in the RELEASING.md about the --cert option for the release builder.
1 parent f627351 commit 2b9167f

File tree

2 files changed

+44
-15
lines changed

2 files changed

+44
-15
lines changed

RELEASING.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ Swift has a tool for producing final product packages, suitable for distribution
1313
5. Create a tag on that commit with the format "x.y.z". Do not omit "z", even if its value is 0.
1414

1515
6. Build the executables for the release by running `swift run build-swiftly-release <version>` from the root of the swiftly repository
16-
* Build on a Apple silicon macOS machine to produce a universal package for x86_64 and arm64
16+
* Build on an Apple macOS machine to produce a universal package for x86_64 and arm64 (add the --cert option to provide a signing certificate file for the .pkg)
1717
* Build on an Amazon Linux 2 image for x86_64
1818
* Build on an Amazon Linux 2 image for arm64
1919

Tools/build-swiftly-release/BuildSwiftlyRelease.swift

Lines changed: 43 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -182,6 +182,14 @@ struct BuildSwiftlyRelease: AsyncParsableCommand {
182182
@Flag(name: .long, help: "Skip the git repo checks and proceed.")
183183
var skip: Bool = false
184184

185+
#if os(macOS)
186+
@Option(help: "Installation certificate to use when building the macOS package")
187+
var cert: String?
188+
189+
@Option(help: "Package identifier of macOS package")
190+
var identifier: String = "org.swift.swiftly"
191+
#endif
192+
185193
@Argument(help: "Version of swiftly to build the release.")
186194
var version: String
187195

@@ -191,7 +199,7 @@ struct BuildSwiftlyRelease: AsyncParsableCommand {
191199
#if os(Linux)
192200
try await self.buildLinuxRelease()
193201
#elseif os(macOS)
194-
try await self.buildMacOSRelease()
202+
try await self.buildMacOSRelease(cert: self.cert, identifier: self.identifier)
195203
#else
196204
#error("Unsupported OS")
197205
#endif
@@ -234,6 +242,10 @@ struct BuildSwiftlyRelease: AsyncParsableCommand {
234242
}
235243

236244
func checkSwiftRequirement() async throws -> String {
245+
guard !self.skip else {
246+
return try await self.assertTool("swift", message: "Please install swift and make sure that it is added to your path.")
247+
}
248+
237249
guard let requiredSwiftVersion = try? self.findSwiftVersion() else {
238250
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.")
239251
}
@@ -361,7 +373,7 @@ struct BuildSwiftlyRelease: AsyncParsableCommand {
361373
print(releaseArchive)
362374
}
363375

364-
func buildMacOSRelease() async throws {
376+
func buildMacOSRelease(cert: String?, identifier: String) async throws {
365377
// Check system requirements
366378
let git = try await self.assertTool("git", message: "Please install git with either `xcode-select --install` or `brew install git`")
367379

@@ -389,17 +401,34 @@ struct BuildSwiftlyRelease: AsyncParsableCommand {
389401
try? FileManager.default.createDirectory(atPath: swiftlyLicenseDir, withIntermediateDirectories: true)
390402
try await self.collectLicenses(swiftlyLicenseDir)
391403

392-
try runProgram(
393-
pkgbuild,
394-
"--root",
395-
swiftlyBinDir + "/..",
396-
"--install-location",
397-
"usr/local",
398-
"--version",
399-
self.version,
400-
"--identifier",
401-
"org.swift.swiftly",
402-
".build/release/swiftly-\(self.version).pkg"
403-
)
404+
if let cert {
405+
try runProgram(
406+
pkgbuild,
407+
"--root",
408+
swiftlyBinDir + "/..",
409+
"--install-location",
410+
"usr/local",
411+
"--version",
412+
self.version,
413+
"--identifier",
414+
identifier,
415+
"--sign",
416+
cert,
417+
".build/release/swiftly-\(self.version).pkg"
418+
)
419+
} else {
420+
try runProgram(
421+
pkgbuild,
422+
"--root",
423+
swiftlyBinDir + "/..",
424+
"--install-location",
425+
"usr/local",
426+
"--version",
427+
self.version,
428+
"--identifier",
429+
identifier,
430+
".build/release/swiftly-\(self.version).pkg"
431+
)
432+
}
404433
}
405434
}

0 commit comments

Comments
 (0)