From c962ae1b737f1037cafed36d32255639bbca7e31 Mon Sep 17 00:00:00 2001 From: Jonathan Peppers Date: Mon, 7 Jun 2021 10:22:42 -0500 Subject: [PATCH 1/3] [BaseTasks] fix `\`-delimited paths on macOS Tests in xamarin-android have started failing with: libfoo.so : error XA4301: Cannot determine ABI of native library 'libfoo.so'. Move this file to a directory with a valid Android ABI name such as 'libs/armeabi-v7a/'. Where the test in question sets `Link=x86\libfoo.so`: https://github.com/xamarin/xamarin-android/blob/bf63c3d116b38459678cb3aefd2f5826e78c385e/src/Xamarin.Android.Build.Tasks/Tests/Xamarin.Android.Build.Tests/XASdkTests.cs#L115 This only fails on macOS and works fine on Windows. I didn't consider this case in 90d76212. I've added test cases for `\`, and added a `string.Replace()` that should solve the problem on macOS. I added test cases for `null` input as well. --- .../AndroidRidAbiHelper.cs | 4 +++ .../AndroidRidAbiHelperTests.cs | 32 ++++++++++++++++++- 2 files changed, 35 insertions(+), 1 deletion(-) diff --git a/src/Microsoft.Android.Build.BaseTasks/AndroidRidAbiHelper.cs b/src/Microsoft.Android.Build.BaseTasks/AndroidRidAbiHelper.cs index 8e6cce4..01aef16 100644 --- a/src/Microsoft.Android.Build.BaseTasks/AndroidRidAbiHelper.cs +++ b/src/Microsoft.Android.Build.BaseTasks/AndroidRidAbiHelper.cs @@ -18,6 +18,10 @@ public static class AndroidRidAbiHelper public static string GetNativeLibraryAbi (string lib) { + if (string.IsNullOrEmpty (lib)) + return null; + lib = lib.Replace ('\\', Path.DirectorySeparatorChar); + // The topmost directory the .so file is contained within var dir = Directory.GetParent (lib); var dirName = dir.Name.ToLowerInvariant (); diff --git a/tests/Microsoft.Android.Build.BaseTasks-Tests/AndroidRidAbiHelperTests.cs b/tests/Microsoft.Android.Build.BaseTasks-Tests/AndroidRidAbiHelperTests.cs index bb241cb..04b6bb5 100644 --- a/tests/Microsoft.Android.Build.BaseTasks-Tests/AndroidRidAbiHelperTests.cs +++ b/tests/Microsoft.Android.Build.BaseTasks-Tests/AndroidRidAbiHelperTests.cs @@ -10,6 +10,14 @@ namespace Microsoft.Android.Build.BaseTasks.Tests public class AndroidRidAbiHelperTests { static object [] StringValueSource = new object [] { + new[] { + /* input */ default (string), + /* expected */ default (string) + }, + new[] { + /* input */ "", + /* expected */ default + }, new[] { /* input */ "armeabi-v7a/libfoo.so", /* expected */ "armeabi-v7a" @@ -65,7 +73,15 @@ public class AndroidRidAbiHelperTests new[] { /* input */ "packages/sqlitepclraw.lib.e_sqlite3.android/1.1.11/runtimes/android-arm64/native/libe_sqlite3.so", /* expected */ "arm64-v8a" - } + }, + new[] { + /* input */ "arm64-v8a\\libfoo.so", + /* expected */ "arm64-v8a" + }, + new[] { + /* input */ "android-arm64\\libfoo.so", + /* expected */ "arm64-v8a" + }, }; [Test] @@ -76,6 +92,12 @@ public void StringValue (string input, string expected) } static object [] ITaskItemValueSource = new object [] { + new object [] { + /* input */ + new TaskItem(""), + /* expected */ + default (string) + }, new object [] { /* input */ new TaskItem("armeabi-v7a/libfoo.so"), @@ -130,6 +152,14 @@ public void StringValue (string input, string expected) /* expected */ "armeabi-v7a" }, + new object [] { + /* input */ + new TaskItem("liblinkwin.so", new Dictionary { + { "Link", "x86_64\\libfoo.so" } + }), + /* expected */ + "x86_64" + }, }; [Test] From f4dd503e814a5721a04a853d2e00d830095a8e12 Mon Sep 17 00:00:00 2001 From: Jonathan Pryor Date: Mon, 7 Jun 2021 15:03:25 -0400 Subject: [PATCH 2/3] Add %(Link) for android-arm64\libfoo.so --- .../AndroidRidAbiHelperTests.cs | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/tests/Microsoft.Android.Build.BaseTasks-Tests/AndroidRidAbiHelperTests.cs b/tests/Microsoft.Android.Build.BaseTasks-Tests/AndroidRidAbiHelperTests.cs index 04b6bb5..c1c239f 100644 --- a/tests/Microsoft.Android.Build.BaseTasks-Tests/AndroidRidAbiHelperTests.cs +++ b/tests/Microsoft.Android.Build.BaseTasks-Tests/AndroidRidAbiHelperTests.cs @@ -160,6 +160,14 @@ public void StringValue (string input, string expected) /* expected */ "x86_64" }, + new object [] { + /* input */ + new TaskItem("liblinkwin.so", new Dictionary { + { "Link", "android-arm64\\libfoo.so" }, + }), + /* expected */ + "x86_64", + }, }; [Test] From 3285d46e41964c2b2f4920e9d250d1958586c28a Mon Sep 17 00:00:00 2001 From: Jonathan Peppers Date: Mon, 7 Jun 2021 14:09:12 -0500 Subject: [PATCH 3/3] Update AndroidRidAbiHelperTests.cs --- .../AndroidRidAbiHelperTests.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/Microsoft.Android.Build.BaseTasks-Tests/AndroidRidAbiHelperTests.cs b/tests/Microsoft.Android.Build.BaseTasks-Tests/AndroidRidAbiHelperTests.cs index c1c239f..f2db030 100644 --- a/tests/Microsoft.Android.Build.BaseTasks-Tests/AndroidRidAbiHelperTests.cs +++ b/tests/Microsoft.Android.Build.BaseTasks-Tests/AndroidRidAbiHelperTests.cs @@ -166,7 +166,7 @@ public void StringValue (string input, string expected) { "Link", "android-arm64\\libfoo.so" }, }), /* expected */ - "x86_64", + "arm64-v8a", }, };