-
Notifications
You must be signed in to change notification settings - Fork 1.6k
/
Copy pathlocalize_podfile.swift
executable file
·108 lines (93 loc) · 3.77 KB
/
localize_podfile.swift
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
#!/usr/bin/swift
/*
* Copyright 2019 Google
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
// Modify a Podfile to get any podspecs defined in the firebase-ios-sdk repo locally.
import Foundation
let arg_cnts: Int = .init(CommandLine.argc)
let podfile = CommandLine.arguments[1]
var releaseTesting = false
if arg_cnts > 2 {
releaseTesting = CommandLine.arguments[1 ..< arg_cnts].contains("release_testing")
}
// Always add these, since they may not be in the Podfile, but we still want the local
// versions when they're dependencies of other requested local pods.
let implicitPods = [
"FirebaseCore", "FirebaseInstallations", "Firebase",
"FirebaseAuth", "FirebaseABTesting",
"FirebaseRemoteConfig", "FirebaseCoreExtension",
"FirebaseAppCheckInterop", "FirebaseAuthInterop",
"FirebaseMessagingInterop", "FirebaseCoreInternal",
"FirebaseSessions", "FirebaseSharedSwift",
"FirebaseRemoteConfigInterop",
]
let binaryPods = [
"GoogleAppMeasurement",
"GoogleAppMeasurementOnDeviceConversion",
"FirebaseAnalytics",
]
var didImplicits = false
var fileContents = ""
do {
fileContents = try String(contentsOfFile: podfile, encoding: .utf8)
} catch {
fatalError("Could not read \(podfile). \(error)")
}
// Search the path upwards to find the root of the firebase-ios-sdk repo.
var url = URL(fileURLWithPath: FileManager().currentDirectoryPath)
while url.path != "/", url.lastPathComponent != "firebase-ios-sdk" {
url = url.deletingLastPathComponent()
}
let repo = url
let lines = fileContents.components(separatedBy: .newlines)
var outBuffer =
"source 'https://github.com/firebase/SpecsDev.git'\n" +
"source 'https://github.com/firebase/SpecsStaging.git'\n" +
"source 'https://cdn.cocoapods.org/'\n"
for line in lines {
var newLine = line.trimmingCharacters(in: .whitespacesAndNewlines)
let tokens = newLine.components(separatedBy: [" ", ","] as CharacterSet)
if tokens.first == "pod", !releaseTesting {
let podNameRaw = String(tokens[1]).replacingOccurrences(of: "'", with: "")
var podName = podNameRaw
// Firebase test Podfile's often use the Firebase subspec to access the
// desired pod. We want to get the requested pod directly.
if podNameRaw.starts(with: "Firebase/") {
podName = podName.replacingOccurrences(of: "Firebase/", with: "Firebase")
}
let podspec = repo.appendingPathComponent(podName + ".podspec").path
if !binaryPods.contains(podName), FileManager().fileExists(atPath: podspec) {
if didImplicits == false {
didImplicits = true
for implicit in implicitPods {
let implicitPodspec = repo.appendingPathComponent(implicit + ".podspec").path
outBuffer += "pod '\(implicit)', :path => '\(implicitPodspec)'\n"
}
}
newLine = "pod '\(podName)', :path => '\(podspec)'"
} else if podNameRaw.starts(with: "Firebase/") {
// Update closed source pods referenced via a subspec from the Firebase pod.
let firebasePodspec = repo.appendingPathComponent("Firebase.podspec").path
newLine = "pod '\(podNameRaw)', :path => '\(firebasePodspec)'"
}
}
outBuffer += newLine + "\n"
}
// Write out the changed file.
do {
try outBuffer.write(toFile: podfile, atomically: false, encoding: String.Encoding.utf8)
} catch {
fatalError("Failed to write \(podfile). \(error)")
}