Skip to content

Commit e892b77

Browse files
committed
[Xamarin.Android.Build.Tasks] Quote Aot Paths (again)
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.
1 parent 19796bb commit e892b77

File tree

4 files changed

+54
-12
lines changed

4 files changed

+54
-12
lines changed

src/Xamarin.Android.Build.Tasks/Tasks/Aot.cs

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -304,7 +304,7 @@ IEnumerable<Config> GetAotConfigs ()
304304
outdir = Path.Combine (AotOutputDirectory, "arm64-v8a");
305305
mtriple = "aarch64-linux-android";
306306
arch = AndroidTargetArch.Arm64;
307-
break;
307+
break;
308308

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

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

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

379-
libs.Add ($"\\\"{Path.Combine (toolchainLibDir, "libgcc.a")}\\\"");
380-
libs.Add ($"\\\"{Path.Combine (androidLibPath, "libc.so")}\\\"");
381-
libs.Add ($"\\\"{Path.Combine (androidLibPath, "libm.so")}\\\"");
379+
libs.Add (Path.Combine (toolchainLibDir, "libgcc.a"));
380+
libs.Add (Path.Combine (androidLibPath, "libc.so"));
381+
libs.Add (Path.Combine (androidLibPath, "libm.so"));
382382

383-
ldFlags = string.Join(";", libs);
383+
ldFlags = $"\\\"{string.Join("\\\";\\\"", libs)}\\\"";
384384
}
385385

386386
string ldName = String.Empty;
@@ -391,6 +391,7 @@ IEnumerable<Config> GetAotConfigs ()
391391
if (ldName.IndexOf ('-') >= 0) {
392392
ldName = ldName.Substring (ldName.LastIndexOf ("-") + 1);
393393
}
394+
ldName=$"\\\"{ldName}\\\"";
394395
}
395396
} else {
396397
ldName = "ld";
@@ -466,7 +467,7 @@ IEnumerable<Config> GetAotConfigs ()
466467
}
467468
}
468469
}
469-
470+
470471
bool RunAotCompiler (string assembliesPath, string aotCompiler, string aotOptions, string assembly, string responseFile)
471472
{
472473
var stdout_completed = new ManualResetEvent (false);
@@ -487,7 +488,7 @@ bool RunAotCompiler (string assembliesPath, string aotCompiler, string aotOption
487488
WindowStyle=ProcessWindowStyle.Hidden,
488489
WorkingDirectory = WorkingDirectory,
489490
};
490-
491+
491492
// we do not want options to be provided out of band to the cross compilers
492493
psi.EnvironmentVariables ["MONO_ENV_OPTIONS"] = String.Empty;
493494
// the C code cannot parse all the license details, including the activation code that tell us which license level is allowed

src/Xamarin.Android.Build.Tasks/Tests/Xamarin.Android.Build.Tests/AotTests.cs

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,13 +7,49 @@
77
using Mono.Cecil;
88
using NUnit.Framework;
99
using Xamarin.ProjectTools;
10+
using Xamarin.Android.Build;
1011

1112
namespace Xamarin.Android.Build.Tests
1213
{
1314
[Category ("Node-2"), Category ("AOT")]
1415
[Parallelizable (ParallelScope.Children)]
1516
public class AotTests : BaseTest
1617
{
18+
public string SdkWithSpacesPath {
19+
get {
20+
return Path.Combine (Root, "temp", string.Format ("SDK Ümläüts"));
21+
}
22+
}
23+
24+
[OneTimeSetUp]
25+
public void Setup ()
26+
{
27+
if (!IsWindows)
28+
return;
29+
30+
var sdkPath = AndroidSdkPath;
31+
var ndkPath = AndroidNdkPath;
32+
33+
var symSdkPath = Path.Combine (SdkWithSpacesPath, "sdk");
34+
var symNdkPath = Path.Combine (SdkWithSpacesPath, "ndk");
35+
36+
SymbolicLink.Create (symSdkPath, sdkPath);
37+
SymbolicLink.Create (symNdkPath, ndkPath);
38+
39+
Environment.SetEnvironmentVariable ("TEST_ANDROID_SDK_PATH", symSdkPath);
40+
Environment.SetEnvironmentVariable ("TEST_ANDROID_NDK_PATH", symNdkPath);
41+
}
42+
43+
[OneTimeTearDown]
44+
public void TearDown ()
45+
{
46+
if (!IsWindows)
47+
return;
48+
Environment.SetEnvironmentVariable ("TEST_ANDROID_SDK_PATH", "");
49+
Environment.SetEnvironmentVariable ("TEST_ANDROID_NDK_PATH", "");
50+
Directory.Delete (SdkWithSpacesPath, recursive: true);
51+
}
52+
1753
[Test, Category ("SmokeTests")]
1854
public void BuildBasicApplicationReleaseProfiledAot ()
1955
{

src/Xamarin.Android.Build.Tasks/Tests/Xamarin.Android.Build.Tests/Xamarin.Android.Build.Tests.csproj

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@
2828
<ItemGroup>
2929
<Compile Remove="DebuggingTasksTests.cs" Condition="!Exists('$(XAInstallPrefix)xbuild\Xamarin\Android\Xamarin.Android.Build.Debugging.Tasks.dll')" />
3030
<Compile Remove="Expected\**" />
31+
<Compile Include="..\..\..\..\tools\xabuild\SymbolicLink.cs" />
3132
<Content Include="Expected\GenerateDesignerFileExpected.cs">
3233
<Link>..\Expected\GenerateDesignerFileExpected.cs</Link>
3334
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>

src/Xamarin.Android.Build.Tasks/Tests/Xamarin.ProjectTools/Android/AndroidSdkResolver.cs

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,9 @@ static string GetPathFromRegistry (string valueName)
2222

2323
public static string GetAndroidSdkPath ()
2424
{
25-
var sdkPath = Environment.GetEnvironmentVariable ("ANDROID_SDK_PATH");
25+
var sdkPath = Environment.GetEnvironmentVariable ("TEST_ANDROID_SDK_PATH");
26+
if (String.IsNullOrEmpty (sdkPath))
27+
sdkPath = Environment.GetEnvironmentVariable ("ANDROID_SDK_PATH");
2628
if (String.IsNullOrEmpty (sdkPath))
2729
sdkPath = GetPathFromRegistry ("AndroidSdkDirectory");
2830
if (String.IsNullOrEmpty (sdkPath))
@@ -34,7 +36,9 @@ public static string GetAndroidSdkPath ()
3436

3537
public static string GetAndroidNdkPath ()
3638
{
37-
var ndkPath = Environment.GetEnvironmentVariable ("ANDROID_NDK_PATH");
39+
var ndkPath = Environment.GetEnvironmentVariable ("TEST_ANDROID_NDK_PATH");
40+
if (String.IsNullOrEmpty (ndkPath))
41+
ndkPath = Environment.GetEnvironmentVariable ("ANDROID_NDK_PATH");
3842
if (String.IsNullOrEmpty (ndkPath))
3943
ndkPath = GetPathFromRegistry ("AndroidNdkDirectory");
4044
if (String.IsNullOrEmpty (ndkPath))

0 commit comments

Comments
 (0)