forked from xamarin/GoogleApisForiOSComponents
-
-
Notifications
You must be signed in to change notification settings - Fork 30
Expand file tree
/
Copy pathcustom_externals_download.cake
More file actions
127 lines (98 loc) · 5.04 KB
/
custom_externals_download.cake
File metadata and controls
127 lines (98 loc) · 5.04 KB
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
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
class ExternalDownloadSource
{
public string Id { get; }
public string Version { get; }
public string ArchiveKey { get; }
public ExternalDownloadSource (string id, string version, string archiveKey)
{
Id = id;
Version = version;
ArchiveKey = archiveKey;
}
public string ArchiveFileName => $"{Id}-{Version}.tar.gz";
public string ExtractionRootName => $"{Id}-{Version}";
public string Url => $"https://dl.google.com/firebase/ios/analytics/{ArchiveKey}/{ArchiveFileName}";
}
// *.tar.gz URLs can be found in the podspecs (e.g., CocoaPods Specs repo paths), such as:
// FirebaseAnalytics: https://github.com/CocoaPods/Specs/tree/master/Specs/e/2/1/FirebaseAnalytics
// GoogleAppMeasurement: https://github.com/CocoaPods/Specs/tree/master/Specs/e/3/b/GoogleAppMeasurement
var ExternalDownloads = new Dictionary<string, ExternalDownloadSource> {
{ "FirebaseAnalytics", new ExternalDownloadSource ("FirebaseAnalytics", "12.10.0", "3c185b45848d98d8") },
{ "GoogleAppMeasurement", new ExternalDownloadSource ("GoogleAppMeasurement", "12.10.0", "5f5e4d8cb469941e") },
};
FilePath GetArchivePath (ExternalDownloadSource source, DirectoryPath externalsPath) =>
externalsPath.CombineWithFilePath (source.ArchiveFileName);
DirectoryPath GetExtractionRoot (ExternalDownloadSource source, DirectoryPath externalsPath) =>
externalsPath.Combine (source.ExtractionRootName);
void DownloadAndExtract (ExternalDownloadSource source, Func<bool> artifactsAlreadyPresent, Action<DirectoryPath, DirectoryPath, DeleteDirectorySettings> copyArtifacts)
{
var externalsPath = new DirectoryPath ("./externals");
if (artifactsAlreadyPresent ()) {
Information ($"{source.Id} artifacts already available in externals. Skipping download.");
return;
}
EnsureDirectoryExists (externalsPath);
var archivePath = GetArchivePath (source, externalsPath);
var extractionRoot = GetExtractionRoot (source, externalsPath);
var deleteSettings = new DeleteDirectorySettings { Recursive = true, Force = true };
if (DirectoryExists (extractionRoot))
DeleteDirectory (extractionRoot, deleteSettings);
if (FileExists (archivePath))
DeleteFile (archivePath);
DownloadArchive (source, archivePath);
var exitCode = ExtractArchive (source, externalsPath, archivePath);
if (exitCode != 0)
throw new Exception ($"tar failed with exit code {exitCode} while extracting {archivePath.GetFilename ()}.");
copyArtifacts (extractionRoot, externalsPath, deleteSettings);
DeleteDirectory (extractionRoot, deleteSettings);
DeleteFile (archivePath);
}
int ExtractArchive (ExternalDownloadSource source, DirectoryPath externalsPath, FilePath archivePath)
{
Information ($"Extracting {source.ArchiveFileName} into externals...");
return StartProcess ("tar", $"-xzf \"{archivePath.FullPath}\" -C \"{externalsPath.FullPath}\"");
}
void DownloadArchive (ExternalDownloadSource source, FilePath archivePath)
{
Information ($"Downloading {source.ArchiveFileName}...");
DownloadFile (source.Url, archivePath);
}
void FirebaseAnalyticsDownload ()
{
var source = ExternalDownloads["FirebaseAnalytics"];
DownloadAndExtract (
source,
() => DirectoryExists (new DirectoryPath ("./externals/FirebaseAnalytics.xcframework")),
(extractionRoot, externalsPath, deleteSettings) => {
var frameworkSource = extractionRoot.Combine ("Frameworks").Combine ("FirebaseAnalytics.xcframework");
var frameworkDestination = externalsPath.Combine ("FirebaseAnalytics.xcframework");
if (!DirectoryExists (frameworkSource))
throw new Exception ($"Expected FirebaseAnalytics.xcframework at {frameworkSource} after extraction.");
if (DirectoryExists (frameworkDestination))
DeleteDirectory (frameworkDestination, deleteSettings);
CopyDirectory (frameworkSource, frameworkDestination);
});
}
void GoogleAppMeasurementDownload ()
{
var source = ExternalDownloads["GoogleAppMeasurement"];
DownloadAndExtract (
source,
() => DirectoryExists (new DirectoryPath ("./externals/GoogleAppMeasurementIdentitySupport.xcframework")) &&
DirectoryExists (new DirectoryPath ("./externals/GoogleAppMeasurement.xcframework")),
(extractionRoot, externalsPath, deleteSettings) => {
var frameworkSource = extractionRoot.Combine ("Frameworks");
var identitySupportSource = frameworkSource.Combine ("GoogleAppMeasurementIdentitySupport.xcframework");
var measurementSource = frameworkSource.Combine ("GoogleAppMeasurement.xcframework");
var identitySupportDest = externalsPath.Combine ("GoogleAppMeasurementIdentitySupport.xcframework");
var measurementDest = externalsPath.Combine ("GoogleAppMeasurement.xcframework");
if (!DirectoryExists (identitySupportSource) || !DirectoryExists (measurementSource))
throw new Exception ($"Expected GoogleAppMeasurement xcframeworks at {frameworkSource} after extraction.");
if (DirectoryExists (identitySupportDest))
DeleteDirectory (identitySupportDest, deleteSettings);
if (DirectoryExists (measurementDest))
DeleteDirectory (measurementDest, deleteSettings);
CopyDirectory (identitySupportSource, identitySupportDest);
CopyDirectory (measurementSource, measurementDest);
});
}