Skip to content

Commit

Permalink
[Xamarin.Android.Build.Tasks] Quote Aot Paths (again)
Browse files Browse the repository at this point in the history
Fixes #5964

We missed a few paths which might need to be quoted in order to handle
spaces in the paths.

```
2021-05-28T22:15:09.3191452Z   [aot-compiler stdout] Executing the native linker: "C:\Program Files (x86)\Android\android-sdk\ndk-bundle\toolchains\llvm\prebuilt\windows-x86_64\bin\arm-linux-androideabi-ld.EXE" -Bsymbolic -shared -o obj\Release\110\aot\armeabi-v7a\libaot-Xamarin.AndroidX.CardView.dll.so.tmp "obj\Release\110\aot\armeabi-v7a\Xamarin.AndroidX.CardView.dll\temp-llvm.o" obj\Release\110\aot\armeabi-v7a\Xamarin.AndroidX.CardView.dll\temp.s.o -LC:\Program Files (x86)\Android\android-sdk\ndk-bundle\toolchains\llvm\prebuilt\windows-x86_64\lib\gcc\arm-linux-androideabi\4.9.x -LC:\Program Files (x86)\Android\android-sdk\ndk-bundle\platforms\android-21\arch-arm\usr\lib -LC:\Program Files (x86)\Android\android-sdk\ndk-bundle\toolchains\llvm\prebuilt\windows-x86_64\bin\..\sysroot\usr\lib\arm-linux-androideabi "C:\Program Files (x86)\Android\android-sdk\ndk-bundle\toolchains\llvm\prebuilt\windows-x86_64\lib\gcc\arm-linux-androideabi\4.9.x\libgcc.a" "C:\Program Files (x86)\Android\android-sdk\ndk-bundle\platforms\android-21\arch-arm\usr\lib\libc.so" "C:\Program Files (x86)\Android\android-sdk\ndk-bundle\platforms\android-21\arch-arm\usr\lib\libm.so"
2021-05-28T22:15:09.3195848Z   [aot-compiler stderr] C:\Program Files (x86)\Android\android-sdk\ndk-bundle\toolchains\llvm\prebuilt\windows-x86_64\bin\arm-linux-androideabi-ld.EXE: error: cannot open Files: No such file or directory
2021-05-28T22:15:09.3197593Z   [aot-compiler stderr] C:\Program Files (x86)\Android\android-sdk\ndk-bundle\toolchains\llvm\prebuilt\windows-x86_64\bin\arm-linux-androideabi-ld.EXE: error: cannot open (x86)\Android\android-sdk\ndk-bundle\toolchains\llvm\prebuilt\windows-x86_64\lib\gcc\arm-linux-androideabi\4.9.x: No such file or directory
2021-05-28T22:15:09.3199375Z   [aot-compiler stderr] C:\Program Files (x86)\Android\android-sdk\ndk-bundle\toolchains\llvm\prebuilt\windows-x86_64\bin\arm-linux-androideabi-ld.EXE: error: cannot open Files: No such file or directory
2021-05-28T22:15:09.3200935Z   [aot-compiler stderr] C:\Program Files (x86)\Android\android-sdk\ndk-bundle\toolchains\llvm\prebuilt\windows-x86_64\bin\arm-linux-androideabi-ld.EXE: error: cannot open (x86)\Android\android-sdk\ndk-bundle\platforms\android-21\arch-arm\usr\lib: No such file or directory
2021-05-28T22:15:09.3202549Z   [aot-compiler stderr] C:\Program Files (x86)\Android\android-sdk\ndk-bundle\toolchains\llvm\prebuilt\windows-x86_64\bin\arm-linux-androideabi-ld.EXE: error: cannot open Files: No such file or directory
2021-05-28T22:15:09.3204244Z   [aot-compiler stderr] C:\Program Files (x86)\Android\android-sdk\ndk-bundle\toolchains\llvm\prebuilt\windows-x86_64\bin\arm-linux-androideabi-ld.EXE: error: cannot open (x86)\Android\android-sdk\ndk-bundle\toolchains\llvm\prebuilt\windows-x86_64\bin\..\sysroot\usr\lib\arm-linux-androideabi: No such file or directory
2021-05-28T22:15:09.3205865Z   [aot-compiler stderr] C:\Program Files (x86)\Android\android-sdk\ndk-bundle\toolchains\llvm\prebuilt\windows-x86_64\bin\arm-linux-androideabi-ld.EXE: error: cannot find -lunwind
2021-05-28T22:15:09.3207138Z   [aot-compiler stderr] C:\Program Files (x86)\Android\android-sdk\ndk-bundle\toolchains\llvm\prebuilt\windows-x86_64\bin\arm-linux-androideabi-ld.EXE: error: cannot find -lcompiler_rt-extras
2021-05-28T22:15:09.3208785Z   [aot-compiler stderr] C:\Program Files (x86)\Android\android-sdk\ndk-bundle\toolchains\llvm\prebuilt\windows-x86_64\bin\arm-linux-androideabi-ld.EXE: error: cannot find -lgcc_real
2021-05-28T22:15:09.3210086Z   [aot-compiler stderr] C:\Program Files (x86)\Android\android-sdk\ndk-bundle\toolchains\llvm\prebuilt\windows-x86_64\bin\arm-linux-androideabi-ld.EXE: error: cannot find -ldl
```

