forked from xamarin/GoogleApisForiOSComponents
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcommon.cake
212 lines (167 loc) · 6.7 KB
/
common.cake
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
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
#load "poco.cake"
void AddArtifactDependencies (List<Artifact> list, Artifact [] dependencies)
{
if (dependencies == null)
return;
list.AddRange (dependencies);
foreach (var dependency in dependencies)
AddArtifactDependencies (list, dependency.Dependencies);
}
void UpdateVersionInCsproj (Artifact artifact)
{
var componentGroup = artifact.ComponentGroup.ToString ();
var csprojPath = $"./source/{componentGroup}/{artifact.CsprojName}/{artifact.CsprojName}.csproj";
XmlPoke(csprojPath, "/Project/PropertyGroup/FileVersion", artifact.NugetVersion);
XmlPoke(csprojPath, "/Project/PropertyGroup/PackageVersion", artifact.NugetVersion);
}
void CreateAndInstallPodfile (Artifact artifact)
{
if (artifact.PodSpecs?.Length == 0)
return;
var podfile = new List<string> ();
var podfileBegin = new List<string> (PODFILE_BEGIN);
podfileBegin [0] = string.Format (podfileBegin [0], artifact.MinimunSupportedVersion);
podfile.AddRange (podfileBegin);
foreach (var podSpec in artifact.PodSpecs) {
if (podSpec.FrameworkSource != FrameworkSource.Pods)
continue;
if (podSpec.SubSpecs == null) {
podfile.Add ($"\tpod '{podSpec.Name}', '{podSpec.Version}'");
continue;
}
if (podSpec.UseDefaultSubspecs)
podfile.Add ($"\tpod '{podSpec.Name}', '{podSpec.Version}'");
foreach (var subSpec in podSpec.SubSpecs)
podfile.Add ($"\tpod '{podSpec.Name}/{subSpec}', '{podSpec.Version}'");
}
if (podfile.Count == PODFILE_BEGIN.Length)
return;
podfile.AddRange (PODFILE_END);
var podfilePath = $"./externals/{artifact.Id}";
EnsureDirectoryExists (podfilePath);
FileWriteLines ($"{podfilePath}/Podfile", podfile.ToArray ());
CocoaPodInstall (podfilePath);
}
void BuildSdkOnPodfile (Artifact artifact)
{
if (artifact.PodSpecs?.Length == 0)
return;
var platforms = new [] { Platform.iOSArm64, Platform.iOSArmV7, Platform.iOSSimulator64, Platform.iOSSimulator };
var podsProject = "./Pods/Pods.xcodeproj";
var workingDirectory = (DirectoryPath)$"./externals/{artifact.Id}";
foreach (var podSpec in artifact.PodSpecs)
{
if (podSpec.FrameworkSource != FrameworkSource.Pods || !podSpec.CanBeBuild)
continue;
var framework = $"{podSpec.FrameworkName}.framework";
var paths = GetDirectories($"{workingDirectory}/Pods/**/{framework}");
if (paths?.Count <= 0) {
BuildXcodeFatFramework (podsProject, podSpec.TargetName, platforms, libraryTitle: podSpec.FrameworkName, workingDirectory: workingDirectory);
CopyDirectory ($"{workingDirectory}/{framework}", $"./externals/{framework}");
} else {
foreach (var path in paths)
CopyDirectory (path, $"./externals/{framework}");
}
}
}
void CleanVisualStudioSolution ()
{
MSBuild(SOLUTION_PATH, c => {
c.Configuration = "Release";
c.Restore = true;
c.MaxCpuCount = 0;
c.Targets.Add("Clean");
});
var deleteDirectorySettings = new DeleteDirectorySettings {
Recursive = true,
Force = true
};
var bins = GetDirectories("./**/bin");
DeleteDirectories (bins, deleteDirectorySettings);
var objs = GetDirectories("./**/obj");
DeleteDirectories (objs, deleteDirectorySettings);
}
void BuildXcodeFatLibrary (FilePath xcodeProject, string target, Platform [] platforms, string libraryTitle = null, string librarySuffix = null, DirectoryPath workingDirectory = null)
{
if (!IsRunningOnUnix())
{
Warning("{0} is not available on the current platform.", "xcodebuild");
return;
}
libraryTitle = libraryTitle ?? target;
workingDirectory = workingDirectory ?? Directory("./externals/");
var libraryFile = (FilePath)(librarySuffix != null ? $"{libraryTitle}.{librarySuffix}" : $"{libraryTitle}");
var archsFiles = new List<FilePath> ();
var buildArch = new Action<string, string, FilePath>((sdk, arch, dest) => {
if (FileExists(dest))
return;
XCodeBuild(new XCodeBuildSettings
{
Project = workingDirectory.CombineWithFilePath(xcodeProject).ToString(),
Target = target,
Sdk = sdk,
Arch = arch,
Configuration = "Release",
});
var outputPath = workingDirectory.Combine("build").Combine($"Release-{sdk}").Combine (target).CombineWithFilePath($"lib{libraryTitle}.a");
CopyFile(outputPath, dest);
});
foreach (var platform in platforms) {
var archFile = $"{libraryTitle}-{platform.Arch}";
archsFiles.Add (archFile);
buildArch (platform.Sdk, platform.Arch, workingDirectory.CombineWithFilePath (archFile));
}
RunLipoCreate (workingDirectory, libraryTitle, archsFiles.ToArray ());
}
void BuildXcodeFatFramework (FilePath xcodeProject, string target, Platform [] platforms, string libraryTitle = null, string librarySuffix = null, DirectoryPath workingDirectory = null)
{
if (!IsRunningOnUnix ()) {
Warning("{0} is not available on the current platform.", "xcodebuild");
return;
}
libraryTitle = libraryTitle ?? target;
workingDirectory = workingDirectory ?? Directory("./externals/");
var libraryFile = (FilePath)(librarySuffix != null ? $"{libraryTitle}.{librarySuffix}" : $"{libraryTitle}");
var fatFramework = (DirectoryPath)$"{libraryTitle}.framework";
var fatFrameworkPath = workingDirectory.Combine (fatFramework);
var archsPaths = new List<FilePath> ();
var buildArch = new Action<string, string, DirectoryPath> ((sdk, arch, dest) => {
if (DirectoryExists (dest))
return;
XCodeBuild (new XCodeBuildSettings {
Project = workingDirectory.CombineWithFilePath (xcodeProject).ToString (),
Target = target,
Sdk = sdk,
Arch = arch,
Configuration = "Release",
});
var outputPath = workingDirectory.Combine ("build").Combine ($"Release-{sdk}").Combine (target).Combine (fatFramework);
CopyDirectory (outputPath, dest);
});
foreach (var platform in platforms) {
var archPath = (DirectoryPath)$"{libraryTitle}-{platform.Arch}.framework";
archsPaths.Add (archPath.CombineWithFilePath (libraryTitle));
buildArch (platform.Sdk, platform.Arch, workingDirectory.Combine (archPath));
if (!DirectoryExists (fatFrameworkPath))
CopyDirectory (workingDirectory.Combine (archPath), fatFrameworkPath);
}
RunLipoCreate (workingDirectory, fatFramework.CombineWithFilePath (libraryFile), archsPaths.ToArray ());
if (libraryTitle != target && FileExists (fatFrameworkPath.CombineWithFilePath (target)))
DeleteFile (fatFrameworkPath.CombineWithFilePath (target));
}
bool TargetExistsInXcodeProject (FilePath xcodeProject, string target, DirectoryPath workingDirectory = null)
{
workingDirectory = workingDirectory ?? Directory("./externals/");
var processSettings = new ProcessSettings {
Arguments = $"-project {workingDirectory.CombineWithFilePath (xcodeProject)} -list",
RedirectStandardOutput = true
};
using(var process = StartAndReturnProcess("xcodebuild", processSettings))
{
process.WaitForExit();
foreach (var line in process.GetStandardOutput ())
if (line.Contains (target))
return true;
return false;
}
}