Skip to content

Commit 937a736

Browse files
authored
Remove support for cached zip builds. (#3574)
* Remove support for cached zip builds. This never really worked that well, and isn't used since we're now building the zip file on Kokoro. Quick iterations can be handled with changing the `podsToInstall` variable leaving this code outdated and unnecessary. * Remove unnecessary initializer.
1 parent 62af875 commit 937a736

File tree

5 files changed

+32
-189
lines changed

5 files changed

+32
-189
lines changed

ZipBuilder/Sources/ZipBuilder/CocoaPodUtils.swift

Lines changed: 1 addition & 84 deletions
Original file line numberDiff line numberDiff line change
@@ -31,17 +31,6 @@ public enum CocoaPodUtils {
3131

3232
/// The location of the pod on disk.
3333
var installedLocation: URL
34-
35-
/// A key that can be generated and used for identifying pods due to binary differences.
36-
var cacheKey: String?
37-
38-
/// Default initializer. Explicitly declared to take advantage of default arguments.
39-
init(name: String, version: String, installedLocation: URL, cacheKey: String? = nil) {
40-
self.name = name
41-
self.version = version
42-
self.installedLocation = installedLocation
43-
self.cacheKey = cacheKey
44-
}
4534
}
4635

4736
/// Executes the `pod cache clean --all` command to remove any cached CocoaPods.
@@ -97,14 +86,9 @@ public enum CocoaPodUtils {
9786
"information for installed Pods.")
9887
}
9988

100-
// Generate the cache key for this framework. We will use the list of subspecs used in the Pod
101-
// to generate this, since a Pod like GoogleUtilities could build different sources based on
102-
// what subspecs are included.
103-
let cacheKey = self.cacheKey(forPod: podName, fromPodfileLock: podfileLock)
10489
let podInfo = PodInfo(name: podName,
10590
version: version,
106-
installedLocation: podDir,
107-
cacheKey: cacheKey)
91+
installedLocation: podDir)
10892
installedPods.append(podInfo)
10993
}
11094

@@ -228,73 +212,6 @@ public enum CocoaPodUtils {
228212
return (framework, version)
229213
}
230214

