forked from xamarin/AndroidSupportComponents
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbuild.cake
618 lines (488 loc) · 29.5 KB
/
build.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
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
// Loads our list of addins from the tools folder
// this assumes using the new bootstrapper build.sh in the root folder
// which downloads the required files
#load "./tools/addins.cake"
// From Cake.Xamarin.Build, dumps out versions of things
LogSystemInfo ();
var TARGET = Argument ("t", Argument ("target", "Default"));
var BUILD_CONFIG = Argument ("config", "Release");
// Lists all the artifacts and their versions for com.android.support.*
// https://dl.google.com/dl/android/maven2/com/android/support/group-index.xml
// Master list of all the packages in the repo:
// https://dl.google.com/dl/android/maven2/master-index.xml
var NUGET_VERSION = "26.1.0.1";
var COMPONENT_VERSION = "26.1.0.0";
var AAR_VERSION = "26.1.0";
var DOC_VERSION = "2017-10-02";
var SUPPORT_PKG_NAME = "com.android.support";
var ARCH_LIFECYCLE_PKG_NAME = "android.arch.lifecycle";
var ARCH_CORE_PKG_NAME = "android.arch.core";
// FROM: https://dl.google.com/android/repository/addon2-1.xml
var MAVEN_REPO_URL = "https://dl.google.com/dl/android/maven2/";
var BUILD_TOOLS_URL = "https://dl-ssl.google.com/android/repository/build-tools_r26-macosx.zip";
var ANDROID_SDK_VERSION = IsRunningOnWindows () ? "v8.0" : "android-26";
var RENDERSCRIPT_FOLDER = "android-8.0.0";
// We grab the previous release's api-info.xml to use as a comparison for this build's generated info to make an api-diff
var BASE_API_INFO_URL = "https://github.com/xamarin/AndroidSupportComponents/releases/download/25.4.0.2/api-info.xml";
var CPU_COUNT = System.Environment.ProcessorCount;
var USE_MSBUILD_ON_MAC = true;
// MSBUILD has issues on *nix/osx with a different CPU Count being specified
if (!IsRunningOnWindows())
CPU_COUNT = 1;
var ARTIFACTS = new [] {
new ArtifactInfo (ARCH_CORE_PKG_NAME, "common", "Xamarin.Android.Arch.Core.Common", "1.0.0", "1.0.0", "1.0.0.0", true) { PathPrefix = "arch-core/" },
new ArtifactInfo (ARCH_LIFECYCLE_PKG_NAME, "common", "Xamarin.Android.Arch.Lifecycle.Common", "1.0.1", "1.0.1", "1.0.1.0", true) { PathPrefix = "arch-lifecycle/" },
new ArtifactInfo (ARCH_LIFECYCLE_PKG_NAME, "runtime", "Xamarin.Android.Arch.Lifecycle.Runtime", "1.0.0", "1.0.0", "1.0.0.0") { PathPrefix = "arch-lifecycle/" },
//new ArtifactInfo (SUPPORT_PKG_NAME, "support-v4", "Xamarin.Android.Support.v4", AAR_VERSION, NUGET_VERSION, COMPONENT_VERSION),
new ArtifactInfo (SUPPORT_PKG_NAME, "support-v13", "Xamarin.Android.Support.v13", AAR_VERSION, NUGET_VERSION, COMPONENT_VERSION),
new ArtifactInfo (SUPPORT_PKG_NAME, "appcompat-v7", "Xamarin.Android.Support.v7.AppCompat", AAR_VERSION, NUGET_VERSION, COMPONENT_VERSION),
new ArtifactInfo (SUPPORT_PKG_NAME, "gridlayout-v7", "Xamarin.Android.Support.v7.GridLayout", AAR_VERSION, NUGET_VERSION, COMPONENT_VERSION),
new ArtifactInfo (SUPPORT_PKG_NAME, "mediarouter-v7", "Xamarin.Android.Support.v7.MediaRouter", AAR_VERSION, NUGET_VERSION, COMPONENT_VERSION),
new ArtifactInfo (SUPPORT_PKG_NAME, "recyclerview-v7", "Xamarin.Android.Support.v7.RecyclerView", AAR_VERSION, NUGET_VERSION, COMPONENT_VERSION),
new ArtifactInfo (SUPPORT_PKG_NAME, "palette-v7", "Xamarin.Android.Support.v7.Palette", AAR_VERSION, NUGET_VERSION, COMPONENT_VERSION),
new ArtifactInfo (SUPPORT_PKG_NAME, "cardview-v7", "Xamarin.Android.Support.v7.CardView", AAR_VERSION, NUGET_VERSION, COMPONENT_VERSION),
new ArtifactInfo (SUPPORT_PKG_NAME, "leanback-v17", "Xamarin.Android.Support.v17.Leanback", AAR_VERSION, NUGET_VERSION, COMPONENT_VERSION),
new ArtifactInfo (SUPPORT_PKG_NAME, "design", "Xamarin.Android.Support.Design", AAR_VERSION, NUGET_VERSION, COMPONENT_VERSION),
new ArtifactInfo (SUPPORT_PKG_NAME, "percent", "Xamarin.Android.Support.Percent", AAR_VERSION, NUGET_VERSION, COMPONENT_VERSION),
new ArtifactInfo (SUPPORT_PKG_NAME, "customtabs", "Xamarin.Android.Support.CustomTabs", AAR_VERSION, NUGET_VERSION, COMPONENT_VERSION),
new ArtifactInfo (SUPPORT_PKG_NAME, "preference-v7", "Xamarin.Android.Support.v7.Preference", AAR_VERSION, NUGET_VERSION, COMPONENT_VERSION),
new ArtifactInfo (SUPPORT_PKG_NAME, "preference-v14", "Xamarin.Android.Support.v14.Preference", AAR_VERSION, NUGET_VERSION, COMPONENT_VERSION),
new ArtifactInfo (SUPPORT_PKG_NAME, "preference-leanback-v17", "Xamarin.Android.Support.v17.Preference.Leanback", AAR_VERSION, NUGET_VERSION, COMPONENT_VERSION),
new ArtifactInfo (SUPPORT_PKG_NAME, "recommendation", "Xamarin.Android.Support.Recommendation", AAR_VERSION, NUGET_VERSION, COMPONENT_VERSION),
new ArtifactInfo (SUPPORT_PKG_NAME, "animated-vector-drawable", "Xamarin.Android.Support.Animated.Vector.Drawable", AAR_VERSION, NUGET_VERSION, COMPONENT_VERSION),
new ArtifactInfo (SUPPORT_PKG_NAME, "support-vector-drawable", "Xamarin.Android.Support.Vector.Drawable", AAR_VERSION, NUGET_VERSION, COMPONENT_VERSION),
new ArtifactInfo (SUPPORT_PKG_NAME, "support-compat", "Xamarin.Android.Support.Compat", AAR_VERSION, NUGET_VERSION, COMPONENT_VERSION),
new ArtifactInfo (SUPPORT_PKG_NAME, "support-core-utils", "Xamarin.Android.Support.Core.Utils", AAR_VERSION, NUGET_VERSION, COMPONENT_VERSION),
new ArtifactInfo (SUPPORT_PKG_NAME, "support-core-ui", "Xamarin.Android.Support.Core.UI", AAR_VERSION, NUGET_VERSION, COMPONENT_VERSION),
new ArtifactInfo (SUPPORT_PKG_NAME, "support-dynamic-animation", "Xamarin.Android.Support.Dynamic.Animation", AAR_VERSION, NUGET_VERSION, COMPONENT_VERSION),
new ArtifactInfo (SUPPORT_PKG_NAME, "support-media-compat", "Xamarin.Android.Support.Media.Compat", AAR_VERSION, NUGET_VERSION, COMPONENT_VERSION),
new ArtifactInfo (SUPPORT_PKG_NAME, "support-fragment", "Xamarin.Android.Support.Fragment", AAR_VERSION, NUGET_VERSION, COMPONENT_VERSION),
new ArtifactInfo (SUPPORT_PKG_NAME, "support-tv-provider", "Xamarin.Android.Support.TV.Provider", AAR_VERSION, NUGET_VERSION, COMPONENT_VERSION),
new ArtifactInfo (SUPPORT_PKG_NAME, "transition", "Xamarin.Android.Support.Transition", AAR_VERSION, NUGET_VERSION, COMPONENT_VERSION),
new ArtifactInfo (SUPPORT_PKG_NAME, "exifinterface", "Xamarin.Android.Support.Exif", AAR_VERSION, NUGET_VERSION, COMPONENT_VERSION),
new ArtifactInfo (SUPPORT_PKG_NAME, "wear", "Xamarin.Android.Support.Wear", AAR_VERSION, NUGET_VERSION, COMPONENT_VERSION),
new ArtifactInfo (SUPPORT_PKG_NAME, "support-annotations", "Xamarin.Android.Support.Annotations", AAR_VERSION, NUGET_VERSION, COMPONENT_VERSION, true),
new ArtifactInfo (SUPPORT_PKG_NAME, "support-emoji", "Xamarin.Android.Support.Emoji", AAR_VERSION, NUGET_VERSION, COMPONENT_VERSION),
new ArtifactInfo (SUPPORT_PKG_NAME, "support-emoji-appcompat", "Xamarin.Android.Support.Emoji.AppCompat", AAR_VERSION, NUGET_VERSION, COMPONENT_VERSION),
new ArtifactInfo (SUPPORT_PKG_NAME, "support-emoji-bundled", "Xamarin.Android.Support.Emoji.Bundled", AAR_VERSION, NUGET_VERSION, COMPONENT_VERSION),
new ArtifactInfo (SUPPORT_PKG_NAME, "renderscript-v8", "Xamarin.Android.Support.v8.RenderScript", AAR_VERSION, NUGET_VERSION, COMPONENT_VERSION),
};
class PartialZipInfo {
public string Url { get;set; }
public string LocalPath { get;set; }
public string Md5 { get;set; }
public long RangeStart { get;set; }
public long RangeEnd { get;set; }
}
class ArtifactInfo
{
public ArtifactInfo (string package, string artifactId, string nugetId, string artifactVersion, string nugetVersion, string componentVersion, bool isJar = false)
{
Package = package;
ArtifactId = artifactId;
NugetId = nugetId;
ArtifactVersion = artifactVersion;
NuGetVersion = nugetVersion;
ComponentVersion = componentVersion;
IsJar = isJar;
}
public string Package { get; set; }
public string ArtifactId { get; set; }
public string NugetId { get;set; }
public string ArtifactVersion { get; set; }
public string NuGetVersion { get; set; }
public string ComponentVersion { get; set; }
public bool IsJar { get; set; }
public string PathPrefix { get;set; }
}
var MONODROID_PATH = "/Library/Frameworks/Xamarin.Android.framework/Versions/Current/lib/mandroid/platforms/" + ANDROID_SDK_VERSION + "/";
if (IsRunningOnWindows ())
MONODROID_PATH = MakeAbsolute (new DirectoryPath (Environment.GetFolderPath (Environment.SpecialFolder.ProgramFilesX86)).Combine ("Reference Assemblies/Microsoft/Framework/MonoAndroid/" + ANDROID_SDK_VERSION +"/")).FullPath;
var MSCORLIB_PATH = "/Library/Frameworks/Xamarin.Android.framework/Libraries/mono/2.1/";
if (IsRunningOnWindows ()) {
var DOTNETDIR = new DirectoryPath (Environment.GetFolderPath (Environment.SpecialFolder.Windows)).Combine ("Microsoft.NET/");
if (DirectoryExists (DOTNETDIR.Combine ("Framework64")))
MSCORLIB_PATH = MakeAbsolute (DOTNETDIR.Combine("Framework64/v4.0.30319/")).FullPath;
else
MSCORLIB_PATH = MakeAbsolute (DOTNETDIR.Combine("Framework/v4.0.30319/")).FullPath;
}
var nugetInfos = ARTIFACTS.Select (a => new NuGetInfo { NuSpec = "./" + a.PathPrefix + a.ArtifactId + "/nuget/" + a.NugetId + ".nuspec", Version = a.NuGetVersion, RequireLicenseAcceptance = true }).ToList ();
nugetInfos.Add (new NuGetInfo { NuSpec = "./support-v4/nuget/Xamarin.Android.Support.v4.nuspec", Version = NUGET_VERSION, RequireLicenseAcceptance = true });
var buildSpec = new BuildSpec {
Libs = new [] {
new DefaultSolutionBuilder {
SolutionPath = "./AndroidSupport.sln",
BuildsOn = BuildPlatforms.Windows | BuildPlatforms.Mac,
MaxCpuCount = CPU_COUNT,
AlwaysUseMSBuild = USE_MSBUILD_ON_MAC,
Verbosity = Cake.Core.Diagnostics.Verbosity.Diagnostic,
OutputFiles = ARTIFACTS.Select (a => new OutputFileCopy { FromFile = "./" + a.PathPrefix + a.ArtifactId + "/source/bin/" + BUILD_CONFIG + "/" + a.NugetId + ".dll" }).ToArray (),
}
},
Samples = new [] {
new DefaultSolutionBuilder { SolutionPath = "./customtabs/samples/ChromeCustomTabsSample.sln", BuildsOn = BuildPlatforms.Windows | BuildPlatforms.Mac, MaxCpuCount = CPU_COUNT, AlwaysUseMSBuild = USE_MSBUILD_ON_MAC },
new DefaultSolutionBuilder { SolutionPath = "./design/samples/Cheesesquare.sln", BuildsOn = BuildPlatforms.Windows | BuildPlatforms.Mac, MaxCpuCount = CPU_COUNT, AlwaysUseMSBuild = USE_MSBUILD_ON_MAC },
new DefaultSolutionBuilder { SolutionPath = "./percent/samples/AndroidSupportSample.sln", BuildsOn = BuildPlatforms.Windows | BuildPlatforms.Mac, MaxCpuCount = CPU_COUNT, AlwaysUseMSBuild = USE_MSBUILD_ON_MAC },
new DefaultSolutionBuilder { SolutionPath = "./recommendation/samples/AndroidSupportSample.sln", BuildsOn = BuildPlatforms.Windows | BuildPlatforms.Mac, MaxCpuCount = CPU_COUNT, AlwaysUseMSBuild = USE_MSBUILD_ON_MAC },
new DefaultSolutionBuilder { SolutionPath = "./support-v4/samples/AndroidSupportSample.sln", BuildsOn = BuildPlatforms.Windows | BuildPlatforms.Mac, MaxCpuCount = CPU_COUNT, AlwaysUseMSBuild = USE_MSBUILD_ON_MAC },
//new DefaultSolutionBuilder { SolutionPath = "./appcompat-v7/samples/AndroidSupportSample.sln", BuildsOn = BuildPlatforms.Windows | BuildPlatforms.Mac, MaxCpuCount = CPU_COUNT, AlwaysUseMSBuild = USE_MSBUILD_ON_MAC },
new DefaultSolutionBuilder { SolutionPath = "./cardview-v7/samples/AndroidSupportSample.sln", BuildsOn = BuildPlatforms.Windows | BuildPlatforms.Mac, MaxCpuCount = CPU_COUNT, AlwaysUseMSBuild = USE_MSBUILD_ON_MAC },
new DefaultSolutionBuilder { SolutionPath = "./gridlayout-v7/samples/AndroidSupportSample.sln", BuildsOn = BuildPlatforms.Windows | BuildPlatforms.Mac, MaxCpuCount = CPU_COUNT, AlwaysUseMSBuild = USE_MSBUILD_ON_MAC },
//new DefaultSolutionBuilder { SolutionPath = "./mediarouter-v7/samples/AndroidSupportSample.sln", BuildsOn = BuildPlatforms.Windows | BuildPlatforms.Mac, MaxCpuCount = CPU_COUNT, AlwaysUseMSBuild = USE_MSBUILD_ON_MAC },
new DefaultSolutionBuilder { SolutionPath = "./palette-v7/samples/AndroidSupportSample.sln", BuildsOn = BuildPlatforms.Windows | BuildPlatforms.Mac, MaxCpuCount = CPU_COUNT, AlwaysUseMSBuild = USE_MSBUILD_ON_MAC },
new DefaultSolutionBuilder { SolutionPath = "./preference-v7/samples/AndroidSupportSample.sln", BuildsOn = BuildPlatforms.Windows | BuildPlatforms.Mac, MaxCpuCount = CPU_COUNT, AlwaysUseMSBuild = USE_MSBUILD_ON_MAC },
new DefaultSolutionBuilder { SolutionPath = "./recyclerview-v7/samples/AndroidSupportSample.sln", BuildsOn = BuildPlatforms.Windows | BuildPlatforms.Mac, MaxCpuCount = CPU_COUNT, AlwaysUseMSBuild = USE_MSBUILD_ON_MAC },
new DefaultSolutionBuilder { SolutionPath = "./renderscript-v8/samples/RenderScriptSample.sln", BuildsOn = BuildPlatforms.Windows | BuildPlatforms.Mac, MaxCpuCount = CPU_COUNT, AlwaysUseMSBuild = USE_MSBUILD_ON_MAC },
new DefaultSolutionBuilder { SolutionPath = "./support-v13/samples/AndroidSupportSample.sln", BuildsOn = BuildPlatforms.Windows | BuildPlatforms.Mac, MaxCpuCount = CPU_COUNT, AlwaysUseMSBuild = USE_MSBUILD_ON_MAC },
new DefaultSolutionBuilder { SolutionPath = "./leanback-v17/samples/AndroidSupportSample.sln", BuildsOn = BuildPlatforms.Windows | BuildPlatforms.Mac, MaxCpuCount = CPU_COUNT, AlwaysUseMSBuild = USE_MSBUILD_ON_MAC },
new DefaultSolutionBuilder { SolutionPath = "./support-vector-drawable/samples/VectorDrawableSample.sln", BuildsOn = BuildPlatforms.Windows | BuildPlatforms.Mac, MaxCpuCount = CPU_COUNT, AlwaysUseMSBuild = USE_MSBUILD_ON_MAC },
new DefaultSolutionBuilder { SolutionPath = "./animated-vector-drawable/samples/VectorDrawableSample.sln", BuildsOn = BuildPlatforms.Windows | BuildPlatforms.Mac, MaxCpuCount = CPU_COUNT, AlwaysUseMSBuild = USE_MSBUILD_ON_MAC },
},
NuGets = nugetInfos.ToArray (),
Components = new [] {
new Component { ManifestDirectory = "./animated-vector-drawable/component" },
new Component { ManifestDirectory = "./customtabs/component" },
new Component { ManifestDirectory = "./design/component" },
new Component { ManifestDirectory = "./percent/component" },
new Component { ManifestDirectory = "./recommendation/component" },
new Component { ManifestDirectory = "./support-v4/component" },
//new Component { ManifestDirectory = "./appcompat-v7/component" },
new Component { ManifestDirectory = "./cardview-v7/component" },
new Component { ManifestDirectory = "./gridlayout-v7/component" },
new Component { ManifestDirectory = "./palette-v7/component" },
new Component { ManifestDirectory = "./preference-v7/component" },
new Component { ManifestDirectory = "./recyclerview-v7/component" },
new Component { ManifestDirectory = "./renderscript-v8/component" },
new Component { ManifestDirectory = "./support-v13/component" },
new Component { ManifestDirectory = "./leanback-v17/component" },
new Component { ManifestDirectory = "./support-vector-drawable/component" },
}
};
var NUGET_SOURCES = EnvironmentVariable ("NUGET_SOURCES") ?? string.Empty;
if (!string.IsNullOrEmpty (NUGET_SOURCES))
buildSpec.NuGetSources = NUGET_SOURCES.Split (';',',').Select (ns => new NuGetSource { Url = ns }).ToArray ();
// You shouldn't have to configure anything below here
// ######################################################
Task ("externals")
.WithCriteria (() => !FileExists ("./externals/support-v4/classes.jar"))
.IsDependentOn ("droiddocs")
.IsDependentOn ("externals-base")
.Does (() =>
{
var path = "./externals/";
EnsureDirectoryExists (path);
// Copy the .aar's to a better location
foreach (var art in ARTIFACTS) {
// Manually process renderscript later
if (art.ArtifactId == "renderscript-v8")
continue;
var localArtifact = new FilePath ("./externals/" + art.PathPrefix + art.ArtifactId + (art.IsJar ? ".jar" : ".aar"));
var artifactUrl = MAVEN_REPO_URL + art.Package.Replace (".", "/") + "/" + art.ArtifactId + "/" + art.ArtifactVersion + "/" + art.ArtifactId + "-" + art.ArtifactVersion + (art.IsJar ? ".jar" : ".aar");
if (!FileExists (localArtifact)) {
EnsureDirectoryExists (localArtifact.GetDirectory ());
DownloadFile (artifactUrl, localArtifact);
}
// Open and fix .aar files
if (!art.IsJar) {
// Cake.Xamarin.Build has some good android aar fixes before we embed it
// https://github.com/Redth/Cake.Xamarin.Build/blob/master/Cake.Xamarin.Build/AndroidAarFixer.cs#L24-L152
FixAndroidAarFile(localArtifact, art.ArtifactId, true, true);
// Only unzip if it doesn't exist
if (!DirectoryExists("./externals/" + art.PathPrefix + art.ArtifactId))
Unzip (localArtifact, "./externals/" + art.PathPrefix + art.ArtifactId);
}
}
// Get Renderscript
if (!FileExists (path + "buildtools.zip"))
DownloadFile (BUILD_TOOLS_URL, path + "buildtools.zip");
if (!FileExists (path + "build-tools/renderscript/lib/renderscript-v8.jar")) {
Unzip (path + "buildtools.zip", path);
CopyDirectory (path + RENDERSCRIPT_FOLDER, path + "build-tools");
DeleteDirectory (path + RENDERSCRIPT_FOLDER, true);
}
// Download v4 manually since we build it separately as a type forwarder lib and it isn't downloaded in the set of main externals
var supportV4ArtifactUrl = MAVEN_REPO_URL + SUPPORT_PKG_NAME.Replace (".", "/") + "/support-v4/" + AAR_VERSION + "/support-v4-" + AAR_VERSION + ".aar";
DownloadFile (supportV4ArtifactUrl, "./externals/support-v4.aar");
Unzip ("./externals/support-v4.aar", "./externals/support-v4");
// Fix naming for some of the arch libraries that have duplicate names of each other
MoveFile ("./externals/arch-core/common.jar", "./externals/arch-core/arch-core-common.jar");
MoveFile ("./externals/arch-lifecycle/common.jar", "./externals/arch-lifecycle/arch-lifecycle-common.jar");
MoveFile ("./externals/arch-lifecycle/runtime.aar", "./externals/arch-lifecycle/arch-lifecycle-runtime.aar");
});
Task ("diff")
.WithCriteria (!IsRunningOnWindows ())
.IsDependentOn ("merge")
.Does (() =>
{
var SEARCH_DIRS = new FilePath [] {
MONODROID_PATH,
"/Library/Frameworks/Xamarin.Android.framework/Versions/Current/lib/xbuild-frameworks/MonoAndroid/v1.0/",
"/Library/Frameworks/Xamarin.Android.framework/Versions/Current/lib/mono/2.1/"
};
MonoApiInfo ("./output/AndroidSupport.Merged.dll",
"./output/AndroidSupport.api-info.xml",
new MonoApiInfoToolSettings { SearchPaths = SEARCH_DIRS });
// Grab the last public release's api-info.xml to use as a base to compare and make an API diff
DownloadFile (BASE_API_INFO_URL, "./output/AndroidSupport.api-info.previous.xml");
// Now diff against current release'd api info
// eg: mono mono-api-diff.exe ./gps.r26.xml ./gps.r27.xml > gps.diff.xml
MonoApiDiff ("./output/AndroidSupport.api-info.previous.xml",
"./output/AndroidSupport.api-info.xml",
"./output/AndroidSupport.api-diff.xml");
// Now let's make a purty html file
// eg: mono mono-api-html.exe -c -x ./gps.previous.info.xml ./gps.current.info.xml > gps.diff.html
MonoApiHtml ("./output/AndroidSupport.api-info.previous.xml",
"./output/AndroidSupport.api-info.xml",
"./output/AndroidSupport.api-diff.html");
});
Task ("merge")
.IsDependentOn ("libs")
.Does (() =>
{
if (FileExists ("./output/AndroidSupport.Merged.dll"))
DeleteFile ("./output/AndroidSupport.Merged.dll");
var mergeDlls = GetFiles ("./output/*.dll");
// Wait for ILRepack support in cake-0.5.2
ILRepack ("./output/AndroidSupport.Merged.dll", mergeDlls.First(), mergeDlls.Skip(1), new ILRepackSettings {
CopyAttrs = true,
AllowMultiple = true,
//TargetKind = ILRepack.TargetKind.Dll,
Libs = new List<DirectoryPath> {
MONODROID_PATH
},
});
});
Task ("nuget-setup")
.IsDependentOn ("buildtasks")
.Does (() =>
{
Action<FilePath, FilePath> mergeTargetsFiles = (FilePath fromFile, FilePath intoFile) =>
{
// Load the doc to append to, and the doc to append
var xOrig = System.Xml.Linq.XDocument.Load (MakeAbsolute(intoFile).FullPath);
System.Xml.Linq.XNamespace nsOrig = xOrig.Root.Name.Namespace;
var xMerge = System.Xml.Linq.XDocument.Load (MakeAbsolute(fromFile).FullPath);
System.Xml.Linq.XNamespace nsMerge = xMerge.Root.Name.Namespace;
// Add all the elements under <Project> into the existing file's <Project> node
foreach (var xItemToAdd in xMerge.Element (nsMerge + "Project").Elements ())
xOrig.Element (nsOrig + "Project").Add (xItemToAdd);
xOrig.Save (MakeAbsolute (intoFile).FullPath);
};
var templateText = FileReadText ("./template.targets");
var nugetArtifacts = ARTIFACTS.ToList ();
nugetArtifacts.Add (new ArtifactInfo (SUPPORT_PKG_NAME, "support-v4", "Xamarin.Android.Support.v4", AAR_VERSION, NUGET_VERSION, COMPONENT_VERSION));
foreach (var art in nugetArtifacts) {
var proguardFile = new FilePath(string.Format("./externals/{0}/proguard.txt", art.PathPrefix + art.ArtifactId));
var targetsText = templateText;
var targetsFile = new FilePath(string.Format ("{0}/nuget/{1}.targets", art.PathPrefix + art.ArtifactId, art.NugetId));
FileWriteText (targetsFile, targetsText);
// Transform all .targets files
var xTargets = System.Xml.Linq.XDocument.Load (MakeAbsolute(targetsFile).FullPath);
System.Xml.Linq.XNamespace nsTargets = xTargets.Root.Name.Namespace;
if (FileExists (proguardFile)) {
var projElem = xTargets.Element(nsTargets + "Project");
Information ("Adding {0} to {1}", "proguard.txt", targetsFile);
projElem.Add (new System.Xml.Linq.XElement (nsTargets + "ItemGroup",
new System.Xml.Linq.XElement (nsTargets + "ProguardConfiguration",
new System.Xml.Linq.XAttribute ("Include", "$(MSBuildThisFileDirectory)..\\..\\proguard\\proguard.txt"))));
}
xTargets.Save (MakeAbsolute(targetsFile).FullPath);
// Check for an existing .targets file in this nuget package
// we need to merge the generated one with it if it exists
// nuget only allows one automatic .targets file in the build/ folder
// of the nuget package, which must be named {nuget-package-id}.targets
// so we need to merge them all into one
var mergeFile = new FilePath (art.PathPrefix + art.ArtifactId + "/nuget/merge.targets");
if (FileExists (mergeFile)) {
Information ("merge.targets found, merging into generated file...");
mergeTargetsFiles (mergeFile, targetsFile);
}
// Transform all template.nuspec files
var nuspecText = FileReadText(art.PathPrefix + art.ArtifactId + "/nuget/template.nuspec");
//nuspecText = nuspecText.Replace ("$xbdversion$", XBD_VERSION);
var nuspecFile = new FilePath(art.PathPrefix + art.ArtifactId + "/nuget/" + art.NugetId + ".nuspec");
FileWriteText(nuspecFile, nuspecText);
var xNuspec = System.Xml.Linq.XDocument.Load (MakeAbsolute(nuspecFile).FullPath);
System.Xml.Linq.XNamespace nsNuspec = xNuspec.Root.Name.Namespace;
// Check if we have a proguard.txt file for this artifact and include it in the nuspec if so
if (FileExists (proguardFile)) {
Information ("Adding {0} to {1}", "proguard.txt", nuspecFile);
var filesElems = xNuspec.Root.Descendants (nsNuspec + "files");
if (filesElems != null) {
var filesElem = filesElems.First();
filesElem.Add (new System.Xml.Linq.XElement (nsNuspec + "file",
new System.Xml.Linq.XAttribute(nsNuspec + "src", proguardFile.ToString()),
new System.Xml.Linq.XAttribute(nsNuspec + "target", "proguard/proguard.txt")));
}
}
xNuspec.Save(MakeAbsolute(nuspecFile).FullPath);
}
});
Task ("component-setup")
.Does (() =>
{
var yamls = GetFiles ("./**/component/component.template.yaml");
foreach (var yaml in yamls) {
var manifestTxt = FileReadText (yaml)
.Replace ("$nuget-version$", NUGET_VERSION)
.Replace ("$version$", COMPONENT_VERSION);
var newYaml = yaml.GetDirectory ().CombineWithFilePath ("component.yaml");
FileWriteText (newYaml, manifestTxt);
}
});
Task ("component-docs")
.IsDependentOn ("component-setup")
.Does (() =>
{
var gettingStartedTemplates = new Dictionary<string, string> ();
foreach (var f in GetFiles ("./component/GettingStarted.*.md")) {
var key = f.GetFilenameWithoutExtension ().FullPath.Replace ("GettingStarted.", "");
var val = TransformTextFile (f).ToString ();
gettingStartedTemplates.Add (key, val);
}
var componentDirs = GetDirectories ("./*");
foreach (var compDir in componentDirs)
Information ("Found: {0}", compDir);
foreach (var compDir in componentDirs) {
var f = compDir.CombineWithFilePath ("./component/GettingStarted.template.md");
if (!FileExists (f))
continue;
Information ("Transforming: {0}", compDir);
var apiLevel = "Android 4.0.3 (API Level 15)";
var t = TransformTextFile (f, "{", "}");
foreach (var kvp in gettingStartedTemplates) {
var v = TransformText (kvp.Value, "{", "}").WithToken ("APILEVEL", apiLevel).ToString ();
t = t.WithToken (kvp.Key, v);
}
FileWriteText (compDir.CombineWithFilePath ("./component/GettingStarted.md"), t.ToString ());
}
var detailsTemplates = new Dictionary<string, string> ();
foreach (var f in GetFiles ("./component/Details.*.md")) {
var key = f.GetFilenameWithoutExtension ().FullPath.Replace ("Details.", "");
var val = TransformTextFile (f).ToString ();
detailsTemplates.Add (key, val);
}
foreach (var compDir in componentDirs) {
var f = compDir.CombineWithFilePath ("./component/Details.template.md");
if (!FileExists (f))
continue;
Information ("Transforming: {0}", compDir);
var t = TransformTextFile (f, "{", "}");
foreach (var kvp in detailsTemplates)
t = t.WithToken (kvp.Key, kvp.Value);
FileWriteText (compDir.CombineWithFilePath ("./component/Details.md"), t.ToString ());
}
});
Task ("genapi")
.IsDependentOn ("externals")
.IsDependentOn ("libs-base")
.Does (() =>
{
var GenApiToolPath = GetFiles ("./tools/**/GenAPI.exe").FirstOrDefault ();
// For some reason GenAPI.exe can't handle absolute paths on mac/unix properly, so always make them relative
// GenAPI.exe -libPath:$(MONOANDROID) -out:Some.generated.cs -w:TypeForwards ./relative/path/to/Assembly.dll
var libDirPrefix = IsRunningOnWindows () ? "output/" : "";
var libs = new FilePath [] {
"./" + libDirPrefix + "Xamarin.Android.Support.Compat.dll",
"./" + libDirPrefix + "Xamarin.Android.Support.Core.UI.dll",
"./" + libDirPrefix + "Xamarin.Android.Support.Core.Utils.dll",
"./" + libDirPrefix + "Xamarin.Android.Support.Fragment.dll",
"./" + libDirPrefix + "Xamarin.Android.Support.Media.Compat.dll",
};
foreach (var lib in libs) {
var genName = lib.GetFilename () + ".generated.cs";
var libPath = IsRunningOnWindows () ? MakeAbsolute (lib).FullPath : lib.FullPath;
var monoDroidPath = IsRunningOnWindows () ? "\"" + MONODROID_PATH + "\"" : MONODROID_PATH;
Information ("GenAPI: {0}", lib.FullPath);
StartProcess (GenApiToolPath, new ProcessSettings {
Arguments = string.Format("-libPath:{0} -out:{1}{2} -w:TypeForwards {3}",
monoDroidPath + "," + MSCORLIB_PATH,
IsRunningOnWindows () ? "" : "./",
genName,
libPath),
WorkingDirectory = "./output/",
});
}
MSBuild ("./AndroidSupport.TypeForwarders.sln", c => c.Configuration = BUILD_CONFIG);
CopyFile ("./support-v4/source/bin/" + BUILD_CONFIG + "/Xamarin.Android.Support.v4.dll", "./output/Xamarin.Android.Support.v4.dll");
});
Task ("buildtasks")
.Does (() =>
{
NuGetRestore ("./support-vector-drawable/buildtask/Vector-Drawable-BuildTasks.csproj");
MSBuild ("./support-vector-drawable/buildtask/Vector-Drawable-BuildTasks.csproj", c => c.Configuration = BUILD_CONFIG);
});
Task ("droiddocs")
.Does (() =>
{
EnsureDirectoryExists("./output");
var compressedDocsFile = "./output/docs-" + DOC_VERSION + ".zip";
if (!FileExists(compressedDocsFile)) {
if (IsRunningOnWindows ())
StartProcess ("util/droiddocs.exe", "scrape --out ./docs --url https://developer.android.com/reference/ --package-filter \"android.support\"");
else
StartProcess ("mono", "util/droiddocs.exe scrape --out ./docs --url https://developer.android.com/reference/ --package-filter \"android.support\"");
// Scraper misses a few files we require
EnsureDirectoryExists("./docs/reference");
DownloadFile("https://developer.android.com/reference/classes.html", "./docs/reference/classes.html");
CopyFile ("./docs/reference/classes.html", "./docs/reference/index.html");
DownloadFile("https://developer.android.com/reference/packages.html", "./docs/reference/packages.html");
ZipCompress ("./docs", compressedDocsFile);
}
if (!DirectoryExists("./docs"))
Unzip (compressedDocsFile, "./docs");
if (!FileExists("./Metadata.generated.xml")) {
// Generate metadata file from docs
if (IsRunningOnWindows ())
StartProcess ("util/droiddocs.exe", "transform --out ./Metadata.generated.xml --type Metadata --dir ./docs --prefix \"/reference/\" --package-filter \"android.support\"");
else
StartProcess ("mono", "util/droiddocs.exe transform --out ./Metadata.generated.xml --type Metadata --dir ./docs --prefix \"/reference/\" --package-filter \"android.support\"");
}
});
Task ("ci-setup")
.WithCriteria (!BuildSystem.IsLocalBuild)
.Does (() =>
{
var buildCommit = "DEV";
var buildNumber = "DEBUG";
var buildTimestamp = DateTime.UtcNow.ToString ();
if (BuildSystem.IsRunningOnJenkins) {
buildNumber = BuildSystem.Jenkins.Environment.Build.BuildTag;
buildCommit = EnvironmentVariable("GIT_COMMIT") ?? buildCommit;
} else if (BuildSystem.IsRunningOnVSTS) {
buildNumber = BuildSystem.TFBuild.Environment.Build.Number;
buildCommit = BuildSystem.TFBuild.Environment.Repository.SourceVersion;
}
ReplaceTextInFiles("./**/source/**/AssemblyInfo.cs", "{BUILD_COMMIT}", buildCommit);
ReplaceTextInFiles("./**/source/**/AssemblyInfo.cs", "{BUILD_NUMBER}", buildNumber);
ReplaceTextInFiles("./**/source/**/AssemblyInfo.cs", "{BUILD_TIMESTAMP}", buildTimestamp);
});
Task ("clean")
.IsDependentOn ("clean-base")
.Does (() =>
{
if (FileExists ("./generated.targets"))
DeleteFile ("./generated.targets");
if (DirectoryExists ("./externals"))
DeleteDirectory ("./externals", true);
CleanDirectories ("./**/packages");
});
Task ("nuget")
.IsDependentOn ("libs")
.IsDependentOn ("nuget-setup")
.IsDependentOn ("nuget-base");
Task ("component")
.IsDependentOn ("nuget")
.IsDependentOn ("component-docs")
.IsDependentOn ("component-base");
Task ("libs")
.IsDependentOn ("externals")
.IsDependentOn ("nuget-setup")
.IsDependentOn ("libs-base")
.IsDependentOn ("genapi");
Task ("ci")
.IsDependentOn ("ci-setup")
.IsDependentOn ("diff")
.IsDependentOn ("component");
SetupXamarinBuildTasks (buildSpec, Tasks, Task);
RunTarget (TARGET);