This repository has been archived by the owner on Nov 6, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 147
/
build.cake
1088 lines (923 loc) · 36.2 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
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
// Tools needed by cake addins
// #tool nuget:?package=Cake.CoreCLR // needed for debugging
#tool nuget:?package=vswhere&version=3.1.7
// Cake Addins
#addin nuget:?package=Cake.FileHelpers&version=7.0.0
#addin nuget:?package=Newtonsoft.Json&version=13.0.3
//using Cake.Common.Tools.MSBuild;
using System;
using System.Text.RegularExpressions;
using System.Xml;
using System.Xml.Linq;
using Newtonsoft.Json;
using Newtonsoft.Json.Linq;
var TARGET = Argument ("t", Argument ("target", "ci"));
var MAX_CPU_COUNT = Argument("maxcpucount", 0);
// 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 REF_DOCS_URL = "https://raw.githubusercontent.com/xamarin/GooglePlayServicesComponents/main/data/docs/play-services-firebase.zip";
var REF_METADATA_URL = "https://raw.githubusercontent.com/xamarin/GooglePlayServicesComponents/main/data/paramnames/play-services-firebase-metadata.xml";
// These are a bunch of parameter names in the txt format which binding projects can use
var REF_PARAMNAMES_URL = "https://raw.githubusercontent.com/xamarin/GooglePlayServicesComponents/main/data/paramnames/play-services-firebase-paramnames.txt";
// Resolve Xamarin.Android installation
var XAMARIN_ANDROID_PATH = EnvironmentVariable ("XAMARIN_ANDROID_PATH");
var ANDROID_SDK_BASE_VERSION = "v1.0";
var ANDROID_SDK_VERSION = "v12.0";
string AndroidSdkBuildTools = $"32.0.0";
if (string.IsNullOrEmpty(XAMARIN_ANDROID_PATH)) {
if (IsRunningOnWindows()) {
var vsInstallPath = VSWhereLatest(new VSWhereLatestSettings { Requires = "Component.Xamarin", IncludePrerelease = true });
XAMARIN_ANDROID_PATH = vsInstallPath.Combine("Common7/IDE/ReferenceAssemblies/Microsoft/Framework/MonoAndroid").FullPath;
} else {
if (DirectoryExists("/Library/Frameworks/Xamarin.Android.framework/Versions/Current/lib/xamarin.android/xbuild-frameworks/MonoAndroid"))
XAMARIN_ANDROID_PATH = "/Library/Frameworks/Xamarin.Android.framework/Versions/Current/lib/xamarin.android/xbuild-frameworks/MonoAndroid";
else
XAMARIN_ANDROID_PATH = "/Library/Frameworks/Xamarin.Android.framework/Versions/Current/lib/xbuild-frameworks/MonoAndroid";
}
}
if (!DirectoryExists($"{XAMARIN_ANDROID_PATH}/{ANDROID_SDK_VERSION}"))
throw new Exception($"Unable to find Xamarin.Android {ANDROID_SDK_VERSION} at {XAMARIN_ANDROID_PATH}.");
// Load all the git variables
var BUILD_COMMIT = EnvironmentVariable("BUILD_COMMIT") ?? "DEV";
var BUILD_NUMBER = EnvironmentVariable("BUILD_NUMBER") ?? "DEBUG";
var BUILD_TIMESTAMP = DateTime.UtcNow.ToString();
var REQUIRED_DOTNET_TOOLS = new [] {
"xamarin-android-binderator",
"xamarin.androidx.migration.tool"
};
string nuget_version_template =
// "71.vvvv.0-preview3" // pre AndroidX version
"1xx.yy.zz.ww-suffix" // AndroidX version preview
//"1xx.yy.zz" // AndroidX version stable/release
;
string nuget_version_suffix = "";
string[] Configs = new []
{
"Debug",
"Release"
};
var MONODROID_PATH = "/Library/Frameworks/Xamarin.Android.framework/Versions/Current/lib/mandroid/platforms/" + ANDROID_SDK_VERSION + "/";
if (IsRunningOnWindows ())
{
var vsInstallPath = VSWhereLatest (new VSWhereLatestSettings { Requires = "Component.Xamarin", IncludePrerelease = true });
MONODROID_PATH = vsInstallPath.Combine ("Common7/IDE/ReferenceAssemblies/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;
}
string JAVA_HOME = EnvironmentVariable ("JAVA_HOME") ?? Argument ("java_home", "");
string ANDROID_HOME = EnvironmentVariable ("ANDROID_HOME") ?? Argument ("android_home", "");
string ANDROID_SDK_ROOT = EnvironmentVariable ("ANDROID_SDK_ROOT") ?? Argument ("android_sdk_root", "");
// Log some variables
Information ($"JAVA_HOME : {JAVA_HOME}");
Information ($"ANDROID_HOME : {ANDROID_HOME}");
Information ($"ANDROID_SDK_ROOT : {ANDROID_SDK_ROOT}");
Information ($"MONODROID_PATH : {MONODROID_PATH}");
Information ($"MSCORLIB_PATH : {MSCORLIB_PATH}");
Information ($"XAMARIN_ANDROID_PATH : {XAMARIN_ANDROID_PATH}");
Information ($"ANDROID_SDK_VERSION : {ANDROID_SDK_VERSION}");
Information ($"BUILD_COMMIT: : {BUILD_COMMIT}");
Information ($"BUILD_NUMBER: : {BUILD_NUMBER}");
Information ($"BUILD_TIMESTAMP: : {BUILD_TIMESTAMP}");
// You shouldn't have to configure anything below here
// ######################################################
void RunProcess(FilePath fileName, string processArguments)
{
var exitCode = StartProcess(fileName, processArguments);
if (exitCode != 0)
throw new Exception ($"Process {fileName} exited with code {exitCode}.");
}
void RunGradle(DirectoryPath root, string target)
{
root = MakeAbsolute(root);
var proc = IsRunningOnWindows()
? root.CombineWithFilePath("gradlew.bat").FullPath
: "bash";
var args = IsRunningOnWindows()
? ""
: root.CombineWithFilePath("gradlew").FullPath;
args += $" {target} -p {root}";
var exitCode = StartProcess(proc, args);
if (exitCode != 0)
throw new Exception($"Gradle exited with code {exitCode}.");
}
Task("javadocs")
.Does(() =>
{
EnsureDirectoryExists("./externals/");
if (!FileExists("./externals/docs.zip"))
DownloadFile(REF_DOCS_URL, "./externals/docs.zip");
if (!DirectoryExists("./externals/docs"))
Unzip ("./externals/docs.zip", "./externals/docs");
if (!FileExists("./externals/paramnames.txt"))
DownloadFile(REF_PARAMNAMES_URL, "./externals/paramnames.txt");
if (!FileExists("./externals/paramnames.xml"))
DownloadFile(REF_METADATA_URL, "./externals/paramnames.xml");
var astJar = new FilePath("./util/JavaASTParameterNames-1.0.jar");
var sourcesJars = GetFiles("./externals/**/*-sources.jar");
foreach (var srcJar in sourcesJars) {
var srcJarPath = MakeAbsolute(srcJar).FullPath;
var outTxtPath = srcJarPath.Replace("-sources.jar", "-paramnames.txt");
var outXmlPath = srcJarPath.Replace("-sources.jar", "-paramnames.xml");
StartProcess("java", "-jar \"" + MakeAbsolute(astJar).FullPath + "\" --text \"" + srcJarPath + "\" \"" + outTxtPath + "\"");
StartProcess("java", "-jar \"" + MakeAbsolute(astJar).FullPath + "\" --xml \"" + srcJarPath + "\" \"" + outXmlPath + "\"");
}
});
Task("tools-update")
.Does
(
() =>
{
/*
// dotnet cake
dotnet tool uninstall -g Cake.Tool
dotnet tool install -g Cake.Tool
// binderator
dotnet tool uninstall -g xamarin.androidbinderator.tool
dotnet tool install -g xamarin.androidbinderator.tool
// androidx-migrator
dotnet tool uninstall -g xamarin.androidx.migration.tool
dotnet tool install -g xamarin.androidx.migration.tool
// apoi-tools
dotnet tool uninstall -g api-tools
dotnet tool install -g api-tools
StartProcess("dotnet", "tool uninstall -g Cake.Tool");
StartProcess("dotnet", "tool install -g Cake.Tool");
*/
StartProcess("dotnet", "tool uninstall -g xamarin.androidbinderator.tool");
StartProcess("dotnet", "tool install -g xamarin.androidbinderator.tool");
StartProcess("dotnet", "tool uninstall -g xamarin.androidx.migration.tool");
StartProcess("dotnet", "tool install -g xamarin.androidx.migration.tool");
StartProcess("dotnet", "tool uninstall -g api-tools");
StartProcess("dotnet", "tool install -g api-tools");
}
);
Task("binderate")
.IsDependentOn("javadocs")
.IsDependentOn("binderate-config-verify")
.Does(() =>
{
var configFile = MakeAbsolute(new FilePath("./config.json")).FullPath;
var basePath = MakeAbsolute(new DirectoryPath ("./")).FullPath;
RunProcess("xamarin-android-binderator",
$"--config=\"{configFile}\" --basepath=\"{basePath}\"");
RunTarget("binderate-prepare-dependencies-samples-packages-config");
RunTarget("binderate-prepare-dependencies-samples-packagereferences");
});
Task("binderate-prepare-dependencies-samples-packagereferences")
.Does
(
() =>
{
// needed for offline builds 28.0.0.1 to 28.0.0.3
EnsureDirectoryExists("./output/");
EnsureDirectoryExists("./externals/");
FilePathCollection files = GetFiles("./samples/**/*.csproj");
foreach(FilePath file in files)
{
Information($"File: {file}");
XmlDocument xml = new XmlDocument();
xml.Load($"{file}");
}
}
);
Task("binderate-prepare-dependencies-samples-packages-config")
.Does
(
() =>
{
// needed for offline builds 28.0.0.1 to 28.0.0.3
EnsureDirectoryExists("./output/");
EnsureDirectoryExists("./externals/");
FilePathCollection files = GetFiles("./samples/**/packages.config");
foreach(FilePath file in files)
{
Information($"File: {file}");
XmlDocument xml = new XmlDocument();
xml.Load($"{file}");
XmlNodeList list = xml.SelectNodes("/packages/package");
foreach (XmlNode xn in list)
{
string id = xn.Attributes["id"].Value; //Get attribute-id
//string text = xn["Text"].InnerText; //Get Text Node
string v = xn.Attributes["version"].Value; //Get attribute-id
Information($" id : {id}");
Information($" version: {v}");
string url = $"https://www.nuget.org/api/v2/package/{id}/{v}";
string file1 = $"./externals/{id.ToLower()}.{v}.nupkg";
try
{
if ( ! FileExists(file1) )
{
DownloadFile(url, file1);
}
}
catch (System.Exception)
{
Error($"Unable to download {url}");
}
}
}
return;
}
);
JArray binderator_json_array = null;
Task("binderate-config-verify")
.IsDependentOn("binderate-fix")
.Does
(
() =>
{
using (StreamReader reader = System.IO.File.OpenText(@"./config.json"))
{
JsonTextReader jtr = new JsonTextReader(reader);
JArray ja = (JArray)JToken.ReadFrom(jtr);
Information("config.json");
//Information($"{ja}");
foreach(JObject jo in ja[0]["artifacts"])
{
bool? dependency_only = (bool?) jo["dependencyOnly"];
if ( dependency_only == true)
{
continue;
}
string version = (string) jo["version"];
string nuget_version = (string) jo["nugetVersion"];
Information($"groupId = {jo["groupId"]}");
Information($"artifactId = {jo["artifactId"]}");
Information($"version = {version}");
Information($"nuget_version = {nuget_version}");
Information($"nugetId = {jo["nugetId"]}");
string[] version_parsed = nuget_version.Split(new string[] {"."}, StringSplitOptions.None);
string nuget_version_new = nuget_version_template;
string version_parsed_xx = version_parsed[0];
string version_parsed_yy = version_parsed[1];
string version_parsed_zz = version_parsed[2];
Information($"version_parsed_xx = {version_parsed_xx}");
if ( version_parsed_xx.Length == 1 )
{
version_parsed_xx = string.Concat("0", version_parsed_xx);
}
Information($"version_parsed_xx = {version_parsed_xx}");
nuget_version_new = nuget_version_new.Replace("1xx", version_parsed_xx);
nuget_version_new = nuget_version_new.Replace("yy", version_parsed_yy);
nuget_version_new = nuget_version_new.Replace("zz", version_parsed_zz);
if (version_parsed.Length == 4)
{
nuget_version_new = nuget_version_new.Replace("ww", version_parsed[3]);
}
else
{
nuget_version_new = nuget_version_new.Replace(".ww", "");
}
nuget_version_new = nuget_version_new.Replace("-suffix", nuget_version_suffix);
Information($"nuget_version_new = {nuget_version_new}");
Information($"nuget_version = {nuget_version}");
if( ! nuget_version_new.Contains($"{nuget_version}") )
{
// AndroidX version
// // pre AndroidX version
Error("check config.json for nuget id - pre AndroidX version");
Error ($" groupId = {jo["groupId"]}");
Error ($" artifactId = {jo["artifactId"]}");
Error ($" version = {version}");
Error ($" nuget_version = {nuget_version}");
Error ($" nugetId = {jo["nugetId"]}");
Warning($" expected : ");
Warning($" nuget_version = {nuget_version_new}");
throw new Exception("check config.json for nuget id");
return;
}
}
}
}
);
Task("binderate-diff")
.IsDependentOn("binderate")
.Does
(
() =>
{
EnsureDirectoryExists("./output/");
// "git diff master:config.json config.json" > ./output/config.json.diff-from-master.txt"
string process = "git";
string process_args = "diff master:config.json config.json";
IEnumerable<string> redirectedStandardOutput;
ProcessSettings process_settings = new ProcessSettings ()
{
Arguments = process_args,
RedirectStandardOutput = true
};
int exitCodeWithoutArguments = StartProcess(process, process_settings, out redirectedStandardOutput);
System.IO.File.WriteAllLines("./output/config.json.diff-from-master.txt", redirectedStandardOutput.ToArray());
Information("Exit code: {0}", exitCodeWithoutArguments);
}
);
Task("binderate-fix")
.Does
(
() =>
{
using (StreamReader reader = System.IO.File.OpenText(@"./config.json"))
{
JsonTextReader jtr = new JsonTextReader(reader);
binderator_json_array = (JArray)JToken.ReadFrom(jtr);
}
Warning("config.json fixing missing folder strucutre ...");
foreach(JObject jo in binderator_json_array[0]["artifacts"])
{
string groupId = (string) jo["groupId"];
string artifactId = (string) jo["artifactId"];
Information($" Verifying files for :");
Information($" group : {groupId}");
Information($" artifact : {artifactId}");
bool? dependency_only = (bool?) jo["dependencyOnly"];
if ( dependency_only == true)
{
continue;
}
string dir_group = $"source/{groupId}";
if ( ! DirectoryExists(dir_group) )
{
Warning($" Creating {dir_group}");
CreateDirectory(dir_group);
}
string dir_artifact = $"{dir_group}/{artifactId}";
if ( ! DirectoryExists(dir_artifact) )
{
Warning($" Creating artifact folder : {dir_artifact}");
CreateDirectory(dir_artifact);
CreateDirectory($"{dir_artifact}/Transforms/");
CreateDirectory($"{dir_artifact}/Additions/");
}
else
{
continue;
}
if ( ! FileExists($"{dir_artifact}/Transforms/Metadata.xml"))
{
Warning($" Creating file : {dir_artifact}/Metadata.xml");
CopyFile
(
$"./source/template-group-id/template-artifact/Transforms/Metadata.xml",
$"{dir_artifact}/Transforms/Metadata.xml"
);
}
if ( ! FileExists($"{dir_artifact}/Transforms/Metadata.Namespaces.xml"))
{
Warning($" Creating file : {dir_artifact}/Metadata.Namespaces.xml");
CopyFile
(
$"./source/template-group-id/template-artifact/Transforms/Metadata.Namespaces.xml",
$"{dir_artifact}/Transforms/Metadata.Namespaces.xml"
);
}
if ( ! FileExists($"{dir_artifact}/Transforms/Metadata.ParameterNames.xml"))
{
Warning($" Creating file : {dir_artifact}/Metadata.ParameterNames.xml");
CopyFile
(
$"./source/template-group-id/template-artifact/Transforms/Metadata.ParameterNames.xml",
$"{dir_artifact}/Transforms/Metadata.ParameterNames.xml"
);
}
if ( ! FileExists($"{dir_artifact}/Transforms/EnumFields.xml"))
{
Warning($" Creating file : {dir_artifact}/EnumFields.xml");
CopyFile
(
$"./source/template-group-id/template-artifact/Transforms/EnumFields.xml",
$"{dir_artifact}/Transforms/EnumFields.xml"
);
}
if ( ! FileExists($"{dir_artifact}/Transforms/EnumMethods.xml"))
{
Warning($" Creating file : {dir_artifact}/EnumMethods.xml");
CopyFile
(
$"./source/template-group-id/template-artifact/Transforms/EnumMethods.xml",
$"{dir_artifact}/Transforms/EnumMethods.xml"
);
}
if ( ! FileExists($"{dir_artifact}/Additions/Additions.cs"))
{
Warning($" Creating file : {dir_artifact}/Additions/Additions.cs");
CopyFile
(
$"./source/template-group-id/template-artifact/Additions/Additions.cs",
$"{dir_artifact}/Additions/Additions.cs"
);
}
}
return;
}
);
Task("mergetargets")
.Does(() =>
{
/*****************************
* BEGIN: Merge all the .targets together into one for the sake of compiling samples
******************************/
var generatedTargets = GetFiles("./generated/*/Xamarin.*.targets");
// Load the doc to append to, and the doc to append
var xFileRoot = System.Xml.Linq.XDocument.Parse("<?xml version=\"1.0\" encoding=\"utf-8\"?>\n<Project ToolsVersion=\"4.0\" xmlns=\"http://schemas.microsoft.com/developer/msbuild/2003\">\n</Project>");
System.Xml.Linq.XNamespace nsRoot = xFileRoot.Root.Name.Namespace;
foreach (var generatedTarget in generatedTargets) {
var xFileChild = System.Xml.Linq.XDocument.Load (MakeAbsolute (generatedTarget).FullPath);
System.Xml.Linq.XNamespace nsChild = xFileRoot.Root.Name.Namespace;
// Add all the elements under <Project> into the existing file's <Project> node
foreach (var xItemToAdd in xFileChild.Element (nsChild + "Project").Elements ())
xFileRoot.Element (nsRoot + "Project").Add (xItemToAdd);
}
// Inject a property to prevent errors from missing assemblies in .targets
// this allows us to use one big .targets file in all the projects and not have to figure out which specific
// ones each project needs to reference for development purposes
if (!xFileRoot.Descendants (nsRoot + "XamarinBuildResourceMergeThrowOnMissingAssembly").Any ()) {
xFileRoot.Element (nsRoot + "Project")
.AddFirst (new System.Xml.Linq.XElement (nsRoot + "PropertyGroup",
new System.Xml.Linq.XElement (nsRoot + "XamarinBuildResourceMergeThrowOnMissingAssembly", false)));
}
xFileRoot.Save ("./generated/generated.targets");
/*****************************
* END: Merge all the .targets together into one for the sake of compiling samples
******************************/
});
Task("libs-native")
.Does(() =>
{
string root = "./source/com.google.android.play/core.extensions/";
RunGradle(root, "build");
string outputDir = "./externals/com.xamarin.google.android.play.core.extensions/";
EnsureDirectoryExists(outputDir);
CleanDirectories(outputDir);
CopyFileToDirectory($"{root}/extensions-aar/build/outputs/aar/extensions-aar-release.aar", outputDir);
Unzip($"{outputDir}/extensions-aar-release.aar", outputDir);
MoveFile($"{outputDir}/classes.jar", $"{outputDir}/extensions.jar");
root = "./source/com.google.android.play/asset.delivery.extensions/";
RunGradle(root, "build");
outputDir = "./externals/com.xamarin.google.android.play.asset.delivery.extensions/";
EnsureDirectoryExists(outputDir);
CleanDirectories(outputDir);
CopyFileToDirectory($"{root}/extensions-aar/build/outputs/aar/extensions-aar-release.aar", outputDir);
Unzip($"{outputDir}/extensions-aar-release.aar", outputDir);
MoveFile($"{outputDir}/classes.jar", $"{outputDir}/extensions.jar");
root = "./source/com.google.android.play/feature.delivery.extensions/";
RunGradle(root, "build");
outputDir = "./externals/com.xamarin.google.android.play.feature.delivery.extensions/";
EnsureDirectoryExists(outputDir);
CleanDirectories(outputDir);
CopyFileToDirectory($"{root}/extensions-aar/build/outputs/aar/extensions-aar-release.aar", outputDir);
Unzip($"{outputDir}/extensions-aar-release.aar", outputDir);
MoveFile($"{outputDir}/classes.jar", $"{outputDir}/extensions.jar");
});
Task("libs")
.IsDependentOn("libs-native")
.Does(() =>
{
Configs = new string[] { "Release" };
foreach(string config in Configs)
{
var settings = new DotNetMSBuildSettings()
.SetConfiguration(config)
.SetMaxCpuCount(MAX_CPU_COUNT)
.EnableBinaryLogger("./output/libs.binlog")
.WithProperty("NodeReuse", "false");
settings.Properties.Add("DesignTimeBuild", new [] { "false" });
settings.Properties.Add("AndroidSdkBuildToolsVersion", new [] { AndroidSdkBuildTools });
if (!string.IsNullOrEmpty(ANDROID_HOME))
{
settings.Properties.Add("AndroidSdkDirectory", new [] { $"{ANDROID_HOME}" } );
}
DotNetRestore("./generated/GooglePlayServices.sln", new DotNetRestoreSettings
{
MSBuildSettings = settings.EnableBinaryLogger("./output/restore.binlog")
});
DotNetMSBuild("./generated/GooglePlayServices.sln", settings);
}
});
Task("samples-directory-build-targets")
.Does
(
() =>
{
Information("samples Director.Build.targets from config.json ...");
using (StreamReader reader = System.IO.File.OpenText(@"./config.json"))
{
JsonTextReader jtr = new JsonTextReader(reader);
binderator_json_array = (JArray)JToken.ReadFrom(jtr);
}
foreach(JObject jo in binderator_json_array[0]["artifacts"])
{
string version = (string) jo["version"];
string nuget_version = (string) jo["nugetVersion"];
Information($"groupId = {jo["groupId"]}");
Information($"artifactId = {jo["artifactId"]}");
Information($"version = {version}");
Information($"nuget_version = {nuget_version}");
Information($"nugetId = {jo["nugetId"]}");
}
XmlDocument doc_all = new XmlDocument();
XmlElement element_p = doc_all.CreateElement( string.Empty, "Project", string.Empty );
doc_all.AppendChild( element_p );
XmlElement element_ig = doc_all.CreateElement( string.Empty, "ItemGroup", string.Empty );
element_p.AppendChild(element_ig);
foreach(JObject jo in binderator_json_array[0]["artifacts"])
{
string version = (string) jo["version"];
string nuget_version = (string) jo["nugetVersion"];
Information($"groupId = {jo["groupId"]}");
Information($"artifactId = {jo["artifactId"]}");
Information($"version = {version}");
Information($"nuget_version = {nuget_version}");
Information($"nugetId = {jo["nugetId"]}");
XmlElement element_pr = doc_all.CreateElement( string.Empty, "PackageReference", string.Empty );
element_ig.AppendChild(element_pr);
XmlAttribute attr_update = doc_all.CreateAttribute("Update");
attr_update.Value = (string) jo["nugetId"];
element_pr.Attributes.Append(attr_update);
XmlAttribute attr_version = doc_all.CreateAttribute("Version");
attr_version.Value = nuget_version;
element_pr.Attributes.Append(attr_version);
}
XmlElement xbd_pr = doc_all.CreateElement( string.Empty, "PackageReference", string.Empty );
element_ig.AppendChild(xbd_pr);
XmlAttribute xbd_attr_update = doc_all.CreateAttribute("Update");
xbd_attr_update.Value = "Xamarin.Build.Download";
xbd_pr.Attributes.Append(xbd_attr_update);
XmlAttribute xbd_attr_version = doc_all.CreateAttribute("Version");
xbd_attr_version.Value = "0.11.4";
xbd_pr.Attributes.Append(xbd_attr_version);
doc_all.Save( System.IO.Path.Combine("samples", "Directory.Build.targets" ));
doc_all.Save( System.IO.Path.Combine("output", "Directory.Build.targets" ));
string[] lines = System.IO.File.ReadAllLines("./output/Directory.Build.targets");
List<string> lines_gps = new List<string>();
List<string> lines_fb = new List<string>();
List<string> lines_mlkit = new List<string>();
List<string> lines_gp = new List<string>();
List<string> lines_diverse = new List<string>();
Parallel.Invoke
(
() =>
{
foreach(string line in lines)
{
if( line.Contains("Project") || line.Contains("ItemGroup") )
{
lines_gps.Add(line);
}
if
(
line.Contains("Xamarin.GooglePlayServices.")
)
{
lines_gps.Add(line);
}
else
{
continue;
}
}
System.IO.File.WriteAllLines("./output/Directory.GPS.packages.props", lines_gps.ToArray());
return;
},
() =>
{
foreach(string line in lines)
{
if( line.Contains("Project") || line.Contains("ItemGroup") )
{
lines_fb.Add(line);
}
if
(
line.Contains("Xamarin.Firebase.")
)
{
lines_fb.Add(line);
}
else
{
continue;
}
}
System.IO.File.WriteAllLines("./output/Directory.FB.packages.props", lines_fb.ToArray());
return;
},
() =>
{
foreach(string line in lines)
{
if( line.Contains("Project") || line.Contains("ItemGroup") )
{
lines_mlkit.Add(line);
}
if
(
line.Contains("Xamarin.Google.MLKit.")
)
{
lines_mlkit.Add(line);
}
else
{
continue;
}
}
System.IO.File.WriteAllLines("./output/Directory.MLKit.packages.props", lines_mlkit.ToArray());
return;
},
() =>
{
foreach(string line in lines)
{
if( line.Contains("Project") || line.Contains("ItemGroup") )
{
lines_gp.Add(line);
}
if
(
line.Contains("Xamarin.Google.Android.Play.")
)
{
lines_gp.Add(line);
}
else
{
continue;
}
}
System.IO.File.WriteAllLines("./output/Directory.GP.packages.props", lines_gp.ToArray());
return;
},
() =>
{
foreach(string line in lines)
{
if( line.Contains("Project") || line.Contains("ItemGroup") )
{
lines_diverse.Add(line);
}
if
(
line.Contains("Square")
||
line.Contains("Xamarin.Grpc.")
||
line.Contains("Xamarin.Io.")
||
line.Contains("Xamarin.JavaX.")
||
line.Contains("Xamarin.Chromium.")
||
line.Contains("Xamarin.CodeHaus.")
||
line.Contains("Xamarin.TensorFlow.")
)
{
lines_diverse.Add(line);
}
else
{
continue;
}
}
System.IO.File.WriteAllLines("./output/Directory.Diverse.packages.props", lines_diverse.ToArray());
return;
}
);
return;
}
);
Task("samples-dotnet")
.IsDependentOn("nuget")
.IsDependentOn("samples-only-dotnet")
;
Task("samples-only-dotnet")
.IsDependentOn("samples-directory-build-targets")
.IsDependentOn("mergetargets")
.IsDependentOn("allbindingprojectrefs")
.Does(() =>
{
// clear the packages folder so we always use the latest
var packagesPath = MakeAbsolute((DirectoryPath)"./samples/packages-dotnet").FullPath;
EnsureDirectoryExists(packagesPath);
CleanDirectories(packagesPath);
string[] solutions = new string[]
{
"./samples/dotnet/BuildAllDotNet.sln",
"./samples/dotnet/BuildAllMauiApp.sln",
"./samples/dotnet/BuildAllPlayDotNet.sln",
};
DotNetMSBuildSettings settings = null;
settings = new DotNetMSBuildSettings()
.SetConfiguration("Debug") // We don't need to run linking
.WithProperty("RestorePackagesPath", packagesPath)
.WithProperty("AndroidSdkBuildToolsVersion", $"{AndroidSdkBuildTools}")
;
if (!string.IsNullOrEmpty(ANDROID_HOME))
settings.WithProperty("AndroidSdkDirectory", $"{ANDROID_HOME}");
foreach(string solution in solutions)
{
FilePath fp_solution = new FilePath(solution);
string filename = fp_solution.GetFilenameWithoutExtension().ToString();
Information($"=====================================================================================================");
Information($"DotNetBuild {solution} / {filename}");
DotNetBuild(solution, new DotNetBuildSettings
{
MSBuildSettings = settings
.EnableBinaryLogger($"./output/samples-dotnet-dotnet-debug-{filename}.binlog")
});
}
settings = new DotNetMSBuildSettings()
.SetConfiguration("Release") // We don't need to run linking
.WithProperty("RestorePackagesPath", packagesPath)
.WithProperty("AndroidSdkBuildToolsVersion", $"{AndroidSdkBuildTools}")
;
foreach(string solution in solutions)
{
FilePath fp_solution = new FilePath(solution);
string filename = fp_solution.GetFilenameWithoutExtension().ToString();
Information($"=====================================================================================================");
Information($"DotNetBuild {solution} / {filename}");
DotNetBuild(solution, new DotNetBuildSettings
{
MSBuildSettings = settings
.EnableBinaryLogger($"./output/samples-dotnet-dotnet-release-{filename}.binlog")
});
}
});
Task("allbindingprojectrefs")
.Does(() =>
{
Action<string,string> generateTargets = (string pattern, string file) => {
var xmlns = (XNamespace)"http://schemas.microsoft.com/developer/msbuild/2003";
var itemGroup = new XElement(xmlns + "ItemGroup");
foreach (var nupkg in GetFiles(pattern)) {
var filename = nupkg.GetFilenameWithoutExtension();
var match = Regex.Match(filename.ToString(), @"(.+?)\.(\d+[\.0-9\-a-zA-Z]+)");
itemGroup.Add(new XElement(xmlns + "PackageReference",
new XAttribute("Include", match.Groups[1]),
new XAttribute("Version", match.Groups[2])));
}
var xdoc = new XDocument(new XElement(xmlns + "Project", itemGroup));
xdoc.Save(file);
};
generateTargets("./output/Xamarin.Firebase.*.nupkg", "./output/FirebasePackages.targets");
generateTargets("./output/Xamarin.GooglePlayServices.*.nupkg", "./output/PlayServicesPackages.targets");
generateTargets("./output/Xamarin.Google.MLKit.*.nupkg", "./output/Google.MLKit.targets");
generateTargets("./output/Xamarin.Google.Android.Play.*.nupkg", "./output/Google.Play.targets");
});
Task("nuget")
.IsDependentOn("libs")
.Does(() =>
{
var outputPath = new DirectoryPath("./output");
var settings = new DotNetMSBuildSettings()
.SetConfiguration("Release")
.SetMaxCpuCount(MAX_CPU_COUNT)
.EnableBinaryLogger ("./output/nuget.binlog");
settings.Targets.Clear();
settings.Targets.Add("Pack");
settings.Properties.Add("PackageOutputPath", new [] { MakeAbsolute(outputPath).FullPath });
settings.Properties.Add("PackageRequireLicenseAcceptance", new [] { "true" });
settings.Properties.Add("DesignTimeBuild", new [] { "false" });
settings.Properties.Add("AndroidSdkBuildToolsVersion", new [] { $"{AndroidSdkBuildTools}" });
if (! string.IsNullOrEmpty(ANDROID_HOME))
{
settings.Properties.Add("AndroidSdkDirectory", new[] { $"{ANDROID_HOME}" });
}
DotNetMSBuild ("./generated/GooglePlayServices.sln", settings);
});
Task ("merge")
.IsDependentOn ("libs")
.Does (() =>
{
var allDlls =
GetFiles ($"./generated/*/bin/Release/monoandroid*/Xamarin.GooglePlayServices.*.dll") +
GetFiles ($"./generated/*/bin/Release/monoandroid*/Xamarin.Firebase.*.dll");
var mergeDlls = allDlls
.GroupBy(d => new FileInfo(d.FullPath).Name)
.Select(g => g.FirstOrDefault())
.ToList();
EnsureDirectoryExists("./output/");
RunProcess("androidx-migrator",
$"merge" +
$" --assembly " + string.Join(" --assembly ", mergeDlls) +
$" --output ./output/GooglePlayServices.Merged.dll" +
$" --search \"{XAMARIN_ANDROID_PATH}/{ANDROID_SDK_VERSION}\" " +
$" --search \"{XAMARIN_ANDROID_PATH}/{ANDROID_SDK_BASE_VERSION}\" " +
$" --inject-assemblyname");
});
Task ("ci-setup")
.WithCriteria (!BuildSystem.IsLocalBuild)
.Does (() =>
{
var glob = "./source/AssemblyInfo.cs";
ReplaceTextInFiles(glob, "{BUILD_COMMIT}", BUILD_COMMIT);
ReplaceTextInFiles(glob, "{BUILD_NUMBER}", BUILD_NUMBER);
ReplaceTextInFiles(glob, "{BUILD_TIMESTAMP}", BUILD_TIMESTAMP);
});
Task("nuget-dependecies")
.Does
(
() =>
{
string icanhasdotnet = "https://icanhasdot.net/Downloads/ICanHasDotnetCore.zip";
}
);
Task("tools-executive-order")
.Does
(
() =>
{
CakeExecuteScript
(
"./utilities.cake",
new CakeSettings
{
Arguments = new Dictionary<string, string>()
{
{ "target", "tools-executive-order" }
}
}
);
}
);
// Task ("genapi")