Skip to content
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Adding x64 emulation support for pkg installers (#7893)
* Adding x64 emulation support for pkg installers

* PR feedback

* PR feedback
  • Loading branch information
sfoslund authored and ericstj committed Sep 17, 2021
commit fe23bc12e191c8390d445f1f441ddd3560f341ed
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,8 @@ public class GenerateMacOSDistributionFile : BuildTask
[Required]
public string DestinationFile { get; set; }

public string Alternativex64InstallPath { get; set; }

public override bool Execute()
{
try
Expand All @@ -38,7 +40,16 @@ public override bool Execute()

var titleElement = new XElement("title", $"{ProductBrandName} ({TargetArchitecture})");

var choiceLineElements = BundledPackages.Select(component => new XElement("line", new XAttribute("choice", component.GetMetadata("FileNameWithExtension"))));
var archScriptContent = @"<![CDATA[
function IsX64Machine() {
var machine = system.sysctl(""hw.machine"");
system.log(""Machine type: "" + machine);
var result = machine == ""x64"" || machine.endsWith(""_x64"");
system.log(""IsX64Machine: "" + result);
return result;
}
]]>";
var scriptElement = new XElement("script", new XText(archScriptContent));

var choiceElements = BundledPackages
.Select(component => new XElement("choice",
Expand All @@ -48,6 +59,23 @@ public override bool Execute()
new XAttribute("description", component.GetMetadata("Description")),
new XElement("pkg-ref", new XAttribute("id", component.GetMetadata("FileNameWithExtension")))));

if (TargetArchitecture == "x64")
{
Alternativex64InstallPath ??= "/usr/local/share/dotnet/x64";

choiceElements =
choiceElements.Select(c => new XElement(c)
.WithAttribute("selected", "IsX64Machine()"))
.Concat(
choiceElements.Select(c => new XElement(c)
.WithAttribute("id", c.Attribute("id").Value + ".alternate")
.WithAttribute("selected", "!IsX64Machine()")
.WithAttribute("customLocation", Alternativex64InstallPath)));
}

var choiceLineElements = choiceElements
.Select(c => new XElement("line", new XAttribute("choice", c.Attribute("id").Value)));

var pkgRefElements = BundledPackages
.Select(component => new XElement("pkg-ref",
new XAttribute("id", component.GetMetadata("FileNameWithExtension")),
Expand Down Expand Up @@ -78,6 +106,7 @@ public override bool Execute()
document.Root.Add(new XElement("choices-outline", choiceLineElements));
document.Root.Add(choiceElements);
document.Root.Add(pkgRefElements);
document.Root.Add(scriptElement);
using XmlWriter writer = XmlWriter.Create(File.OpenWrite(DestinationFile));
document.WriteTo(writer);
}
Expand All @@ -89,4 +118,13 @@ public override bool Execute()
return true;
}
}

static class XElementExtensions
{
public static XElement WithAttribute(this XElement element, XName attribute, object value)
{
element.SetAttributeValue(attribute, value);
return element;
}
}
}