Skip to content

Commit 2cc26bd

Browse files
authored
Add -localPodspecPath option (#4453)
1 parent 75b881f commit 2cc26bd

File tree

3 files changed

+65
-13
lines changed

3 files changed

+65
-13
lines changed

ZipBuilder/Sources/ZipBuilder/CocoaPodUtils.swift

Lines changed: 36 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -171,10 +171,14 @@ public enum CocoaPodUtils {
171171
let podsDir = projectDir.appendingPathComponent("Pods")
172172
var installedPods: [String: PodInfo] = [:]
173173
for (podName, version) in pods {
174-
let podDir = podsDir.appendingPathComponent(podName)
175-
guard FileManager.default.directoryExists(at: podDir) else {
176-
fatalError("Directory for \(podName) doesn't exist at \(podDir) - failed while getting " +
177-
"information for installed Pods.")
174+
var podDir = podsDir.appendingPathComponent(podName)
175+
// Make sure that pod got installed if it's not coming from a local podspec.
176+
if !FileManager.default.directoryExists(at: podDir) {
177+
guard let repoDir = LaunchArgs.shared.localPodspecPath else {
178+
fatalError("Directory for \(podName) doesn't exist at \(podDir) - failed while getting " +
179+
"information for installed Pods.")
180+
}
181+
podDir = repoDir
178182
}
179183
let dependencies = [String](deps[podName] ?? [])
180184
let podInfo = PodInfo(version: version, dependencies: dependencies, installedLocation: podDir)
@@ -304,12 +308,38 @@ public enum CocoaPodUtils {
304308
target 'FrameworkMaker' do\n
305309
"""
306310

311+
var versionsSpecified = false
312+
307313
// Loop through the subspecs passed in and use the actual Pod name.
308314
for pod in pods {
309-
let version = pod.version == nil ? "" : ", '\(pod.version!)'"
310-
podfile += " pod '\(pod.name)'" + version + "\n"
315+
podfile += " pod '\(pod.name)'"
316+
// Check if we want to use a local version of the podspec.
317+
if let localURL = LaunchArgs.shared.localPodspecPath,
318+
FileManager.default.fileExists(atPath: localURL.appendingPathComponent(pod.name + ".podspec").path) {
319+
podfile += ", :path => '\(localURL.path)'"
320+
} else if let podVersion = pod.version {
321+
podfile += ", '\(podVersion)'"
322+
}
323+
if pod.version != nil {
324+
// Don't add Google pods if versions were specified or we're doing a secondary install
325+
// to create module maps.
326+
versionsSpecified = true
327+
}
328+
podfile += "\n"
311329
}
312330

331+
// If we're using local pods, explicitly add Google* podspecs if they exist and there are no
332+
// explicit versions in the Podfile. Note there are versions for local podspecs if we're doing
333+
// the secondary install for module map building.
334+
if !versionsSpecified, let localURL = LaunchArgs.shared.localPodspecPath {
335+
let podspecs = try! FileManager.default.contentsOfDirectory(atPath: localURL.path)
336+
for podspec in podspecs {
337+
if podspec.starts(with: "Google"), podspec.hasSuffix(".podspec") {
338+
let podName = podspec.replacingOccurrences(of: ".podspec", with: "")
339+
podfile += " pod '\(podName)', :path => '\(localURL.path)/\(podspec)'\n"
340+
}
341+
}
342+
}
313343
podfile += "end"
314344
return podfile
315345
}

ZipBuilder/Sources/ZipBuilder/LaunchArgs.swift

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@ struct LaunchArgs {
4545
case customSpecRepos
4646
case existingVersions
4747
case keepBuildArtifacts
48+
case localPodspecPath
4849
case minimumIOSVersion
4950
case outputDir
5051
case releasingSDKs
@@ -72,6 +73,8 @@ struct LaunchArgs {
7273
"of type `ZipBuilder_FirebaseSDKs`."
7374
case .keepBuildArtifacts:
7475
return "A flag to indicate keeping (not deleting) the build artifacts."
76+
case .localPodspecPath:
77+
return "Path to override podspec search with local podspec."
7578
case .minimumIOSVersion:
7679
return "The minimum supported iOS version. The default is 9.0."
7780
case .outputDir:
@@ -118,6 +121,9 @@ struct LaunchArgs {
118121
/// A flag to keep the build artifacts after this script completes.
119122
let keepBuildArtifacts: Bool
120123

124+
/// Path to override podspec search with local podspec.
125+
let localPodspecPath: URL?
126+
121127
/// The minimum iOS Version to build for.
122128
let minimumIOSVersion: String
123129

@@ -238,6 +244,20 @@ struct LaunchArgs {
238244
outputDir = nil
239245
}
240246

247+
// Parse the local podspec search path.
248+
if let localPath = defaults.string(forKey: Key.localPodspecPath.rawValue) {
249+
let url = URL(fileURLWithPath: localPath)
250+
guard fileChecker.directoryExists(at: url) else {
251+
LaunchArgs.exitWithUsageAndLog("Could not parse \(Key.localPodspecPath) key: value " +
252+
"passed in is not a file URL or the directory does not exist. Value: \(localPath)")
253+
}
254+
255+
localPodspecPath = url.standardizedFileURL
256+
} else {
257+
// No argument was passed in.
258+
localPodspecPath = nil
259+
}
260+
241261
// Parse the release candidate number. Note: if the String passed in isn't an integer, ignore
242262
// it and don't fail since we can append something else to the filenames.
243263
if let rcFlag = defaults.string(forKey: Key.rc.rawValue),

ZipBuilder/Sources/ZipBuilder/ZipBuilder.swift

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -671,13 +671,15 @@ struct ZipBuilder {
671671
}
672672

673673
// Get all the frameworks contained in this directory.
674-
var foundFrameworks: [URL]
675-
do {
676-
foundFrameworks = try fileManager.recursivelySearch(for: .frameworks,
677-
in: podInfo.installedLocation)
678-
} catch {
679-
fatalError("Cannot search for .framework files in Pods directory " +
680-
"\(podInfo.installedLocation): \(error)")
674+
var foundFrameworks: [URL] = []
675+
if podInfo.installedLocation != LaunchArgs.shared.localPodspecPath {
676+
do {
677+
foundFrameworks = try fileManager.recursivelySearch(for: .frameworks,
678+
in: podInfo.installedLocation)
679+
} catch {
680+
fatalError("Cannot search for .framework files in Pods directory " +
681+
"\(podInfo.installedLocation): \(error)")
682+
}
681683
}
682684

683685
// If there are no frameworks, it's an open source pod and we need to compile the source to

0 commit comments

Comments
 (0)