231-
/// Generates a key representing the unique combination of all subspecs used for that Pod. This is
232-
/// necessary for Pods like GoogleUtilities, where we will need to include all subspecs as part of
233-
/// a build. Otherwise we could accidentally use a cached framework that doesn't include all the
234-
/// code necessary to function.
235-
///
236-
/// - Parameters:
237-
/// - framework: The framework being built.
238-
/// - podfileLock: The contents of the Podfile.lock for the project.
239-
/// - Returns: A key to describe the full set of subspecs used to build the framework, or an empty
240-
/// String if there were no specific subspecs used.
241-
private static func cacheKey(forPod podName: String,
242-
fromPodfileLock podfileLock: String) -> String? {
243-
// Ignore the umbrella Firebase pod, cacheing doesn't make sense.
244-
guard podName != "Firebase" else { return nil }
245-
246-
// Get the first section of the Podfile containing only Pods installed, the only thing we care
247-
// about.
248-
guard let podsInstalled = podfileLock.components(separatedBy: "DEPENDENCIES:").first else {
249-
fatalError("""
250-
Could not generate cache key for \(podName) from Podfile.lock contents - is this a valid
251-
Podfile.lock?
252-
---------- Podfile.lock contents ----------
253-
\(podfileLock)
254-
-------------------------------------------
255-
""")
256-
}
257-
258-
// Only get the lines that start with " - ", and have the framework we're looking for since
259-
// they are the top level pods that are installed.
260-
// Example result of a single line: `- GoogleUtilities/Environment (~> 5.2)`.
261-
let lines = podsInstalled.components(separatedBy: .newlines).filter {
262-
$0.hasPrefix(" - ") && $0.contains(podName)
263-
}
264-
265-
// Get a list of all the subspecs used to build this framework, and use that to generate the
266-
// cache key.
267-
var uniqueSubspecs = Set<String>()
268-
for line in lines.sorted() {
269-
// Separate the line into readable chunks, using a space and quote as a separator.
270-
// Example result: `["-", "GoogleUtilities/Environment", "(~>", "5.2)"]`.
271-
let components = line.components(separatedBy: CharacterSet(charactersIn: " \""))
272-
273-
// The Pod and subspec will be the only variables we care about, filter out the rest.
274-
// Example result: 'GoogleUtilities/Environment' or `FirebaseCore`. Only Pods with a subspec
275-
// should be included here, which are always in the format of `PodName/SubspecName`.
276-
guard let fullPodName = components.filter({ $0.contains("\(podName)/") }).first else {
277-
continue
278-
}
279-
280-
// The fullPodName will be something like `GoogleUtilities/UserDefaults`, get the subspec
281-
// name.
282-
let subspec = fullPodName.replacingOccurrences(of: "\(podName)/", with: "")
283-
if !subspec.isEmpty {
284-
uniqueSubspecs.insert(subspec)
285-
}
286-
}
287-
288-
// Return nil if there are no subpsecs used, since no cache key is necessary.
289-
guard !uniqueSubspecs.isEmpty else {
290-
return nil
291-
}
292-
293-
// Assemble the cache key based on the framework name, and all subspecs (sorted alphabetically
294-
// for repeatability) separated by a `+` (as was previously used).
295-
return podName + "+" + uniqueSubspecs.sorted().joined(separator: "+")
296-
}
297-
298215
/// Create the contents of a Podfile for an array of subspecs. This assumes the array of subspecs
299216
/// is not empty.
300217
private static func generatePodfile(for pods: [CocoaPod],

ZipBuilder/Sources/ZipBuilder/FrameworkBuilder.swift

Lines changed: 18 additions & 53 deletions
Original file line numberDiff line numberDiff line change
@@ -76,78 +76,43 @@ struct FrameworkBuilder {
7676
/// - Parameters:
7777
/// - framework: The name of the Framework being built.
7878
/// - version: String representation of the version.
79-
/// - cacheKey: The key used for caching this framework build. If nil, the framework name will
80-
/// be used.
81-
/// - cacheEnabled: Flag for enabling the cache. Defaults to false.
8279
/// - Parameter logsOutputDir: The path to the directory to place build logs.
8380
/// - Returns: A URL to the framework that was built (or pulled from the cache).
8481
public func buildFramework(withName podName: String,
8582
version: String,
86-
cacheKey: String?,
87-
cacheEnabled: Bool = false,
8883
logsOutputDir: URL? = nil) -> URL {
8984
print("Building \(podName)")
9085

91-
// Cache is temporarily disabled due to pod cache list issues.
92-
// Get the CocoaPods cache to see if we can pull from any frameworks already built.
93-
// let podsCache = CocoaPodUtils.listPodCache(inDir: projectDir)
94-
//
95-
// guard let cachedVersions = podsCache[podName] else {
96-
// fatalError("Cannot find a pod cache for framework \(podName).")
97-
// }
98-
//
99-
// guard let podInfo = cachedVersions[version] else {
100-
// fatalError("""
101-
// Cannot find a pod cache for framework \(podName) at version \(version).
102-
// Something could be wrong with your CocoaPods cache - try running the following:
103-
//
104-
// pod cache clean '\(podName)' --all
105-
// """)
106-
// }
107-
//
108-
// // TODO: Figure out if we need the MD5 at all.
109-
let md5 = podName
110-
// let md5 = Shell.calculateMD5(for: podInfo.installedLocation)
111-
11286
// Get (or create) the cache directory for storing built frameworks.
11387
let fileManager = FileManager.default
11488
var cachedFrameworkRoot: URL
11589
do {
11690
let cacheDir = try fileManager.firebaseCacheDirectory()
117-
cachedFrameworkRoot = cacheDir.appendingPathComponents([podName, version, md5])
118-
if let cacheKey = cacheKey {
119-
cachedFrameworkRoot.appendPathComponent(cacheKey)
120-
}
91+
cachedFrameworkRoot = cacheDir.appendingPathComponents([podName, version])
12192
} catch {
12293
fatalError("Could not create caches directory for building frameworks: \(error)")
12394
}
12495

12596
// Build the full cached framework path.
12697
let cachedFrameworkDir = cachedFrameworkRoot.appendingPathComponent("\(podName).framework")
127-
let cachedFrameworkExists = fileManager.directoryExists(at: cachedFrameworkDir)
128-
if cachedFrameworkExists, cacheEnabled {
129-
print("Framework \(podName) version \(version) has already been built and cached at " +
130-
"\(cachedFrameworkDir)")
131-
return cachedFrameworkDir
132-
} else {
133-
let frameworkDir = compileFrameworkAndResources(withName: podName)
134-
do {
135-
// Remove the previously cached framework, if it exists, otherwise the `moveItem` call will
136-
// fail.
137-
if cachedFrameworkExists {
138-
try fileManager.removeItem(at: cachedFrameworkDir)
139-
} else if !fileManager.directoryExists(at: cachedFrameworkRoot) {
140-
// If the root directory doesn't exist, create it so the `moveItem` will succeed.
141-
try fileManager.createDirectory(at: cachedFrameworkRoot,
142-
withIntermediateDirectories: true)
143-
}
144-
145-
// Move the newly built framework to the cache directory.
146-
try fileManager.moveItem(at: frameworkDir, to: cachedFrameworkDir)
147-
return cachedFrameworkDir
148-
} catch {
149-
fatalError("Could not move built frameworks into the cached frameworks directory: \(error)")
98+
let frameworkDir = compileFrameworkAndResources(withName: podName)
99+
do {
100+
// Remove the previously cached framework if it exists, otherwise the `moveItem` call will
101+
// fail.
102+
fileManager.removeDirectoryIfExists(at: cachedFrameworkDir)
103+
104+
// Create the root cache directory if it doesn't exist.
105+
if !fileManager.directoryExists(at: cachedFrameworkRoot) {
106+
// If the root directory doesn't exist, create it so the `moveItem` will succeed.
107+
try fileManager.createDirectory(at: cachedFrameworkRoot,
108+
withIntermediateDirectories: true)
150109
}
110+
111+
// Move the newly built framework to the cache directory.
112+
try fileManager.moveItem(at: frameworkDir, to: cachedFrameworkDir)
113+
return cachedFrameworkDir
114+
} catch {
115+
fatalError("Could not move built frameworks into the cached frameworks directory: \(error)")
151116
}
152117
}
153118

ZipBuilder/Sources/ZipBuilder/LaunchArgs.swift

Lines changed: 0 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -39,10 +39,8 @@ 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 cacheEnabled
4342
case carthageDir
4443
case customSpecRepos
45-
case deleteCache
4644
case existingVersions
4745
case outputDir
4846
case releasingSDKs
@@ -53,16 +51,11 @@ struct LaunchArgs {
5351
/// Usage description for the key.
5452
var usage: String {
5553
switch self {
56-
case .cacheEnabled:
57-
return "A flag to control using the cache for frameworks."
5854
case .carthageDir:
5955
return "The directory pointing to all Carthage JSON manifests. Passing this flag enables" +
6056
"the Carthage build."
6157
case .customSpecRepos:
6258
return "A comma separated list of custom CocoaPod Spec repos."
63-
case .deleteCache:
64-
return "A flag to empty the cache. Note: if this flag and the `cacheEnabled` flag is " +
65-
"set, it will fail since that's probably unintended."
6659
case .existingVersions:
6760
return "The file path to a textproto file containing the existing released SDK versions, " +
6861
"of type `ZipBuilder_FirebaseSDKs`."
@@ -106,12 +99,6 @@ struct LaunchArgs {
10699
/// based frameworks.
107100
let templateDir: URL
108101

109-
/// A flag to control using the cache for frameworks.
110-
let cacheEnabled: Bool
111-
112-
/// A flag to delete the cache from the cache directory.
113-
let deleteCache: Bool
114-
115102
/// The release candidate number, zero indexed.
116103
let rcNumber: Int?
117104

@@ -233,16 +220,6 @@ struct LaunchArgs {
233220
}
234221

235222
updatePodRepo = defaults.bool(forKey: Key.updatePodRepo.rawValue)
236-
237-
// Parse the cache keys. If no value is provided for each, it defaults to `false`.
238-
cacheEnabled = defaults.bool(forKey: Key.cacheEnabled.rawValue)
239-
deleteCache = defaults.bool(forKey: Key.deleteCache.rawValue)
240-
241-
if deleteCache, cacheEnabled {
242-
LaunchArgs.exitWithUsageAndLog("Invalid pair - attempted to delete the cache and enable " +
243-
"it at the same time. Please remove on of the keys and try " +
244-
"again.")
245-
}
246223
}
247224

248225
/// Prints an error that occurred, the proper usage String, and quits the application.

ZipBuilder/Sources/ZipBuilder/ZipBuilder.swift

Lines changed: 4 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -115,22 +115,15 @@ struct ZipBuilder {
115115
/// Paths needed throughout the process of packaging the Zip file.
116116
private let paths: FilesystemPaths
117117

118-
/// Determines if the cache should be used or not.
119-
private let useCache: Bool
120-
121118
/// Default initializer. If allSDKsPath and currentReleasePath are provided, it will also verify
122119
/// that the
123120
///
124121
/// - Parameters:
125122
/// - paths: Paths that are needed throughout the process of packaging the Zip file.
126123
/// - customSpecRepo: A custom spec repo to be used for fetching CocoaPods from.
127-
/// - useCache: Enables or disables the cache.
128-
init(paths: FilesystemPaths,
129-
customSpecRepos: [URL]? = nil,
130-
useCache: Bool = false) {
124+
init(paths: FilesystemPaths, customSpecRepos: [URL]? = nil) {
131125
self.paths = paths
132126
self.customSpecRepos = customSpecRepos
133-
self.useCache = useCache
134127
}
135128

136129
// TODO: This function contains a lot of "copy these paths to this directory, fail if there are
@@ -183,8 +176,8 @@ struct ZipBuilder {
183176
fatalError("Could not get contents of the README template: \(error)")
184177
}
185178

186-
// Break the `podsToInstall` into a variable since it's helpful when debugging non-cache builds
187-
// to just install a subset of pods, like the following line:
179+
// Break the `podsToInstall` into a variable since it's helpful when debugging builds to just
180+
// install a subset of pods, like the following line:
188181
// let podsToInstall: [CocoaPod] = [.core, .analytics, .storage]
189182
let podsToInstall = CocoaPod.allCases
190183

@@ -219,9 +212,7 @@ struct ZipBuilder {
219212

220213
// Generate the frameworks. Each key is the pod name and the URLs are all frameworks to be
221214
// copied in each product's directory.
222-
let frameworks = generateFrameworks(fromPods: installedPods,
223-
inProjectDir: projectDir,
224-
useCache: useCache)
215+
let frameworks = generateFrameworks(fromPods: installedPods, inProjectDir: projectDir)
225216

226217
for (framework, paths) in frameworks {
227218
print("Frameworks for pod: \(framework) were compiled at \(paths)")
@@ -683,7 +674,6 @@ struct ZipBuilder {
683674
/// .framework file already).
684675
private func generateFrameworks(fromPods pods: [CocoaPodUtils.PodInfo],
685676
inProjectDir projectDir: URL,
686-
useCache: Bool = false,
687677
carthageBuild: Bool = false) -> [String: [URL]] {
688678
// Verify the Pods folder exists and we can get the contents of it.
689679
let fileManager = FileManager.default
@@ -730,8 +720,6 @@ struct ZipBuilder {
730720
let builder = FrameworkBuilder(projectDir: projectDir)
731721
let framework = builder.buildFramework(withName: pod.name,
732722
version: pod.version,
733-
cacheKey: pod.cacheKey,
734-
cacheEnabled: useCache,
735723
logsOutputDir: paths.logsOutputDir)
736724

737725
frameworks = [framework]

ZipBuilder/Sources/ZipBuilder/main.swift

Lines changed: 9 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -16,19 +16,17 @@
1616

1717
import Foundation
1818

19+
// Delete the cache directory, if it exists.
20+
do {
21+
let cacheDir = try FileManager.default.firebaseCacheDirectory()
22+
FileManager.default.removeDirectoryIfExists(at: cacheDir)
23+
} catch {
24+
fatalError("Could not remove the cache before packaging the release: \(error)")
25+
}
26+
1927
// Get the launch arguments, parsed by user defaults.
2028
let args = LaunchArgs()
2129

22-
// Clear the cache if requested.
23-
if args.deleteCache {
24-
do {
25-
let cacheDir = try FileManager.default.firebaseCacheDirectory()
26-
try FileManager.default.removeItem(at: cacheDir)
27-
} catch {
28-
fatalError("Could not empty the cache before building the zip file: \(error)")
29-
}
30-
}
31-
3230
// Keep timing for how long it takes to build the zip file for information purposes.
3331
let buildStart = Date()
3432
var cocoaPodsUpdateMessage: String = ""
@@ -43,9 +41,7 @@ var paths = ZipBuilder.FilesystemPaths(templateDir: args.templateDir)
4341
paths.allSDKsPath = args.allSDKsPath
4442
paths.currentReleasePath = args.currentReleasePath
4543
paths.logsOutputDir = args.outputDir?.appendingPathComponent("build_logs")
46-
let builder = ZipBuilder(paths: paths,
47-
customSpecRepos: args.customSpecRepos,
48-
useCache: args.cacheEnabled)
44+
let builder = ZipBuilder(paths: paths, customSpecRepos: args.customSpecRepos)
4945

5046
do {
5147
// Build the zip file and get the path.

0 commit comments

Comments
 (0)