Skip to content

Commit

Permalink
[BaseTasks] fix \-delimited paths on macOS (#122)
Browse files Browse the repository at this point in the history
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 90d7621.

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.

Co-authored-by: Jonathan Pryor <jonpryor@vt.edu>
  • Loading branch information
jonathanpeppers and jonpryor committed Jun 8, 2021
1 parent bdcf899 commit e3d708c
Show file tree
Hide file tree
Showing 2 changed files with 43 additions and 1 deletion.
4 changes: 4 additions & 0 deletions src/Microsoft.Android.Build.BaseTasks/AndroidRidAbiHelper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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 ();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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]
Expand All @@ -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"),
Expand Down Expand Up @@ -130,6 +152,22 @@ public void StringValue (string input, string expected)
/* expected */
"armeabi-v7a"
},
new object [] {
/* input */
new TaskItem("liblinkwin.so", new Dictionary<string,string> {
{ "Link", "x86_64\\libfoo.so" }
}),
/* expected */
"x86_64"
},
new object [] {
/* input */
new TaskItem("liblinkwin.so", new Dictionary<string,string> {
{ "Link", "android-arm64\\libfoo.so" },
}),
/* expected */
"arm64-v8a",
},
};

[Test]
Expand Down

0 comments on commit e3d708c

Please sign in to comment.