Skip to content
This repository was archived by the owner on Jun 20, 2023. It is now read-only.

Commit 817d3c3

Browse files
committed
Clean up build script
1 parent 85d4f22 commit 817d3c3

File tree

1 file changed

+37
-7
lines changed

1 file changed

+37
-7
lines changed

build.cake

Lines changed: 37 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -59,22 +59,22 @@ var AAR_INFOS = new [] {
5959
new AarInfo ("support-core-ui", "support-core-ui", "Xamarin.Android.Support.Core.UI", AAR_VERSION, NUGET_VERSION, COMPONENT_VERSION),
6060
new AarInfo ("support-media-compat", "support-media-compat", "Xamarin.Android.Support.Media.Compat", AAR_VERSION, NUGET_VERSION, COMPONENT_VERSION),
6161
new AarInfo ("support-fragment", "support-fragment", "Xamarin.Android.Support.Fragment", AAR_VERSION, NUGET_VERSION, COMPONENT_VERSION),
62-
new AarInfo ("transition", "transition", "Xamarin.Android.Support.Transitionß", AAR_VERSION, NUGET_VERSION, COMPONENT_VERSION),
62+
new AarInfo ("transition", "transition", "Xamarin.Android.Support.Transition", AAR_VERSION, NUGET_VERSION, COMPONENT_VERSION),
6363
};
6464

6565
class AarInfo
6666
{
67-
public AarInfo (string key, string path, string nugetId, string aarVersion, string nugetVersion, string componentVersion)
67+
public AarInfo (string dir, string path, string nugetId, string aarVersion, string nugetVersion, string componentVersion)
6868
{
69-
Key = key;
69+
Dir = dir;
7070
Path = path;
7171
NugetId = nugetId;
7272
AarVersion = aarVersion;
7373
NuGetVersion = nugetVersion;
7474
ComponentVersion = componentVersion;
7575
}
7676

77-
public string Key { get; set; }
77+
public string Dir { get; set; }
7878
public string Path { get; set; }
7979
public string NugetId { get;set; }
8080
public string AarVersion { get; set; }
@@ -316,10 +316,13 @@ Task ("component-setup").Does (() =>
316316
Task ("nuget-setup").Does (() => {
317317
var templateText = FileReadText ("./template.targets");
318318

319+
if (FileExists ("./generated.targets"))
320+
DeleteFile ("./generated.targets");
321+
319322
foreach (var aar in AAR_INFOS) {
320323

321-
var msName = aar.Key.Replace("-", "");
322-
324+
var msName = aar.Dir.Replace("-", "");
325+
323326
var items = new Dictionary<string, string> {
324327
{ "_XbdUrl_", "_XbdUrl_" + msName },
325328
{ "_XbdSha1_", "_XbdSha1_" + msName },
@@ -333,7 +336,7 @@ Task ("nuget-setup").Does (() => {
333336
{ "$XbdSha1$", M2_REPOSITORY_SHA1 },
334337
{ "$XbdKey$", "androidsupport-" + AAR_VERSION },
335338
{ "$XbdAssemblyName$", aar.NugetId },
336-
{ "$AarKey$", aar.Key },
339+
{ "$AarKey$", aar.Dir },
337340
{ "$AarVersion$", aar.AarVersion}
338341
};
339342

@@ -344,6 +347,33 @@ Task ("nuget-setup").Does (() => {
344347

345348
var targetsFile = string.Format ("{0}/nuget/{1}.targets", aar.Path, aar.NugetId);
346349
FileWriteText (targetsFile, targetsText);
350+
351+
// Merge each generated targets file into one main one
352+
// this makes one file to import into our actual binding projects
353+
// which is much easier/less maintenance
354+
if (!FileExists ("./generated.targets"))
355+
FileWriteText ("./generated.targets", "<?xml version=\"1.0\" encoding=\"utf-8\"?>\n<Project ToolsVersion=\"4.0\" xmlns=\"http://schemas.microsoft.com/developer/msbuild/2003\">\n</Project>");
356+
357+
// Load the doc to append to, and the doc to append
358+
var xFileRoot = System.Xml.Linq.XDocument.Load ("./generated.targets");
359+
System.Xml.Linq.XNamespace nsRoot = xFileRoot.Root.Name.Namespace;
360+
var xFileChild = System.Xml.Linq.XDocument.Load (targetsFile);
361+
System.Xml.Linq.XNamespace nsChild = xFileRoot.Root.Name.Namespace;
362+
363+
// Add all the elements under <Project> into the existing file's <Project> node
364+
foreach (var xItemToAdd in xFileChild.Element (nsChild + "Project").Elements ())
365+
xFileRoot.Element (nsRoot + "Project").Add (xItemToAdd);
366+
367+
// Inject a property to prevent errors from missing assemblies in .targets
368+
// this allows us to use one big .targets file in all the projects and not have to figure out which specific
369+
// ones each project needs to reference for development purposes
370+
if (!xFileRoot.Descendants (nsRoot + "XamarinBuildResourceMergeThrowOnMissingAssembly").Any ()) {
371+
xFileRoot.Element (nsRoot + "Project")
372+
.AddFirst (new System.Xml.Linq.XElement (nsRoot + "PropertyGroup",
373+
new System.Xml.Linq.XElement (nsRoot + "XamarinBuildResourceMergeThrowOnMissingAssembly", false)));
374+
}
375+
376+
xFileRoot.Save ("./generated.targets");
347377
}
348378
});
349379

0 commit comments

Comments
 (0)