So lets quote ALL the things.
  • Loading branch information
dellis1972 committed Jun 2, 2021
1 parent 19796bb commit e892b77
Show file tree
Hide file tree
Showing 4 changed files with 54 additions and 12 deletions.
21 changes: 11 additions & 10 deletions src/Xamarin.Android.Build.Tasks/Tasks/Aot.cs
Original file line number Diff line number Diff line change
Expand Up @@ -304,7 +304,7 @@ IEnumerable<Config> GetAotConfigs ()
outdir = Path.Combine (AotOutputDirectory, "arm64-v8a");
mtriple = "aarch64-linux-android";
arch = AndroidTargetArch.Arm64;
break;
break;

case "x86":
aotCompiler = Path.Combine (sdkBinDirectory, "cross-x86");
Expand Down Expand Up @@ -366,21 +366,21 @@ IEnumerable<Config> GetAotConfigs ()

var libs = new List<string>();
if (NdkUtil.UsingClangNDK) {
libs.Add ($"-L{toolchainLibDir}");
libs.Add ($"-L{androidLibPath}");
libs.Add ($"-L{toolchainLibDir.TrimEnd ('\\')}");
libs.Add ($"-L{androidLibPath.TrimEnd ('\\')}");

if (arch == AndroidTargetArch.Arm) {
// Needed for -lunwind to work
string compilerLibDir = Path.Combine (toolchainPath, "..", "sysroot", "usr", "lib", NdkUtil.GetArchDirName (arch));
libs.Add ($"-L{compilerLibDir}");
libs.Add ($"-L{compilerLibDir.TrimEnd ('\\')}");
}
}

libs.Add ($"\\\"{Path.Combine (toolchainLibDir, "libgcc.a")}\\\"");
libs.Add ($"\\\"{Path.Combine (androidLibPath, "libc.so")}\\\"");
libs.Add ($"\\\"{Path.Combine (androidLibPath, "libm.so")}\\\"");
libs.Add (Path.Combine (toolchainLibDir, "libgcc.a"));
libs.Add (Path.Combine (androidLibPath, "libc.so"));
libs.Add (Path.Combine (androidLibPath, "libm.so"));

ldFlags = string.Join(";", libs);
ldFlags = $"\\\"{string.Join("\\\";\\\"", libs)}\\\"";
}

string ldName = String.Empty;
Expand All @@ -391,6 +391,7 @@ IEnumerable<Config> GetAotConfigs ()
if (ldName.IndexOf ('-') >= 0) {
ldName = ldName.Substring (ldName.LastIndexOf ("-") + 1);
}
ldName=$"\\\"{ldName}\\\"";
}
} else {
ldName = "ld";
Expand Down Expand Up @@ -466,7 +467,7 @@ IEnumerable<Config> GetAotConfigs ()
}
}
}

