@@ -389,15 +389,16 @@ struct ZipBuilder {
389
389
frameworksToAssemble: [ String : [ URL ] ] ,
390
390
firebasePod: CocoaPodUtils . PodInfo ) throws -> URL {
391
391
// 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)
393
394
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)
396
397
}
397
398
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 )
401
402
}
402
403
403
404
// Copy all required files from the Firebase pod. This will cause a fatalError if anything
@@ -452,28 +453,76 @@ struct ZipBuilder {
452
453
rootZipDir: zipDir,
453
454
builtFrameworks: frameworksToAssemble,
454
455
podsToIgnore: analyticsPods)
455
-
456
456
// Update the README.
457
457
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
+ }
472
503
}
504
+ try fileManager. removeItem ( at: xcResourceDir)
473
505
}
474
506
}
475
507
} 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
+ }
477
526
}
478
527
}
479
528
0 commit comments