Skip to content

Commit be596c1

Browse files
committed
[WIP] Use the new Xamarin.Android toolchain
Symlinks aren't preserved when `xaprepare` copies the binaries, it will be fixed later. This commit is to see which tests break and how.
1 parent 23a63c5 commit be596c1

File tree

5 files changed

+82
-25
lines changed

5 files changed

+82
-25
lines changed

build-tools/xaprepare/xaprepare/Application/NDKTool.cs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,12 +6,14 @@ class NDKTool
66
{
77
public string Name { get; }
88
public string DestinationName { get; } = String.Empty;
9+
public bool Prefixed { get; }
910

10-
public NDKTool (string name, string? destinationName = null)
11+
public NDKTool (string name, string? destinationName = null, bool prefixed = false)
1112
{
1213
if (name.Trim ().Length == 0) {
1314
throw new ArgumentException (nameof (name), "must not be empty");
1415
}
16+
Prefixed = prefixed;
1517
Name = name;
1618
if (String.IsNullOrWhiteSpace (destinationName)) {
1719
return;

build-tools/xaprepare/xaprepare/ConfigAndData/Configurables.cs

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ namespace Xamarin.Android.Prepare
1515
//
1616
partial class Configurables
1717
{
18-
const string BinutilsVersion = "2.35.2-XA.1";
18+
const string BinutilsVersion = "L_13.0.1-B_2.37-3.0.0-beta1";
1919

2020
const string MicrosoftOpenJDK11Version = "11.0.10";
2121
const string MicrosoftOpenJDK11Release = "9.1";
@@ -53,7 +53,7 @@ public static partial class Urls
5353

5454
public static Uri MonoArchive_BaseUri = new Uri ("https://xamjenkinsartifact.azureedge.net/mono-sdks/");
5555

56-
public static Uri BinutilsArchive = new Uri ($"https://github.com/xamarin/xamarin-android-binutils/releases/download/{BinutilsVersion}/xamarin-android-binutils-{BinutilsVersion}.7z");
56+
public static Uri BinutilsArchive = new Uri ($"https://github.com/xamarin/xamarin-android-binutils/releases/download/{BinutilsVersion}/xamarin-android-toolchain-{BinutilsVersion}.7z");
5757
}
5858

5959
public static partial class Defaults
@@ -219,9 +219,15 @@ public static partial class Defaults
219219
};
220220

221221
public static readonly List <NDKTool> NDKTools = new List<NDKTool> {
222+
// Tools prefixed with architecture triple
223+
new NDKTool (name: "as", prefixed: true),
224+
new NDKTool (name: "ld", prefixed: true),
225+
new NDKTool (name: "strip", prefixed: true),
226+
227+
// Unprefixed tools
222228
new NDKTool (name: "as"),
223-
new NDKTool (name: "ld"),
224-
new NDKTool (name: "strip"),
229+
new NDKTool (name: "llvm-mc"),
230+
new NDKTool (name: "llvm-strip"),
225231
};
226232
}
227233

build-tools/xaprepare/xaprepare/Steps/Step_InstallGNUBinutils.Unix.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,6 @@ namespace Xamarin.Android.Prepare
22
{
33
partial class Step_InstallGNUBinutils
44
{
5-
const string? ExecutableExtension = null;
5+
const string[]? ExecutableExtensions = null;
66
}
77
}

build-tools/xaprepare/xaprepare/Steps/Step_InstallGNUBinutils.Windows.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,6 @@ namespace Xamarin.Android.Prepare
33
partial class Step_InstallGNUBinutils
44
{
55
const string HostName = "windows";
6-
const string ExecutableExtension = ".exe";
6+
static readonly string[]? ExecutableExtensions = WindowsExtensions;
77
}
88
}

build-tools/xaprepare/xaprepare/Steps/Step_InstallGNUBinutils.cs

