@@ -509,18 +509,13 @@ struct FrameworkBuilder {
509
509
510
510
// Move all the Resources into .bundle directories in the destination Resources dir. The
511
511
// Resources live are contained within the folder structure:
512
- // `projectDir/arch/Release-platform/FrameworkName`
512
+ // `projectDir/arch/Release-platform/FrameworkName`.
513
+ // The Resources are stored at the top-level of the .framework or .xcframework directory.
514
+ // For Firebase distributions, they are propagated one level higher in the final distribution.
513
515
514
- let contentsDir = projectDir. appendingPathComponents ( [ anyArch. rawValue,
515
- " Release- \( anyArch. platform. rawValue) " ,
516
- framework] )
517
- let resourceDir = frameworkDir. appendingPathComponent ( " Resources " )
518
- do {
519
- try ResourcesManager . moveAllBundles ( inDirectory: contentsDir, to: resourceDir)
520
- } catch {
521
- fatalError ( " Could not move bundles into Resources directory while building \( framework) : " +
522
- " \( error) " )
523
- }
516
+ let resourceContents = projectDir. appendingPathComponents ( [ anyArch. rawValue,
517
+ " Release- \( anyArch. platform. rawValue) " ,
518
+ framework] )
524
519
525
520
guard let moduleMapContentsTemplate = podInfo. moduleMapContents else {
526
521
fatalError ( " Module map contents missing for framework \( framework) " )
@@ -529,6 +524,7 @@ struct FrameworkBuilder {
529
524
let xcframework = packageXCFramework ( withName: framework,
530
525
fromFolder: frameworkDir,
531
526
thinArchives: thinArchives,
527
+ resourceContents: resourceContents,
532
528
moduleMapContents: moduleMapContents)
533
529
534
530
var carthageFramework : URL ?
@@ -545,6 +541,7 @@ struct FrameworkBuilder {
545
541
carthageFramework = packageCarthageFramework ( withName: framework,
546
542
fromFolder: frameworkDir,
547
543
thinArchives: carthageThinArchives,
544
+ resourceContents: resourceContents,
548
545
moduleMapContents: moduleMapContents)
549
546
}
550
547
// Remove the temporary thin archives.
@@ -697,10 +694,12 @@ struct FrameworkBuilder {
697
694
/// - Parameter withName: The framework name.
698
695
/// - Parameter fromFolder: The almost complete framework folder. Includes everything but the binary.
699
696
/// - Parameter thinArchives: All the thin archives.
697
+ /// - Parameter resourceContents: Location of the resources for this xcframework.
700
698
/// - Parameter moduleMapContents: Module map contents for all frameworks in this pod.
701
699
private func packageXCFramework( withName framework: String ,
702
700
fromFolder: URL ,
703
701
thinArchives: [ Architecture : URL ] ,
702
+ resourceContents: URL ,
704
703
moduleMapContents: String ) -> URL {
705
704
let fileManager = FileManager . default
706
705
@@ -784,6 +783,17 @@ struct FrameworkBuilder {
784
783
case . success:
785
784
print ( " XCFramework for \( framework) built successfully at \( xcframework) . " )
786
785
}
786
+ // xcframework resources are packaged at top of xcframework. We do a copy instead of a move
787
+ // because the resources may also be copied for the Carthage distribution.
788
+ let resourceDir = xcframework. appendingPathComponent ( " Resources " )
789
+ do {
790
+ try ResourcesManager . moveAllBundles ( inDirectory: resourceContents,
791
+ to: resourceDir,
792
+ keepOriginal: true )
793
+ } catch {
794
+ fatalError ( " Could not move bundles into Resources directory while building \( framework) : " +
795
+ " \( error) " )
796
+ }
787
797
788
798
return xcframework
789
799
}
@@ -792,10 +802,12 @@ struct FrameworkBuilder {
792
802
/// - Parameter withName: The framework name.
793
803
/// - Parameter fromFolder: The almost complete framework folder. Includes everything but the binary.
794
804
/// - Parameter thinArchives: All the thin archives.
805
+ /// - Parameter resourceContents: Location of the resources for this Carthage framework.
795
806
/// - Parameter moduleMapContents: Module map contents for all frameworks in this pod.
796
807
private func packageCarthageFramework( withName framework: String ,
797
808
fromFolder: URL ,
798
809
thinArchives: [ Architecture : URL ] ,
810
+ resourceContents: URL ,
799
811
moduleMapContents: String ) -> URL {
800
812
let fileManager = FileManager . default
801
813
@@ -814,12 +826,31 @@ struct FrameworkBuilder {
814
826
let slices = thinArchives. filter { $0. key != Architecture . x86_64h }
815
827
816
828
// Package a normal .framework with the given slices.
817
- let destination = platformFrameworksDir. appendingPathComponent ( fromFolder. lastPathComponent)
829
+ let frameworkDir = platformFrameworksDir. appendingPathComponent ( fromFolder. lastPathComponent)
818
830
packageFramework ( withName: framework,
819
831
fromFolder: fromFolder,
820
832
thinArchives: slices,
821
- destination: destination ,
833
+ destination: frameworkDir ,
822
834
moduleMapContents: moduleMapContents)
823
- return destination
835
+
836
+ // Add Info.plist frameworks to make Carthage happy.
837
+ let plistPath = frameworkDir. appendingPathComponents ( [ " Info.plist " ] )
838
+ // Drop the extension of the framework name.
839
+ let plist = CarthageUtils . generatePlistContents ( forName: framework)
840
+ do {
841
+ try plist. write ( to: plistPath)
842
+ } catch {
843
+ fatalError ( " Could not copy plist for \( frameworkDir) for Carthage release. \( error) " )
844
+ }
845
+
846
+ // Carthage Resources are packaged in the framework.
847
+ let resourceDir = frameworkDir. appendingPathComponent ( " Resources " )
848
+ do {
849
+ try ResourcesManager . moveAllBundles ( inDirectory: resourceContents, to: resourceDir)
850
+ } catch {
851
+ fatalError ( " Could not move bundles into Resources directory while building \( framework) : " +
852
+ " \( error) " )
853
+ }
854
+ return frameworkDir
824
855
}
825
856
}
0 commit comments