@@ -22,6 +22,56 @@ import Foundation
2222enum CarthageUtils { }
2323
2424extension CarthageUtils {
25+ /// Package all required files for a Carthage release.
26+ ///
27+ /// - Parameters:
28+ /// - templateDir: The template project directory, contains the dummy Firebase library.
29+ /// - carthageJSONDir: Location of directory containing all JSON Carthage manifests.
30+ /// - artifacts: Release Artifacts from build.
31+ /// - rcNumber: The RC number.
32+ /// - Returns: The path to the root of the Carthage installation.
33+ static func packageCarthageRelease( templateDir: URL ,
34+ carthageJSONDir: URL ,
35+ artifacts: ZipBuilder . ReleaseArtifacts ,
36+ rcNumber: Int ? ) -> URL ? {
37+ guard let zipLocation = artifacts. carthageDir else { return nil }
38+
39+ do {
40+ print ( " Creating Carthage release... " )
41+ let carthagePath =
42+ zipLocation. deletingLastPathComponent ( ) . appendingPathComponent ( " carthage_build " )
43+ // Create a copy of the release directory since we'll be modifying it.
44+ let fileManager = FileManager . default
45+ fileManager. removeIfExists ( at: carthagePath)
46+ try fileManager. copyItem ( at: zipLocation, to: carthagePath)
47+
48+ // Package the Carthage distribution with the current directory structure.
49+ let carthageDir = zipLocation. deletingLastPathComponent ( ) . appendingPathComponent ( " carthage " )
50+ fileManager. removeIfExists ( at: carthageDir)
51+ var output = carthageDir. appendingPathComponent ( artifacts. firebaseVersion)
52+ if let rcNumber = args. rcNumber {
53+ output. appendPathComponent ( " rc \( rcNumber) " )
54+ } else {
55+ output. appendPathComponent ( " latest-non-rc " )
56+ }
57+ try fileManager. createDirectory ( at: output, withIntermediateDirectories: true )
58+ generateCarthageRelease ( fromPackagedDir: carthagePath,
59+ templateDir: templateDir,
60+ jsonDir: carthageJSONDir,
61+ artifacts: artifacts,
62+ outputDir: output)
63+
64+ // Remove the duplicated Carthage build directory.
65+ fileManager. removeIfExists ( at: carthagePath)
66+ print ( " Done creating Carthage release! Files written to \( output) " )
67+
68+ // Save the directory for later copying.
69+ return carthageDir
70+ } catch {
71+ fatalError ( " Could not copy output directory for Carthage build: \( error) " )
72+ }
73+ }
74+
2575 /// Generates all required files for a Carthage release.
2676 ///
2777 /// - Parameters:
@@ -31,18 +81,19 @@ extension CarthageUtils {
3181 /// - firebaseVersion: The version of the Firebase pod.
3282 /// - coreDiagnosticsPath: The path to the Core Diagnostics framework built for Carthage.
3383 /// - outputDir: The directory where all artifacts should be created.
34- static func generateCarthageRelease ( fromPackagedDir packagedDir : URL ,
35- templateDir : URL ,
36- jsonDir : URL ,
37- firebaseVersion : String ,
38- coreDiagnosticsPath : URL ,
39- outputDir: URL ) {
84+
85+ private static func generateCarthageRelease ( fromPackagedDir packagedDir : URL ,
86+ templateDir : URL ,
87+ jsonDir : URL ,
88+ artifacts : ZipBuilder . ReleaseArtifacts ,
89+ outputDir: URL ) {
4090 let directories : [ String ]
4191 do {
4292 directories = try FileManager . default. contentsOfDirectory ( atPath: packagedDir. path)
4393 } catch {
4494 fatalError ( " Could not get contents of Firebase directory to package Carthage build. \( error) " )
4595 }
96+ let firebaseVersion = artifacts. firebaseVersion
4697
4798 // Loop through each directory available and package it as a separate Zip file.
4899 for product in directories {
@@ -51,23 +102,20 @@ extension CarthageUtils {
51102
52103 // Parse the JSON file, ensure that we're not trying to overwrite a release.
53104 var jsonManifest = parseJSONFile ( fromDir: jsonDir, product: product)
54- guard jsonManifest [ firebaseVersion] == nil else {
55- print ( " Carthage release for \( product) \( firebaseVersion) already exists - skipping. " )
56- continue
105+ if !args. carthageSkipVersionCheck {
106+ guard jsonManifest [ firebaseVersion] == nil else {
107+ print ( " Carthage release for \( product) \( firebaseVersion) already exists - skipping. " )
108+ continue
109+ }
57110 }
58111
59- // Find all the .frameworks in this directory.
60- let allContents : [ String ]
61- do {
62- allContents = try FileManager . default. contentsOfDirectory ( atPath: fullPath. path)
63- } catch {
64- fatalError ( " Could not get contents of \( product) for Carthage build in order to add " +
65- " an Info.plist in each framework. \( error) " )
112+ // Make updates to all frameworks to make Carthage happy. We don't worry about xcframeworks
113+ // here.
114+ let allFileObjects = FileManager . default. enumerator ( atPath: fullPath. path) ? . allObjects
115+ guard let allFiles = allFileObjects as? [ String ] else {
116+ fatalError ( " Failed to get file list for Carthage construction at \( fullPath. path) " )
66117 }
67-
68- // Carthage will fail to install a framework if it doesn't have an Info.plist, even though
69- // they're not used for static frameworks. Generate one and write it to each framework.
70- let frameworks = allContents. filter { $0. hasSuffix ( " .framework " ) }
118+ let frameworks = allFiles. filter { $0. hasSuffix ( " .framework " ) }
71119 for framework in frameworks {
72120 let plistPath = fullPath. appendingPathComponents ( [ framework, " Info.plist " ] )
73121 // Drop the extension of the framework name.
@@ -93,17 +141,6 @@ extension CarthageUtils {
93141 } catch {
94142 fatalError ( " Could not copy \( noticesName) to FirebaseCore for Carthage build. \( error) " )
95143 }
96-
97- // Override the Core Diagnostics framework with one that includes the proper bit flipped.
98- let coreDiagnosticsFramework = Constants . coreDiagnosticsName + " .framework "
99- let destination = fullPath. appendingPathComponent ( coreDiagnosticsFramework)
100- do {
101- // Remove the existing framework and replace it with the newly compiled one.
102- try FileManager . default. removeItem ( at: destination)
103- try FileManager . default. copyItem ( at: coreDiagnosticsPath, to: destination)
104- } catch {
105- fatalError ( " Could not replace \( coreDiagnosticsFramework) during Carthage build. \( error) " )
106- }
107144 }
108145
109146 // Hash the contents of the directory to get a unique name for Carthage.
0 commit comments