Lines changed: 67 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -7,10 +7,11 @@ namespace Xamarin.Android.Prepare
77
{
88
partial class Step_InstallGNUBinutils : StepWithDownloadProgress
99
{
10-
static readonly string ProductName = $"GNU Binutils {Configurables.Defaults.BinutilsVersion}";
10+
static readonly string[]? WindowsExtensions = {".exe", ".cmd"};
11+
static readonly string ProductName = $"Xamarin.Android Toolchain {Configurables.Defaults.BinutilsVersion}";
1112

1213
public Step_InstallGNUBinutils ()
13-
: base ("Install GNU Binutils")
14+
: base ("Install Xamarin.Android Toolchain")
1415
{}
1516

1617
protected override async Task<bool> Execute (Context context)
@@ -19,7 +20,7 @@ protected override async Task<bool> Execute (Context context)
1920
string windowsDestinationDirectory = Configurables.Paths.WindowsBinutilsInstallDir;
2021

2122
bool hostHaveAll = HaveAllBinutils (hostDestinationDirectory);
22-
bool windowsHaveAll = HaveAllBinutils (windowsDestinationDirectory, ".exe");
23+
bool windowsHaveAll = HaveAllBinutils (windowsDestinationDirectory, WindowsExtensions);
2324

2425
if (hostHaveAll && windowsHaveAll) {
2526
Log.StatusLine ("All Binutils are already installed");
@@ -43,28 +44,42 @@ protected override async Task<bool> Execute (Context context)
4344
}
4445

4546
if (!hostHaveAll) {
46-
CopyToDestination (context, "Host", tempDir, hostDestinationDirectory, executableExtension: ExecutableExtension);
47+
CopyToDestination (context, "Host", tempDir, hostDestinationDirectory, executableExtensions: ExecutableExtensions);
4748
}
4849

4950
if (!windowsHaveAll) {
50-
CopyToDestination (context, "Windows", tempDir, windowsDestinationDirectory, "windows", ".exe");
51+
CopyToDestination (context, "Windows", tempDir, windowsDestinationDirectory, "windows", WindowsExtensions);
5152
}
5253

5354
return true;
5455
}
5556

56-
bool CopyToDestination (Context context, string label, string sourceDir, string destinationDir, string osName = HostName, string? executableExtension = null)
57+
bool CopyToDestination (Context context, string label, string sourceDir, string destinationDir, string osName = HostName, string[]? executableExtensions = null)
5758
{
5859
Log.StatusLine ();
5960
Log.StatusLine ($"Installing for {label}:");
6061

6162
string sourcePath = Path.Combine (sourceDir, osName);
6263
foreach (var kvp in Configurables.Defaults.AndroidToolchainPrefixes) {
6364
string prefix = kvp.Value;
65+
CopyTools (prefix);
66+
}
67+
CopyTools (String.Empty);
68+
69+
return true;
6470

71+
void CopyTools (string prefix)
72+
{
73+
bool copyPrefixed = !String.IsNullOrEmpty (prefix);
74+
Console.WriteLine ($"Copy prefixed? {copyPrefixed}");
6575
foreach (NDKTool tool in Configurables.Defaults.NDKTools) {
66-
string toolName = GetToolName (prefix, tool, executableExtension);
67-
string toolSourcePath = Path.Combine (sourcePath, toolName);
76+
Console.WriteLine ($"tool name {tool.Name}, prefixed? {tool.Prefixed}");
77+
if (tool.Prefixed != copyPrefixed) {
78+
continue;
79+
}
80+
81+
string toolSourcePath = GetToolPath (sourcePath, prefix, tool, executableExtensions, throwOnMissing: true);
82+
string toolName = Path.GetFileName (toolSourcePath);
6883
string toolDestinationPath = Path.Combine (destinationDir, toolName);
6984
string versionMarkerPath = GetVersionMarker (toolDestinationPath);
7085

@@ -73,8 +88,6 @@ bool CopyToDestination (Context context, string label, string sourceDir, string
7388
File.WriteAllText (versionMarkerPath, DateTime.UtcNow.ToString ());
7489
}
7590
}
76-
77-
return true;
7891
}
7992

8093
async Task<bool> DownloadBinutils (Context context, string localPackagePath, Uri url)
@@ -106,16 +119,27 @@ async Task<bool> DownloadBinutils (Context context, string localPackagePath, Uri
106119
return true;
107120
}
108121

109-
bool HaveAllBinutils (string dir, string? executableExtension = null)
122+
bool HaveAllBinutils (string dir, string[]? executableExtensions = null)
110123
{
111124
Log.DebugLine ("Checking if all binutils are installed in {dir}");
112-
string extension = executableExtension ?? String.Empty;
113125
foreach (var kvp in Configurables.Defaults.AndroidToolchainPrefixes) {
114126
string prefix = kvp.Value;
127+
if (!CheckToolsExist (prefix)) {
128+
return false;
129+
}
130+
}
131+
132+
return CheckToolsExist (String.Empty);
115133

134+
bool CheckToolsExist (string prefix)
135+
{
136+
bool checkPrefixed = !String.IsNullOrEmpty (prefix);
116137
foreach (NDKTool tool in Configurables.Defaults.NDKTools) {
117-
string toolName = GetToolName (prefix, tool, executableExtension);
118-
string toolPath = Path.Combine (dir, toolName);
138+
if (tool.Prefixed != checkPrefixed) {
139+
continue;
140+
}
141+
string toolPath = GetToolPath (dir, prefix, tool, executableExtensions);
142+
string toolName = Path.GetFileName (toolPath);
119143
string versionMarkerPath = GetVersionMarker (toolPath);
120144

121145
Log.DebugLine ($"Checking {toolName}");
@@ -129,14 +153,39 @@ bool HaveAllBinutils (string dir, string? executableExtension = null)
129153
return false;
130154
}
131155
}
132-
}
133156

134-
return true;
157+
return true;
158+
}
135159
}
136160

137-
string GetToolName (string prefix, NDKTool tool, string? executableExtension = null)
161+
string GetToolPath (string sourcePath, string prefix, NDKTool tool, string[]? executableExtensions = null, bool throwOnMissing = false)
138162
{
139-
return $"{prefix}-{(String.IsNullOrEmpty (tool.DestinationName) ? tool.Name : tool.DestinationName)}{executableExtension}";
163+
string baseName = $"{(String.IsNullOrEmpty (tool.DestinationName) ? tool.Name : tool.DestinationName)}";
164+
165+
if (!String.IsNullOrEmpty (prefix)) {
166+
baseName = $"{prefix}-{baseName}";
167+
}
168+
169+
if (executableExtensions == null || executableExtensions.Length == 0) {
170+
return Path.Combine (sourcePath, baseName);
171+
}
172+
173+
foreach (string executableExtension in executableExtensions) {
174+
string binary = Path.Combine (sourcePath, $"{baseName}{executableExtension}");
175+
Console.WriteLine ($"Checking: {binary}");
176+
if (!Utilities.FileExists (binary)) {
177+
continue;
178+
}
179+
180+
return binary;
181+
}
182+
183+
if (throwOnMissing) {
184+
string extensions = String.Join (",", executableExtensions);
185+
throw new InvalidOperationException ($"Failed to find binary file '{baseName}{{{extensions}}}'");
186+
}
187+
188+
return baseName;
140189
}
141190

142191
string GetVersionMarker (string toolPath)

0 commit comments

Comments
 (0)