bool RunAotCompiler (string assembliesPath, string aotCompiler, string aotOptions, string assembly, string responseFile)
{
var stdout_completed = new ManualResetEvent (false);
Expand All @@ -487,7 +488,7 @@ bool RunAotCompiler (string assembliesPath, string aotCompiler, string aotOption
WindowStyle=ProcessWindowStyle.Hidden,
WorkingDirectory = WorkingDirectory,
};

// we do not want options to be provided out of band to the cross compilers
psi.EnvironmentVariables ["MONO_ENV_OPTIONS"] = String.Empty;
// the C code cannot parse all the license details, including the activation code that tell us which license level is allowed
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,49 @@
using Mono.Cecil;
using NUnit.Framework;
using Xamarin.ProjectTools;
using Xamarin.Android.Build;

namespace Xamarin.Android.Build.Tests
{
[Category ("Node-2"), Category ("AOT")]
[Parallelizable (ParallelScope.Children)]
public class AotTests : BaseTest
{
public string SdkWithSpacesPath {
get {
return Path.Combine (Root, "temp", string.Format ("SDK Ümläüts"));
}
}

[OneTimeSetUp]
public void Setup ()
{
if (!IsWindows)
return;

var sdkPath = AndroidSdkPath;
var ndkPath = AndroidNdkPath;

var symSdkPath = Path.Combine (SdkWithSpacesPath, "sdk");
var symNdkPath = Path.Combine (SdkWithSpacesPath, "ndk");

SymbolicLink.Create (symSdkPath, sdkPath);
SymbolicLink.Create (symNdkPath, ndkPath);

Environment.SetEnvironmentVariable ("TEST_ANDROID_SDK_PATH", symSdkPath);
Environment.SetEnvironmentVariable ("TEST_ANDROID_NDK_PATH", symNdkPath);
}

[OneTimeTearDown]
public void TearDown ()
{
if (!IsWindows)
return;
Environment.SetEnvironmentVariable ("TEST_ANDROID_SDK_PATH", "");
Environment.SetEnvironmentVariable ("TEST_ANDROID_NDK_PATH", "");
Directory.Delete (SdkWithSpacesPath, recursive: true);
}

[Test, Category ("SmokeTests")]
public void BuildBasicApplicationReleaseProfiledAot ()
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
<ItemGroup>
<Compile Remove="DebuggingTasksTests.cs" Condition="!Exists('$(XAInstallPrefix)xbuild\Xamarin\Android\Xamarin.Android.Build.Debugging.Tasks.dll')" />
<Compile Remove="Expected\**" />
<Compile Include="..\..\..\..\tools\xabuild\SymbolicLink.cs" />
<Content Include="Expected\GenerateDesignerFileExpected.cs">
<Link>..\Expected\GenerateDesignerFileExpected.cs</Link>
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,9 @@ static string GetPathFromRegistry (string valueName)

public static string GetAndroidSdkPath ()
{
var sdkPath = Environment.GetEnvironmentVariable ("ANDROID_SDK_PATH");
var sdkPath = Environment.GetEnvironmentVariable ("TEST_ANDROID_SDK_PATH");
if (String.IsNullOrEmpty (sdkPath))
sdkPath = Environment.GetEnvironmentVariable ("ANDROID_SDK_PATH");
if (String.IsNullOrEmpty (sdkPath))
sdkPath = GetPathFromRegistry ("AndroidSdkDirectory");
if (String.IsNullOrEmpty (sdkPath))
Expand All @@ -34,7 +36,9 @@ public static string GetAndroidSdkPath ()

public static string GetAndroidNdkPath ()
{
var ndkPath = Environment.GetEnvironmentVariable ("ANDROID_NDK_PATH");
var ndkPath = Environment.GetEnvironmentVariable ("TEST_ANDROID_NDK_PATH");
if (String.IsNullOrEmpty (ndkPath))
ndkPath = Environment.GetEnvironmentVariable ("ANDROID_NDK_PATH");
if (String.IsNullOrEmpty (ndkPath))
ndkPath = GetPathFromRegistry ("AndroidNdkDirectory");
if (String.IsNullOrEmpty (ndkPath))
Expand Down

0 comments on commit e892b77

Please sign in to comment.