Skip to content

Commit 2fe8a25

Browse files
authored
Fix Resource generation for Carthage xcframeworks (#8182)
1 parent 7a0679d commit 2fe8a25

File tree

2 files changed

+68
-40
lines changed

2 files changed

+68
-40
lines changed

ReleaseTooling/Sources/ZipBuilder/FirebaseBuilder.swift

Lines changed: 0 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -46,24 +46,6 @@ struct FirebaseBuilder {
4646
options: carthageBuildOptions
4747
)
4848

49-
// Prepare the release directory for zip packaging.
50-
do {
51-
// Move the Resources out of each directory in order to maintain the existing Zip structure.
52-
let fileManager = FileManager.default
53-
let contents = try fileManager.contentsOfDirectory(atPath: location.path)
54-
for fileOrFolder in contents {
55-
let fullPath = location.appendingPathComponent(fileOrFolder)
56-
57-
// Ignore any files.
58-
guard fileManager.isDirectory(at: fullPath) else { continue }
59-
60-
// Move all the bundles in the frameworks out to a common "Resources" directory to match the
61-
// existing Zip structure.
62-
let resourcesDir = fullPath.appendingPathComponent("Resources")
63-
_ = try ResourcesManager.moveAllBundles(inDirectory: fullPath, to: resourcesDir)
64-
}
65-
}
66-
6749
print("Attempting to Zip the directory...")
6850
let candidateName = "Firebase-\(firebaseVersion)-latest.zip"
6951
let zipped = Zip.zipContents(ofDir: location, name: candidateName)

ReleaseTooling/Sources/ZipBuilder/ZipBuilder.swift

Lines changed: 68 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -389,15 +389,16 @@ struct ZipBuilder {
389389
frameworksToAssemble: [String: [URL]],
390390
firebasePod: CocoaPodUtils.PodInfo) throws -> URL {
391391
// Create the directory that will hold all the contents of the Zip file.
392-
let zipDir = FileManager.default.temporaryDirectory(withName: packageKind)
392+
let fileManager = FileManager.default
393+
let zipDir = fileManager.temporaryDirectory(withName: packageKind)
393394
do {
394-
if FileManager.default.directoryExists(at: zipDir) {
395-
try FileManager.default.removeItem(at: zipDir)
395+
if fileManager.directoryExists(at: zipDir) {
396+
try fileManager.removeItem(at: zipDir)
396397
}
397398

398-
try FileManager.default.createDirectory(at: zipDir,
399-
withIntermediateDirectories: true,
400-
attributes: nil)
399+
try fileManager.createDirectory(at: zipDir,
400+
withIntermediateDirectories: true,
401+
attributes: nil)
401402
}
402403

403404
// Copy all required files from the Firebase pod. This will cause a fatalError if anything
@@ -452,28 +453,73 @@ struct ZipBuilder {
452453
rootZipDir: zipDir,
453454
builtFrameworks: frameworksToAssemble,
454455
podsToIgnore: analyticsPods)
455-
456456
// Update the README.
457457
readmeDeps += dependencyString(for: pod.key, in: productDir, frameworks: podFrameworks)
458-
459-
// Special case for Crashlytics:
460-
// Copy additional tools to avoid users from downloading another artifact to upload symbols.
461-
let crashlyticsPodName = "FirebaseCrashlytics"
462-
if pod.key == crashlyticsPodName {
463-
for file in ["upload-symbols", "run"] {
464-
let source = pod.value.installedLocation.appendingPathComponent(file)
465-
466-
let target = zipDir.appendingPathComponent(crashlyticsPodName)
467-
.appendingPathComponent(file)
468-
do {
469-
try FileManager.default.copyItem(at: source, to: target)
470-
} catch {
471-
fatalError("Error copying Crashlytics tools from \(source) to \(target): \(error)")
458+
} catch {
459+
fatalError("Could not copy frameworks from \(pod) into the zip file: \(error)")
460+
}
461+
do {
462+
// Update Resources: For the zip distribution, they get pulled from the xcframework to the
463+
// top-level product directory. For the Carthage distribution, they propagate to each
464+
// individual framework.
465+
// TODO: Investigate changing the zip distro to also have Resources in the .frameworks to
466+
// enable different platform Resources.
467+
let productPath = zipDir.appendingPathComponent(pod.key)
468+
let contents = try fileManager.contentsOfDirectory(atPath: productPath.path)
469+
for fileOrFolder in contents {
470+
let xcPath = productPath.appendingPathComponent(fileOrFolder)
471+
let xcResourceDir = xcPath.appendingPathComponent("Resources")
472+
473+
// Ignore anything that not an xcframework with Resources
474+
guard fileManager.isDirectory(at: xcPath),
475+
xcPath.lastPathComponent.hasSuffix("xcframework"),
476+
fileManager.directoryExists(at: xcResourceDir) else { continue }
477+
478+
if packageKind == "Firebase" {
479+
// Move all the bundles in the frameworks out to a common "Resources" directory to
480+
// match the existing Zip structure.
481+
let resourcesDir = productPath.appendingPathComponent("Resources")
482+
try fileManager.moveItem(at: xcResourceDir, to: resourcesDir)
483+
484+
} else {
485+
let xcContents = try fileManager.contentsOfDirectory(atPath: xcPath.path)
486+
for fileOrFolder in xcContents {
487+
let platformPath = xcPath.appendingPathComponent(fileOrFolder)
488+
guard fileManager.isDirectory(at: platformPath) else { continue }
489+
490+
let platformContents = try fileManager.contentsOfDirectory(atPath: platformPath.path)
491+
for fileOrFolder in platformContents {
492+
let frameworkPath = platformPath.appendingPathComponent(fileOrFolder)
493+
494+
// Ignore anything that not a framework.
495+
guard fileManager.isDirectory(at: frameworkPath),
496+
frameworkPath.lastPathComponent.hasSuffix("framework") else { continue }
497+
let resourcesDir = frameworkPath.appendingPathComponent("Resources")
498+
try fileManager.copyItem(at: xcResourceDir, to: resourcesDir)
499+
}
472500
}
501+
try fileManager.removeItem(at: xcResourceDir)
473502
}
474503
}
475504
} catch {
476-
fatalError("Could not copy frameworks from \(pod) into the zip file: \(error)")
505+
fatalError("Could not setup Resources for \(pod) for \(packageKind) \(error)")
506+
}
507+
508+
// Special case for Crashlytics:
509+
// Copy additional tools to avoid users from downloading another artifact to upload symbols.
510+
let crashlyticsPodName = "FirebaseCrashlytics"
511+
if pod.key == crashlyticsPodName {
512+
for file in ["upload-symbols", "run"] {
513+
let source = pod.value.installedLocation.appendingPathComponent(file)
514+
515+
let target = zipDir.appendingPathComponent(crashlyticsPodName)
516+
.appendingPathComponent(file)
517+
do {
518+
try fileManager.copyItem(at: source, to: target)
519+
} catch {
520+
fatalError("Error copying Crashlytics tools from \(source) to \(target): \(error)")
521+
}
522+
}
477523
}
478524
}
479525

0 commit comments

Comments
 (0)