forked from xamarin/XamarinComponents
-
Notifications
You must be signed in to change notification settings - Fork 0
/
common.cake
377 lines (317 loc) · 14.5 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
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
#tool nuget:?package=XamarinComponent&version=1.1.0.65
#addin nuget:?package=Cake.XCode&version=4.0.0
#addin nuget:?package=Cake.Xamarin.Build&version=4.0.0
#addin nuget:?package=Cake.Xamarin&version=3.0.0
#addin nuget:?package=Cake.FileHelpers&version=3.0.0
#addin nuget:?package=YamlDotNet&version=4.2.1
#addin nuget:?package=Cake.Yaml&version=2.1.0
#addin nuget:?package=Newtonsoft.Json&version=9.0.1
#addin nuget:?package=Cake.Json&version=3.0.1
#addin nuget:?package=Mono.ApiTools.NuGetDiff&version=1.0.1&loaddependencies=true
using Mono.ApiTools;
using NuGet.Packaging;
using NuGet.Versioning;
public enum TargetOS {
Windows,
Mac,
Android,
iOS,
tvOS,
}
void BuildXCodeFatLibrary(FilePath xcodeProject, string target, string libraryTitle = null, FilePath fatLibrary = null, DirectoryPath workingDirectory = null, string targetFolderName = null)
{
BuildXCodeFatLibrary_iOS(xcodeProject, target, libraryTitle, fatLibrary, workingDirectory, targetFolderName);
}
void BuildXCodeFatLibrary_iOS(FilePath xcodeProject, string target, string libraryTitle = null, FilePath fatLibrary = null, DirectoryPath workingDirectory = null, string targetFolderName = null)
{
if (!IsRunningOnUnix())
{
Warning("{0} is not available on the current platform.", "xcodebuild");
return;
}
libraryTitle = libraryTitle ?? target;
fatLibrary = fatLibrary ?? string.Format("lib{0}.a", libraryTitle);
workingDirectory = workingDirectory ?? Directory("./externals/");
var output = string.Format("lib{0}.a", libraryTitle);
var i386 = string.Format("lib{0}-i386.a", libraryTitle);
var x86_64 = string.Format("lib{0}-x86_64.a", libraryTitle);
var armv7 = string.Format("lib{0}-armv7.a", libraryTitle);
var armv7s = string.Format("lib{0}-armv7s.a", libraryTitle);
var arm64 = string.Format("lib{0}-arm64.a", libraryTitle);
var buildArch = new Action<string, string, FilePath>((sdk, arch, dest) => {
if (!FileExists(dest))
{
XCodeBuild(new XCodeBuildSettings
{
Project = workingDirectory.CombineWithFilePath(xcodeProject).ToString(),
Target = target,
Sdk = sdk,
Arch = arch,
Configuration = "Release",
});
var tmpOutputPath = workingDirectory.Combine("build").Combine("Release-" + sdk);
if (!string.IsNullOrEmpty (targetFolderName))
tmpOutputPath = tmpOutputPath.Combine (targetFolderName);
var outputPath = tmpOutputPath.CombineWithFilePath(output);
CopyFile(outputPath, dest);
}
});
buildArch("iphonesimulator", "i386", workingDirectory.CombineWithFilePath(i386));
buildArch("iphonesimulator", "x86_64", workingDirectory.CombineWithFilePath(x86_64));
buildArch("iphoneos", "armv7", workingDirectory.CombineWithFilePath(armv7));
buildArch("iphoneos", "armv7s", workingDirectory.CombineWithFilePath(armv7s));
buildArch("iphoneos", "arm64", workingDirectory.CombineWithFilePath(arm64));
RunLipoCreate(workingDirectory, fatLibrary, i386, x86_64, armv7, armv7s, arm64);
}
void BuildXCodeFatLibrary_tvOS(FilePath xcodeProject, string target, string libraryTitle = null, FilePath fatLibrary = null, DirectoryPath workingDirectory = null, string targetFolderName = null)
{
if (!IsRunningOnUnix())
{
Warning("{0} is not available on the current platform.", "xcodebuild");
return;
}
libraryTitle = libraryTitle ?? target;
fatLibrary = fatLibrary ?? string.Format("lib{0}.a", libraryTitle);
workingDirectory = workingDirectory ?? Directory("./externals/");
var output = string.Format("lib{0}.a", libraryTitle);
var x86_64 = string.Format("lib{0}-x86_64.a", libraryTitle);
var arm64 = string.Format("lib{0}-arm64.a", libraryTitle);
var buildArch = new Action<string, string, FilePath>((sdk, arch, dest) => {
if (!FileExists(dest))
{
XCodeBuild(new XCodeBuildSettings
{
Project = workingDirectory.CombineWithFilePath(xcodeProject).ToString(),
Target = target,
Sdk = sdk,
Arch = arch,
Configuration = "Release",
});
var tmpOutputPath = workingDirectory.Combine("build").Combine("Release-" + sdk);
if (!string.IsNullOrEmpty (targetFolderName))
tmpOutputPath = tmpOutputPath.Combine (targetFolderName);
var outputPath = tmpOutputPath.CombineWithFilePath(output);
CopyFile(outputPath, dest);
}
});
buildArch("appletvsimulator", "x86_64", workingDirectory.CombineWithFilePath(x86_64));
buildArch("appletvos", "arm64", workingDirectory.CombineWithFilePath(arm64));
RunLipoCreate(workingDirectory, fatLibrary, x86_64, arm64);
}
void BuildXCodeFatLibrary_macOS(FilePath xcodeProject, string target, string libraryTitle = null, FilePath fatLibrary = null, DirectoryPath workingDirectory = null, string targetFolderName = null)
{
if (!IsRunningOnUnix())
{
Warning("{0} is not available on the current platform.", "xcodebuild");
return;
}
// NOTE: 'i386' is no longer supported
libraryTitle = libraryTitle ?? target;
fatLibrary = fatLibrary ?? string.Format("lib{0}.a", libraryTitle);
workingDirectory = workingDirectory ?? Directory("./externals/");
var output = string.Format("lib{0}.a", libraryTitle);
// var i386 = string.Format("lib{0}-i386.a", libraryTitle);
var x86_64 = string.Format("lib{0}-x86_64.a", libraryTitle);
var buildArch = new Action<string, string, FilePath>((sdk, arch, dest) => {
if (!FileExists(dest))
{
XCodeBuild(new XCodeBuildSettings
{
Project = workingDirectory.CombineWithFilePath(xcodeProject).ToString(),
Target = target,
Sdk = sdk,
Arch = arch,
Configuration = "Release",
});
var tmpOutputPath = workingDirectory.Combine("build").Combine("Release");
if (!string.IsNullOrEmpty (targetFolderName))
tmpOutputPath = tmpOutputPath.Combine (targetFolderName);
var outputPath = tmpOutputPath.CombineWithFilePath(output);
CopyFile(outputPath, dest);
}
});
buildArch("macosx", "x86_64", workingDirectory.CombineWithFilePath(x86_64));
// buildArch("macosx", "i386", workingDirectory.CombineWithFilePath(i386));
RunLipoCreate(workingDirectory, fatLibrary, x86_64);
// RunLipoCreate(workingDirectory, fatLibrary, x86_64, i386);
}
void BuildXCode (FilePath project, string target, string libraryTitle, DirectoryPath workingDirectory, TargetOS os)
{
if (!IsRunningOnUnix ()) {
Warning("{0} is not available on the current platform.", "xcodebuild");
return;
}
var fatLibrary = string.Format("lib{0}.a", libraryTitle);
var output = string.Format ("lib{0}.a", libraryTitle);
var i386 = string.Format ("lib{0}-i386.a", libraryTitle);
var x86_64 = string.Format ("lib{0}-x86_64.a", libraryTitle);
var armv7 = string.Format ("lib{0}-armv7.a", libraryTitle);
var armv7s = string.Format ("lib{0}-armv7s.a", libraryTitle);
var arm64 = string.Format ("lib{0}-arm64.a", libraryTitle);
var buildArch = new Action<string, string, FilePath> ((sdk, arch, dest) => {
if (!FileExists (dest)) {
XCodeBuild (new XCodeBuildSettings {
Project = workingDirectory.CombineWithFilePath (project).ToString (),
Target = target,
Sdk = sdk,
Arch = arch,
Configuration = "Release",
});
var outputPath = workingDirectory.Combine ("build").Combine (os == TargetOS.Mac ? "Release" : ("Release-" + sdk)).Combine (target).CombineWithFilePath (output);
CopyFile (outputPath, dest);
}
});
if (os == TargetOS.Mac) {
// not supported anymore
// buildArch ("macosx", "i386", workingDirectory.CombineWithFilePath (i386));
buildArch ("macosx", "x86_64", workingDirectory.CombineWithFilePath (x86_64));
if (!FileExists (workingDirectory.CombineWithFilePath (fatLibrary))) {
RunLipoCreate (workingDirectory, fatLibrary, x86_64);
}
} else if (os == TargetOS.iOS) {
buildArch ("iphonesimulator", "i386", workingDirectory.CombineWithFilePath (i386));
buildArch ("iphonesimulator", "x86_64", workingDirectory.CombineWithFilePath (x86_64));
buildArch ("iphoneos", "armv7", workingDirectory.CombineWithFilePath (armv7));
buildArch ("iphoneos", "armv7s", workingDirectory.CombineWithFilePath (armv7s));
buildArch ("iphoneos", "arm64", workingDirectory.CombineWithFilePath (arm64));
if (!FileExists (workingDirectory.CombineWithFilePath (fatLibrary))) {
RunLipoCreate (workingDirectory, fatLibrary, i386, x86_64, armv7, armv7s, arm64);
}
} else if (os == TargetOS.tvOS) {
buildArch ("appletvsimulator", "x86_64", workingDirectory.CombineWithFilePath (x86_64));
buildArch ("appletvos", "arm64", workingDirectory.CombineWithFilePath (arm64));
if (!FileExists (workingDirectory.CombineWithFilePath (fatLibrary))) {
RunLipoCreate (workingDirectory, fatLibrary, x86_64, arm64);
}
}
}
void BuildDynamicXCode (FilePath project, string target, string libraryTitle, DirectoryPath workingDirectory, TargetOS os)
{
if (!IsRunningOnUnix ()) {
Warning("{0} is not available on the current platform.", "xcodebuild");
return;
}
var fatLibrary = (DirectoryPath)string.Format("{0}.framework", libraryTitle);
var fatLibraryPath = workingDirectory.Combine (fatLibrary);
var output = (DirectoryPath)string.Format ("{0}.framework", libraryTitle);
var i386 = (DirectoryPath)string.Format ("{0}-i386.framework", libraryTitle);
var x86_64 = (DirectoryPath)string.Format ("{0}-x86_64.framework", libraryTitle);
var armv7 = (DirectoryPath)string.Format ("{0}-armv7.framework", libraryTitle);
var armv7s = (DirectoryPath)string.Format ("{0}-armv7s.framework", libraryTitle);
var arm64 = (DirectoryPath)string.Format ("{0}-arm64.framework", libraryTitle);
var buildArch = new Action<string, string, DirectoryPath> ((sdk, arch, dest) => {
if (!DirectoryExists (dest)) {
XCodeBuild (new XCodeBuildSettings {
Project = workingDirectory.CombineWithFilePath (project).ToString (),
Target = target,
Sdk = sdk,
Arch = arch,
Configuration = "Release",
});
var outputPath = workingDirectory.Combine ("build").Combine (os == TargetOS.Mac ? "Release" : ("Release-" + sdk)).Combine (target).Combine (output);
CopyDirectory (outputPath, dest);
}
});
if (os == TargetOS.Mac) {
buildArch ("macosx", "x86_64", workingDirectory.Combine (x86_64));
if (!DirectoryExists (fatLibraryPath)) {
CopyDirectory (workingDirectory.Combine (x86_64), fatLibraryPath);
RunLipoCreate (workingDirectory, fatLibrary.CombineWithFilePath (libraryTitle),
x86_64.CombineWithFilePath (libraryTitle));
}
} else if (os == TargetOS.iOS) {
buildArch ("iphonesimulator", "i386", workingDirectory.Combine (i386));
buildArch ("iphonesimulator", "x86_64", workingDirectory.Combine (x86_64));
buildArch ("iphoneos", "armv7", workingDirectory.Combine (armv7));
buildArch ("iphoneos", "armv7s", workingDirectory.Combine (armv7s));
buildArch ("iphoneos", "arm64", workingDirectory.Combine (arm64));
if (!DirectoryExists (fatLibraryPath)) {
CopyDirectory (workingDirectory.Combine (arm64), fatLibraryPath);
RunLipoCreate (workingDirectory, fatLibrary.CombineWithFilePath (libraryTitle),
i386.CombineWithFilePath (libraryTitle),
x86_64.CombineWithFilePath (libraryTitle),
armv7.CombineWithFilePath (libraryTitle),
armv7s.CombineWithFilePath (libraryTitle),
arm64.CombineWithFilePath (libraryTitle));
}
} else if (os == TargetOS.tvOS) {
buildArch ("appletvsimulator", "x86_64", workingDirectory.Combine (x86_64));
buildArch ("appletvos", "arm64", workingDirectory.Combine (arm64));
if (!DirectoryExists (fatLibraryPath)) {
CopyDirectory (workingDirectory.Combine (arm64), fatLibraryPath);
RunLipoCreate (workingDirectory, fatLibrary.CombineWithFilePath (libraryTitle),
x86_64.CombineWithFilePath (libraryTitle),
arm64.CombineWithFilePath (libraryTitle));
}
}
}
void DownloadMonoSources (string tag, DirectoryPath dest, params string[] urls)
{
var rootUrl = $"https://github.com/mono/mono/raw/{tag}";
EnsureDirectoryExists (dest);
foreach (var originalUrl in urls) {
// make sure the urls are rooted
var url = originalUrl;
if (!url.StartsWith ("http:") && !url.StartsWith ("https:")) {
url = $"{rootUrl}/{url}";
}
// get the path parts
var file = url.Substring (url.LastIndexOf ("/") + 1);
var dir = url.Substring (0, url.LastIndexOf ("/"));
var destFile = dest.CombineWithFilePath (file);
// download the file
if (!FileExists (destFile)) {
Information ($"Downloading '{url}' to '{destFile}'...");
DownloadFile (url, destFile);
}
// if this is a .sources file, download all the listed files too
if (file.EndsWith (".sources")) {
var listedFiles = FileReadLines (destFile)
.Where (f => !f.StartsWith (".."))
.Select (f => $"{dir}/{f}")
.ToArray ();
DownloadMonoSources (tag, dest, listedFiles);
}
}
}
/// Api Diff Stuff
async Task BuildApiDiff (FilePath nupkg)
{
var baseDir = nupkg.GetDirectory(); //get the parent directory of the packge file
using (var reader = new PackageArchiveReader (nupkg.FullPath))
{
//get the id from the package and the version number
var packageId = reader.GetIdentity ().Id;
var currentVersionNo = reader.GetIdentity ().Version.ToNormalizedString();
//calculate the diff storage path from the location of the nuget
var diffRoot = $"{baseDir}/api-diff/{packageId}";
CleanDirectories (diffRoot);
// get the latest version of this package - if any
var latestVersion = (await NuGetVersions.GetLatestAsync (packageId))?.ToNormalizedString ();
// log what is going to happen
if (string.IsNullOrEmpty (latestVersion))
Information ($"Running a diff on a new package '{packageId}'...");
else
Information ($"Running a diff on '{latestVersion}' vs '{currentVersionNo}' of '{packageId}'...");
// create comparer
var comparer = new NuGetDiff ();
comparer.PackageCache = "./externals/package_cache"; // TODO: should this be a variable
comparer.SaveAssemblyApiInfo = true; // we don't keep this, but it lets us know if there were no changes
comparer.SaveAssemblyMarkdownDiff = true; // we want markdown
comparer.IgnoreResolutionErrors = true; // we don't care if frameowrk/platform types can't be found
await comparer.SaveCompleteDiffToDirectoryAsync (packageId, latestVersion, reader, diffRoot);
// run the diff with just the breaking changes
comparer.MarkdownDiffFileExtension = ".breaking.md";
comparer.IgnoreNonBreakingChanges = true;
await comparer.SaveCompleteDiffToDirectoryAsync (packageId, latestVersion, reader, diffRoot);
// TODO: there are two bugs in this version of mono-api-html
var mdFiles = $"{diffRoot}/*.*.md";
// 1. the <h4> doesn't look pretty in the markdown
ReplaceTextInFiles (mdFiles, "<h4>", "> ");
ReplaceTextInFiles (mdFiles, "</h4>", Environment.NewLine);
// 2. newlines are inccorect on Windows: https://github.com/mono/mono/pull/9918
ReplaceTextInFiles (mdFiles, "\r\r", "\r");
// we are done
Information ($"Diff complete of '{packageId}'.");
}
}