forked from mattleibow/square-bindings
-
Notifications
You must be signed in to change notification settings - Fork 0
/
build.cake
722 lines (632 loc) · 27.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
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
#tool nuget:https://nuget.org/api/v2/?package=XamarinComponent
#addin nuget:https://nuget.org/api/v2/?package=Octokit&version=0.20.0
#addin nuget:https://nuget.org/api/v2/?package=Cake.Xamarin
#addin nuget:https://nuget.org/api/v2/?package=Cake.XCode
#addin nuget:https://nuget.org/api/v2/?package=Cake.FileHelpers
using System.Net;
using System.Text.RegularExpressions;
using System.Xml;
using System.Xml.Linq;
using Octokit;
//////////////////////////////////////////////////////////////////////
// ARGUMENTS
//////////////////////////////////////////////////////////////////////
var target = Argument("target", "Default").ToUpper();
// special logic to tweak builds for platform limitations
var ForMacOnly = target.EndsWith("-MAC");
var ForWindowsOnly = target.EndsWith("-WINDOWS");
var ForEverywhere = !ForMacOnly && !ForWindowsOnly;
var ForWindows = ForEverywhere || !ForMacOnly;
var ForMac = ForEverywhere || !ForWindowsOnly;
target = target.Replace("-MAC", string.Empty).Replace("-WINDOWS", string.Empty);
Information("Building target '{0}' for {1}.", target, ForEverywhere ? "everywhere" : (ForWindowsOnly ? "Windows only" : "Mac only"));
//////////////////////////////////////////////////////////////////////
// PREPARATION
//////////////////////////////////////////////////////////////////////
// the tools
FilePath XamarinComponentPath = "./tools/XamarinComponent/tools/xamarin-component.exe";
// the output folder
DirectoryPath outDir = "./output/";
FilePath outputZip = "output.zip";
if (!DirectoryExists(outDir)) {
CreateDirectory(outDir);
}
// get CI variables
var sha = EnvironmentVariable("APPVEYOR_REPO_COMMIT") ?? EnvironmentVariable("TRAVIS_COMMIT");
var branch = EnvironmentVariable("APPVEYOR_REPO_BRANCH") ?? EnvironmentVariable("TRAVIS_BRANCH");
var tag = EnvironmentVariable("APPVEYOR_REPO_TAG_NAME") ?? EnvironmentVariable("TRAVIS_TAG");
var pull = EnvironmentVariable("APPVEYOR_PULL_REQUEST_NUMBER") ?? EnvironmentVariable("TRAVIS_PULL_REQUEST");
// get the temporary build artifacts filename
var buildType = "COMMIT";
if (!string.IsNullOrEmpty(pull) && !string.Equals(pull, "false", StringComparison.OrdinalIgnoreCase)) {
buildType = "PULL" + pull;
} else if (!string.IsNullOrEmpty(tag)) {
buildType = "TAG";
}
var tagOrBranch = branch;
if (!string.IsNullOrEmpty(tag)) {
tagOrBranch = tag;
}
var TemporaryArtifactsFilename = string.Format("{0}_{1}_{2}.zip", buildType, tagOrBranch, sha);
// the GitHub communication (for storing the temporary build artifacts)
var GitHubToken = EnvironmentVariable("GitHubToken");
var GitHubUser = "mattleibow";
var GitHubRepository = "square-bindings";
var GitHubBuildTag = "CI";
public enum TargetOS {
Windows,
Mac,
Android,
iOS,
tvOS,
}
//////////////////////////////////////////////////////////////////////
// VERSIONS
//////////////////////////////////////////////////////////////////////
const string okio_version = "1.10.0"; // OkIO
const string okhttp_version = "2.7.5"; // OkHttp
const string okhttp3_version = "3.4.1"; // OkHttp3
const string okhttpws_version = "2.7.5"; // OkHttp-WS
const string okhttp3ws_version = "3.4.1"; // OkHttp3-WS
const string okhttpurlconnection_version = "2.7.5"; // OkHttp-UrlConnection
const string picasso_version = "2.5.2"; // Picasso
const string androidtimessquare_version = "1.6.5"; // AndroidTimesSquare
const string socketrocket_version = "0.5.0"; // SocketRocket
const string valet_version = "2.2.2"; // Valet
const string aardvark_version = "1.5.0"; // Aardvark
const string seismic_version = "1.0.2"; // Seismic
const string pollexor_version = "2.0.4"; // Pollexor
const string retrofit_version = "1.9.0"; // Retrofit
const string picassookhttp_version = "1.0.2"; // Picasso 2 OkHttp 3 Downloader
////////////////////////////////////////////////////////////////////////////////////////////////////
// TOOLS & FUNCTIONS - the bits to make it all work
////////////////////////////////////////////////////////////////////////////////////////////////////
var NugetToolPath = File ("./tools/nuget.exe");
var XamarinComponentToolPath = File ("./tools/XamarinComponent/tools/xamarin-component.exe");
var GitToolPath = EnvironmentVariable ("GIT_EXE") ?? (IsRunningOnWindows () ? "C:\\Program Files (x86)\\Git\\bin\\git.exe" : "git");
Information (MakeAbsolute (File (".")).ToString ());
Information (MakeAbsolute (File ("./tools/nuget.exe")).ToString ());
Information (FileExists (MakeAbsolute (File ("./tools/nuget.exe"))).ToString ());
var RunGit = new Action<DirectoryPath, string> ((directory, arguments) =>
{
StartProcess (GitToolPath, new ProcessSettings {
Arguments = arguments,
WorkingDirectory = directory,
});
});
var RunNuGetRestore = new Action<FilePath> ((solution) =>
{
NuGetRestore (solution, new NuGetRestoreSettings {
ToolPath = NugetToolPath
});
});
var RunComponentRestore = new Action<FilePath> ((solution) =>
{
RestoreComponents (solution, new XamarinComponentRestoreSettings {
ToolPath = XamarinComponentToolPath
});
});
var PackageNuGet = new Action<FilePath, DirectoryPath> ((nuspecPath, outputPath) =>
{
// NuGet messes up path on mac, so let's add ./ in front twice
var basePath = IsRunningOnUnix () ? "././" : "./";
if (!DirectoryExists (outputPath)) {
CreateDirectory (outputPath);
}
NuGetPack (nuspecPath, new NuGetPackSettings {
Verbosity = NuGetVerbosity.Detailed,
OutputDirectory = outputPath,
BasePath = basePath,
ToolPath = NugetToolPath
});
});
var RunLipo = new Action<DirectoryPath, FilePath, FilePath[]> ((directory, output, inputs) =>
{
if (!IsRunningOnUnix ()) {
throw new InvalidOperationException ("lipo is only available on Unix.");
}
var dir = directory.CombineWithFilePath (output).GetDirectory ();
if (!DirectoryExists (dir)) {
CreateDirectory (dir);
}
var inputString = string.Join(" ", inputs.Select (i => string.Format ("\"{0}\"", i)));
StartProcess ("lipo", new ProcessSettings {
Arguments = string.Format("-create -output \"{0}\" {1}", output, inputString),
WorkingDirectory = directory,
});
});
var BuildXCode = new Action<FilePath, string, DirectoryPath, TargetOS> ((project, libraryTitle, workingDirectory, os) =>
{
if (!IsRunningOnUnix ()) {
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 = libraryTitle,
Sdk = sdk,
Arch = arch,
Configuration = "Release",
});
var outputPath = workingDirectory.Combine ("build").Combine (os == TargetOS.Mac ? "Release" : ("Release-" + sdk)).Combine (libraryTitle).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))) {
RunLipo (workingDirectory, fatLibrary, new [] {
(FilePath)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))) {
RunLipo (workingDirectory, fatLibrary, new [] {
(FilePath)i386,
(FilePath)x86_64,
(FilePath)armv7,
(FilePath)armv7s,
(FilePath)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))) {
RunLipo (workingDirectory, fatLibrary, new [] {
(FilePath)x86_64,
(FilePath)arm64
});
}
}
});
var DownloadPod = new Action<DirectoryPath, string, string, IDictionary<string, string>> ((podfilePath, platform, platformVersion, pods) =>
{
if (!IsRunningOnUnix ()) {
return;
}
if (!FileExists (podfilePath.CombineWithFilePath ("Podfile.lock"))) {
var builder = new StringBuilder ();
builder.AppendFormat ("platform :{0}, '{1}'", platform, platformVersion);
builder.AppendLine ();
if (CocoaPodVersion (new CocoaPodSettings ()) >= new System.Version (1, 0)) {
builder.AppendLine ("install! 'cocoapods', :integrate_targets => false");
}
builder.AppendLine ("target 'Xamarin' do");
foreach (var pod in pods) {
builder.AppendFormat (" pod '{0}', '{1}'", pod.Key, pod.Value);
builder.AppendLine ();
}
builder.AppendLine ("end");
if (!DirectoryExists (podfilePath)) {
CreateDirectory (podfilePath);
}
System.IO.File.WriteAllText (podfilePath.CombineWithFilePath ("Podfile").ToString (), builder.ToString ());
CocoaPodInstall (podfilePath, new CocoaPodInstallSettings {
NoIntegrate = true
});
}
});
var CreateStaticPod = new Action<DirectoryPath, string, string, string, string, string> ((path, osxVersion, iosVersion, tvosVersion, name, version) => {
if (osxVersion != null) {
DownloadPod (path.Combine("osx"),
"osx", osxVersion,
new Dictionary<string, string> { { name, version } });
BuildXCode ("Pods/Pods.xcodeproj",
name,
path.Combine ("osx"),
TargetOS.Mac);
}
if (iosVersion != null) {
DownloadPod (path.Combine("ios"),
"ios", iosVersion,
new Dictionary<string, string> { { name, version } });
BuildXCode ("Pods/Pods.xcodeproj",
name,
path.Combine ("ios"),
TargetOS.iOS);
}
if (tvosVersion != null) {
DownloadPod (path.Combine("tvos"),
"tvos", tvosVersion,
new Dictionary<string, string> { { name, version } });
BuildXCode ("Pods/Pods.xcodeproj",
name,
path.Combine ("tvos"),
TargetOS.tvOS);
}
});
var DownloadJar = new Action<string, string, string> ((source, destination, version) =>
{
source = string.Format("http://search.maven.org/remotecontent?filepath=" + source, version);
FilePath dest = string.Format(destination, version);
DirectoryPath destDir = dest.GetDirectory ();
if (!DirectoryExists (destDir))
CreateDirectory (destDir);
if (!FileExists (dest)) {
DownloadFile (source, dest);
}
});
var CheckoutGit = new Action<string, string, string> ((source, destination, version) =>
{
if (!IsRunningOnUnix ()) {
return;
}
DirectoryPath dest = MakeAbsolute ((DirectoryPath) destination);
if (!DirectoryExists (destination)) {
RunGit (".", "clone " + source + " " + dest);
}
RunGit (destination, "--git-dir=.git checkout " + version);
});
var Build = new Action<FilePath> ((solution) =>
{
if (IsRunningOnWindows ()) {
MSBuild (solution, s => s.SetConfiguration ("Release").SetMSBuildPlatform (MSBuildPlatform.x86));
} else {
XBuild (solution, s => s.SetConfiguration ("Release"));
}
});
void MergeDirectory(DirectoryPath source, DirectoryPath dest, bool replace)
{
var sourceDirName = source.FullPath;
var destDirName = dest.FullPath;
if (!DirectoryExists(source)) {
throw new DirectoryNotFoundException("Source directory does not exist or could not be found: " + source);
}
if (!DirectoryExists(dest)) {
CreateDirectory(dest);
}
DirectoryInfo dir = new DirectoryInfo(sourceDirName);
FileInfo[] files = dir.GetFiles();
foreach (FileInfo file in files) {
string temppath = dest.CombineWithFilePath(file.Name).FullPath;
if (FileExists(temppath)) {
if (replace) {
DeleteFile(temppath);
}
} else {
file.CopyTo(temppath);
}
}
DirectoryInfo[] dirs = dir.GetDirectories();
foreach (DirectoryInfo subdir in dirs) {
string temppath = dest.Combine(subdir.Name).FullPath;
MergeDirectory(subdir.FullName, temppath, replace);
}
}
////////////////////////////////////////////////////////////////////////////////////////////////////
// EXTERNALS -
////////////////////////////////////////////////////////////////////////////////////////////////////
Task ("externals")
.Does (() =>
{
if (ForWindows) {
DownloadJar ("com/squareup/okio/okio/{0}/okio-{0}.jar",
"externals/OkIO/okio.jar",
okio_version);
DownloadJar ("com/squareup/okhttp/okhttp/{0}/okhttp-{0}.jar",
"externals/OkHttp/okhttp.jar",
okhttp_version);
DownloadJar ("com/squareup/okhttp3/okhttp/{0}/okhttp-{0}.jar",
"externals/OkHttp3/okhttp3.jar",
okhttp3_version);
DownloadJar ("com/squareup/okhttp/okhttp-ws/{0}/okhttp-ws-{0}.jar",
"externals/OkHttp.WS/okhttp-ws.jar",
okhttpws_version);
DownloadJar ("com/squareup/okhttp3/okhttp-ws/{0}/okhttp-ws-{0}.jar",
"externals/OkHttp3.WS/okhttp3-ws.jar",
okhttp3ws_version);
DownloadJar ("com/squareup/okhttp/okhttp-urlconnection/{0}/okhttp-urlconnection-{0}.jar",
"externals/OkHttp.UrlConnection/okhttp-urlconnection.jar",
okhttpurlconnection_version);
DownloadJar ("com/squareup/picasso/picasso/{0}/picasso-{0}.jar",
"externals/Picasso/picasso.jar",
picasso_version);
DownloadJar ("com/squareup/android-times-square/{0}/android-times-square-{0}.aar",
"externals/AndroidTimesSquare/android-times-square.aar",
androidtimessquare_version);
DownloadJar ("com/squareup/seismic/{0}/seismic-{0}.jar",
"externals/Seismic/seismic.jar",
seismic_version);
DownloadJar ("com/squareup/pollexor/{0}/pollexor-{0}.jar",
"externals/Pollexor/pollexor.jar",
pollexor_version);
DownloadJar ("com/squareup/retrofit/retrofit/{0}/retrofit-{0}.jar",
"externals/Retrofit/retrofit.jar",
retrofit_version);
DownloadJar ("com/jakewharton/picasso/picasso2-okhttp3-downloader/{0}/picasso2-okhttp3-downloader-{0}.jar",
"externals/Picasso2OkHttp3Downloader/picasso2-okhttp3-downloader.jar",
picassookhttp_version);
}
if (ForMac) {
CreateStaticPod ("externals/SocketRocket/", "10.8", "6.0", "9.0", "SocketRocket", socketrocket_version);
CreateStaticPod ("externals/Valet/", "10.10", "6.0", null, "Valet", valet_version);
CreateStaticPod ("externals/Aardvark/", null, "6.0", null, "Aardvark", aardvark_version);
}
});
////////////////////////////////////////////////////////////////////////////////////////////////////
// LIBS -
////////////////////////////////////////////////////////////////////////////////////////////////////
Task ("libs")
.IsDependentOn ("externals")
.Does (() =>
{
FilePath solution = "./binding/Square.sln";
if (ForWindowsOnly) {
solution = "./binding/Square.Windows.sln";
} else if (ForMacOnly) {
solution = "./binding/Square.Mac.sln";
}
RunNuGetRestore (solution);
Build (solution);
var outputs = new List<string> ();
if (ForWindows) {
outputs.Add ("Square.OkIO/bin/Release/Square.OkIO.dll");
outputs.Add ("Square.OkHttp/bin/Release/Square.OkHttp.dll");
outputs.Add ("Square.OkHttp3/bin/Release/Square.OkHttp3.dll");
outputs.Add ("Square.Picasso/bin/Release/Square.Picasso.dll");
outputs.Add ("Square.OkHttp.WS/bin/Release/Square.OkHttp.WS.dll");
outputs.Add ("Square.OkHttp3.WS/bin/Release/Square.OkHttp3.WS.dll");
outputs.Add ("Square.OkHttp.UrlConnection/bin/Release/Square.OkHttp.UrlConnection.dll");
outputs.Add ("Square.AndroidTimesSquare/bin/Release/Square.AndroidTimesSquare.dll");
outputs.Add ("Square.Seismic/bin/Release/Square.Seismic.dll");
outputs.Add ("Square.Pollexor/bin/Release/Square.Pollexor.dll");
outputs.Add ("Square.Retrofit/bin/Release/Square.Retrofit.dll");
outputs.Add ("JakeWharton.Picasso2OkHttp3Downloader/bin/Release/JakeWharton.Picasso2OkHttp3Downloader.dll");
}
if (ForMac) {
outputs.Add ("Square.SocketRocket/bin/Release/Square.SocketRocket.dll");
outputs.Add ("Square.SocketRocket-OSX/bin/Release/Square.SocketRocket.OSX.dll");
outputs.Add ("Square.SocketRocket-TVOS/bin/Release/Square.SocketRocket.TVOS.dll");
outputs.Add ("Square.Valet/bin/Release/Square.Valet.dll");
outputs.Add ("Square.Aardvark/bin/Release/Square.Aardvark.dll");
}
foreach (var output in outputs) {
CopyFileToDirectory ("./binding/" + output, "./output/");
}
CopyFileToDirectory ("README.md", "./output/");
CopyFileToDirectory ("LICENSE.txt", "./output/");
});
////////////////////////////////////////////////////////////////////////////////////////////////////
// PACKAGING -
////////////////////////////////////////////////////////////////////////////////////////////////////
Task ("nuget")
.IsDependentOn ("libs")
.Does (() =>
{
DeleteFiles ("./output/*.nupkg");
var nugets = new List<string> ();
if (ForWindows) {
nugets.Add ("./nuget/Square.AndroidTimesSquare.nuspec");
nugets.Add ("./nuget/Square.OkHttp.nuspec");
nugets.Add ("./nuget/Square.OkHttp.UrlConnection.nuspec");
nugets.Add ("./nuget/Square.OkHttp.WS.nuspec");
nugets.Add ("./nuget/Square.OkHttp3.nuspec");
nugets.Add ("./nuget/Square.OkHttp3.WS.nuspec");
nugets.Add ("./nuget/Square.OkIO.nuspec");
nugets.Add ("./nuget/Square.Picasso.nuspec");
nugets.Add ("./nuget/Square.Pollexor.nuspec");
nugets.Add ("./nuget/Square.Retrofit.nuspec");
nugets.Add ("./nuget/Square.Seismic.nuspec");
nugets.Add ("./nuget/JakeWharton.Picasso2OkHttp3Downloader.nuspec");
}
if (ForMac) {
nugets.Add ("./nuget/Square.Aardvark.nuspec");
nugets.Add ("./nuget/Square.SocketRocket.nuspec");
nugets.Add ("./nuget/Square.Valet.nuspec");
}
foreach (var nuget in nugets) {
PackageNuGet (nuget, "./output/");
}
});
Task ("component")
.IsDependentOn ("nuget")
.Does (() =>
{
DeleteFiles ("./output/*.xam");
var yamls = new List<string> ();
if (ForWindows) {
yamls.Add ("./component/square.androidtimessquare");
yamls.Add ("./component/square.okhttp");
yamls.Add ("./component/square.okhttp.ws");
yamls.Add ("./component/square.okhttp3");
yamls.Add ("./component/square.okhttp3.ws");
yamls.Add ("./component/square.picasso");
yamls.Add ("./component/square.pollexor");
yamls.Add ("./component/square.seismic");
}
if (ForMac) {
yamls.Add ("./component/square.aardvark");
yamls.Add ("./component/square.socketrocket");
yamls.Add ("./component/square.valet");
}
foreach (DirectoryPath yaml in yamls) {
PackageComponent (yaml, new XamarinComponentSettings {
ToolPath = XamarinComponentToolPath
});
MoveFiles (yaml + "/*.xam", "./output/");
}
});
////////////////////////////////////////////////////////////////////////////////////////////////////
// SAMPLES -
////////////////////////////////////////////////////////////////////////////////////////////////////
Task ("samples")
.IsDependentOn ("libs")
.Does (() =>
{
var samples = new List<string> ();
if (ForWindows) {
samples.Add ("./sample/AndroidTimesSquareSample/AndroidTimesSquareSample.sln");
samples.Add ("./sample/OkHttp3Sample/OkHttp3Sample.sln");
samples.Add ("./sample/OkHttp3WSSample/OkHttp3WSSample.sln");
samples.Add ("./sample/OkHttpSample/OkHttpSample.sln");
samples.Add ("./sample/OkHttpWSSample/OkHttpWSSample.sln");
samples.Add ("./sample/PicassoSample/PicassoSample.sln");
samples.Add ("./sample/PollexorSample/PollexorSample.sln");
samples.Add ("./sample/SeismicSample/SeismicSample.sln");
}
if (ForMac) {
samples.Add ("./sample/AardvarkSample/AardvarkSample.sln");
samples.Add ("./sample/SocketRocketSample/SocketRocketSample.sln");
samples.Add ("./sample/SocketRocketSample-OSX/SocketRocketSample-OSX.sln");
samples.Add ("./sample/ValetSample/ValetSample.sln");
}
foreach (var sample in samples) {
RunComponentRestore (sample);
RunNuGetRestore (sample);
Build (sample);
}
});
////////////////////////////////////////////////////////////////////////////////////////////////////
// CLEAN -
////////////////////////////////////////////////////////////////////////////////////////////////////
Task ("clean")
.Does (() =>
{
CleanDirectories ("./binding/*/bin");
CleanDirectories ("./binding/*/obj");
CleanDirectories ("./binding/packages");
CleanDirectories ("./binding/Components");
CleanDirectories ("./sample/*/bin");
CleanDirectories ("./sample/*/obj");
CleanDirectories ("./sample/packages");
CleanDirectories ("./sample/Components");
CleanDirectories ("./output");
});
Task ("clean-native")
.IsDependentOn ("clean")
.Does (() =>
{
CleanDirectories("./externals");
});
//////////////////////////////////////////////////////////////////////
// TEMPORARY ARTIFACT MANAGEMENT
//////////////////////////////////////////////////////////////////////
Task("DownloadArtifacts")
.WithCriteria(!string.IsNullOrEmpty(sha))
.WithCriteria(!ForEverywhere)
.Does(() =>
{
if (ForWindowsOnly) {
Information("Connecting to GitHub...");
var client = new GitHubClient(new ProductHeaderValue("CrossPlatformBuild"));
client.Credentials = new Credentials(GitHubToken);
Information("Loading releases...");
var releases = client.Release.GetAll(GitHubUser, GitHubRepository).Result;
var releaseId = releases.Single(r => r.TagName == GitHubBuildTag).Id;
Information("Loading CI release...");
Release release = null;
ReleaseAsset asset = null;
var waitSeconds = 0;
while (asset == null) {
release = client.Release.Get(GitHubUser, GitHubRepository, releaseId).Result;
Information("Loading asset...");
asset = release.Assets.SingleOrDefault(a => a.Name == TemporaryArtifactsFilename);
if (asset == null) {
// only try for 15 minutes
if (waitSeconds > 15 * 60) {
throw new Exception("Unable to download assets, maybe the build has failed.");
}
Information("Asset not found, waiting another 30 seconds.");
waitSeconds += 30;
System.Threading.Thread.Sleep(1000 * 30);
}
}
Information("Found asset: {0}", asset.Id);
Information("Url: {0}", asset.BrowserDownloadUrl);
Information("Downloading asset...");
if (FileExists(outputZip)) {
DeleteFile(outputZip);
}
var url = string.Format("https://api.github.com/repos/{0}/{1}/releases/assets/{2}?access_token={3}", GitHubUser, GitHubRepository, asset.Id, GitHubToken);
var wc = new WebClient();
wc.Headers.Add("Accept", "application/octet-stream");
wc.Headers.Add("User-Agent", "CrossPlatformBuild");
wc.DownloadFile(url, outputZip.FullPath);
Information("Extracting output...");
DirectoryPath tmp = "./temp-output/";
if (DirectoryExists(tmp)) {
CleanDirectory(tmp);
} else {
CreateDirectory(tmp);
}
Unzip(outputZip, tmp);
MergeDirectory(tmp, outDir, false);
}
});
Task("UploadArtifacts")
.WithCriteria(!string.IsNullOrEmpty(sha))
.WithCriteria(!ForEverywhere)
.Does(() =>
{
Information("Connecting to GitHub...");
var client = new GitHubClient(new ProductHeaderValue("CrossPlatformBuild"));
client.Credentials = new Credentials(GitHubToken);
Information("Loading releases...");
var releases = client.Release.GetAll(GitHubUser, GitHubRepository).Result;
var releaseId = releases.Single(r => r.TagName == GitHubBuildTag).Id;
Information("Loading CI release...");
var release = client.Release.Get(GitHubUser, GitHubRepository, releaseId).Result;
Information("Loading asset...");
var asset = release.Assets.SingleOrDefault(a => a.Name == TemporaryArtifactsFilename);
if (asset != null) {
Information("Deleting asset...");
client.Release.DeleteAsset(GitHubUser, GitHubRepository, asset.Id).Wait();
} else {
Information("Asset not found.");
}
if (ForMacOnly) {
Information("Compressing output...");
if (FileExists(outputZip)) {
DeleteFile(outputZip);
}
Zip(outDir, outputZip);
Information("Creating asset...");
var archiveContents = System.IO.File.OpenRead(outputZip.FullPath);
var assetUpload = new ReleaseAssetUpload {
FileName = TemporaryArtifactsFilename,
ContentType = "application/zip",
RawData = archiveContents
};
Information("Uploading asset...");
asset = client.Release.UploadAsset(release, assetUpload).Result;
Information("Uploaded asset: {0}", asset.Id);
Information("Url: {0}", asset.BrowserDownloadUrl);
}
});
////////////////////////////////////////////////////////////////////////////////////////////////////
// START -
////////////////////////////////////////////////////////////////////////////////////////////////////
Task ("CI")
.IsDependentOn ("externals")
.IsDependentOn ("libs")
.IsDependentOn ("nuget")
.IsDependentOn ("component")
.IsDependentOn ("samples")
.Does (() =>
{
});
Task("Default")
.IsDependentOn("externals")
.IsDependentOn("libs")
.IsDependentOn("nuget")
.IsDependentOn("component")
.IsDependentOn("DownloadArtifacts") // download late as each package is platform-specific
.IsDependentOn("UploadArtifacts") // upload early so the other build can start
.IsDependentOn("samples");
RunTarget (target);