Skip to content

Commit 6fc928d

Browse files
committed
Fix Resource generation for Carthage xcframeworks
1 parent 1d9bb05 commit 6fc928d

File tree

2 files changed

+71
-40
lines changed

2 files changed

+71
-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: 71 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,76 @@ 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)
477+
else { continue }
478+
479+
if packageKind == "Firebase" {
480+
// Move all the bundles in the frameworks out to a common "Resources" directory to
481+
// match the existing Zip structure.
482+
let resourcesDir = productPath.appendingPathComponent("Resources")
483+
try fileManager.moveItem(at: xcResourceDir, to: resourcesDir)
484+
485+
} else {
486+
let xcContents = try fileManager.contentsOfDirectory(atPath: xcPath.path)
487+
for fileOrFolder in xcContents {
488+
let platformPath = xcPath.appendingPathComponent(fileOrFolder)
489+
guard fileManager.isDirectory(at: platformPath)
490+
else { continue }
491+
492+
let platformContents = try fileManager.contentsOfDirectory(atPath: platformPath.path)
493+
for fileOrFolder in platformContents {
494+
let frameworkPath = platformPath.appendingPathComponent(fileOrFolder)
495+
496+
// Ignore anything that not a framework.
497+
guard fileManager.isDirectory(at: frameworkPath),
498+
frameworkPath.lastPathComponent.hasSuffix("framework")
499+
else { continue }
500+
let resourcesDir = frameworkPath.appendingPathComponent("Resources")
501+
try fileManager.copyItem(at: xcResourceDir, to: resourcesDir)
502+
}
472503
}
504+
try fileManager.removeItem(at: xcResourceDir)
473505
}
474506
}
475507
} catch {
476-
fatalError("Could not copy frameworks from \(pod) into the zip file: \(error)")
508+
fatalError("Could not setup Resources for \(pod) for \(packageKind) \(error)")
509+
}
510+
511+
// Special case for Crashlytics:
512+
// Copy additional tools to avoid users from downloading another artifact to upload symbols.
513+
let crashlyticsPodName = "FirebaseCrashlytics"
514+
if pod.key == crashlyticsPodName {
515+
for file in ["upload-symbols", "run"] {
516+
let source = pod.value.installedLocation.appendingPathComponent(file)
517+
518+
let target = zipDir.appendingPathComponent(crashlyticsPodName)
519+
.appendingPathComponent(file)
520+
do {
521+
try fileManager.copyItem(at: source, to: target)
522+
} catch {
523+
fatalError("Error copying Crashlytics tools from \(source) to \(target): \(error)")
524+
}
525+
}
477526
}
478527
}
479528

0 commit comments

Comments
 (0)