@@ -22,6 +22,56 @@ import Foundation
22
22
enum CarthageUtils { }
23
23
24
24
extension 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
+
25
75
/// Generates all required files for a Carthage release.
26
76
///
27
77
/// - Parameters:
@@ -31,18 +81,19 @@ extension CarthageUtils {
31
81
/// - firebaseVersion: The version of the Firebase pod.
32
82
/// - coreDiagnosticsPath: The path to the Core Diagnostics framework built for Carthage.
33
83
/// - 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 ) {
40
90
let directories : [ String ]
41
91
do {
42
92
directories = try FileManager . default. contentsOfDirectory ( atPath: packagedDir. path)
43
93
} catch {
44
94
fatalError ( " Could not get contents of Firebase directory to package Carthage build. \( error) " )
45
95
}
96
+ let firebaseVersion = artifacts. firebaseVersion
46
97
47
98
// Loop through each directory available and package it as a separate Zip file.
48
99
for product in directories {
@@ -51,23 +102,20 @@ extension CarthageUtils {
51
102
52
103
// Parse the JSON file, ensure that we're not trying to overwrite a release.
53
104
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
+ }
57
110
}
58
111
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) " )
66
117
}
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 " ) }
71
119
for framework in frameworks {
72
120
let plistPath = fullPath. appendingPathComponents ( [ framework, " Info.plist " ] )
73
121
// Drop the extension of the framework name.
@@ -93,17 +141,6 @@ extension CarthageUtils {
93
141
} catch {
94
142
fatalError ( " Could not copy \( noticesName) to FirebaseCore for Carthage build. \( error) " )
95
143
}
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
- }
107
144
}
108
145
109
146
// Hash the contents of the directory to get a unique name for Carthage.
0 commit comments