Skip to content

Commit 4cc5450

Browse files
authored
Add argument for build root override. (#3864)
This will allow CI to give a directory on a volume that has more storage space, allowing the build to succeed.
1 parent 59db097 commit 4cc5450

File tree

3 files changed

+30
-3
lines changed

3 files changed

+30
-3
lines changed

ZipBuilder/Sources/ZipBuilder/FileManager+Utils.swift

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -110,9 +110,12 @@ public extension FileManager {
110110
/// Returns a deterministic path of a temporary directory for the given name. Note: This does
111111
/// *not* create the directory if it doesn't exist, merely generates the name for creation.
112112
func temporaryDirectory(withName name: String) -> URL {
113-
// Get access to the temporary directory.
113+
// Get access to the temporary directory. This could be passed in via `LaunchArgs`, or use the
114+
// default temporary directory.
114115
let tempDir: URL
115-
if #available(OSX 10.12, *) {
116+
if let root = LaunchArgs.shared.buildRoot {
117+
tempDir = root
118+
} else if #available(OSX 10.12, *) {
116119
tempDir = temporaryDirectory
117120
} else {
118121
tempDir = URL(fileURLWithPath: NSTemporaryDirectory())

ZipBuilder/Sources/ZipBuilder/LaunchArgs.swift

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@ extension FileManager: FileChecker {}
3939
struct LaunchArgs {
4040
/// Keys associated with the launch args. See `Usage` for descriptions of each flag.
4141
private enum Key: String, CaseIterable {
42+
case buildRoot
4243
case carthageDir
4344
case customSpecRepos
4445
case existingVersions
@@ -51,6 +52,9 @@ struct LaunchArgs {
5152
/// Usage description for the key.
5253
var usage: String {
5354
switch self {
55+
case .buildRoot:
56+
return "The root directory for build artifacts. If `nil`, a temporary directory will be " +
57+
"used."
5458
case .carthageDir:
5559
return "The directory pointing to all Carthage JSON manifests. Passing this flag enables" +
5660
"the Carthage build."
@@ -79,6 +83,9 @@ struct LaunchArgs {
7983
/// verify expected version numbers.
8084
let allSDKsPath: URL?
8185

86+
/// The root directory for build artifacts. If `nil`, a temporary directory will be used.
87+
let buildRoot: URL?
88+
8289
/// The directory pointing to all Carthage JSON manifests. Passing this flag enables the Carthage
8390
/// build.
8491
let carthageDir: URL?
@@ -105,6 +112,9 @@ struct LaunchArgs {
105112
/// A flag to update the Pod Repo or not.
106113
let updatePodRepo: Bool
107114

115+
/// The shared instance for processing launch args using default arguments.
116+
static let shared: LaunchArgs = LaunchArgs()
117+
108118
/// Initializes with values pulled from the instance of UserDefaults passed in.
109119
///
110120
/// - Parameters:
@@ -219,6 +229,20 @@ struct LaunchArgs {
219229
carthageDir = nil
220230
}
221231

232+
// Parse the Carthage directory key.
233+
if let buildRoot = defaults.string(forKey: Key.buildRoot.rawValue) {
234+
let url = URL(fileURLWithPath: buildRoot)
235+
guard fileChecker.directoryExists(at: url) else {
236+
LaunchArgs.exitWithUsageAndLog("Could not parse \(Key.buildRoot) key: value " +
237+
"passed in is not a file URL or the directory does not exist. Value: \(buildRoot)")
238+
}
239+
240+
self.buildRoot = url.standardizedFileURL
241+
} else {
242+
// No argument was passed in.
243+
buildRoot = nil
244+
}
245+
222246
updatePodRepo = defaults.bool(forKey: Key.updatePodRepo.rawValue)
223247
}
224248

ZipBuilder/Sources/ZipBuilder/main.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ do {
2525
}
2626

2727
// Get the launch arguments, parsed by user defaults.
28-
let args = LaunchArgs()
28+
let args = LaunchArgs.shared
2929

3030
// Keep timing for how long it takes to build the zip file for information purposes.
3131
let buildStart = Date()

0 commit comments

Comments
 (0)