Skip to content

Commit

Permalink
[Xamarin.Android.Build.Tasks] Quote AOT lib paths (#3653)
Browse files Browse the repository at this point in the history
Fixes: #3651

AOT compilation (`$(AotAssemblies)`=True) on Windows was failing:

        [aot-compiler stdout] Executing the native linker: "D:\Program Files (x86)\Android\android-sdk\ndk\20.0.5594570\toolchains\arm-linux-androideabi-4.9\prebuilt\windows-x86_64\bin\arm-linux-androideabi-ld"  -shared -o obj\Release\90\aot\armeabi-v7a\libaot-Xamarin.Android.Arch.Lifecycle.ViewModel.dll.so.tmp "obj\Release\90\aot\armeabi-v7a\Xamarin.Android.Arch.Lifecycle.ViewModel.dll\temp-llvm.o" obj\Release\90\aot\armeabi-v7a\Xamarin.Android.Arch.Lifecycle.ViewModel.dll\temp.s.o D:\Program Files (x86)\Android\android-sdk\ndk\20.0.5594570\toolchains\arm-linux-androideabi-4.9\prebuilt\windows-x86_64\lib\gcc\arm-linux-androideabi\4.9.x\libgcc.a D:\Program Files (x86)\Android\android-sdk\ndk\20.0.5594570\platforms\android-19\arch-arm\usr\lib\libc.so D:\Program Files (x86)\Android\android-sdk\ndk\20.0.5594570\platforms\android-19\arch-arm\usr\lib\libm.so
        [aot-compiler stderr] D:\Program Files (x86)\Android\android-sdk\ndk\20.0.5594570\toolchains\arm-linux-androideabi-4.9\prebuilt\windows-x86_64\bin\arm-linux-androideabi-ld: error: cannot open D:\Program: No such file or directory
        [aot-compiler stderr] D:\Program Files (x86)\Android\android-sdk\ndk\20.0.5594570\toolchains\arm-linux-androideabi-4.9\prebuilt\windows-x86_64\bin\arm-linux-androideabi-ld: error: cannot open Files: No such file or directory

AOT compilation failed because reasons the paths for `libgcc.a`,
`libc.so`, and `libm.so` were not quoted, preventing appropriate
option parsing on behalf of mono.  This has a straightforward
solution: ensure those paths are quoted.

(*All* filesystem paths should be quoted when sent via a shell.
Unfortunately, this is not done consistently.)

When paths were properly quoted, [a different error arose][0]:

	  [aot-compiler stderr] '"opt"' is not recognized as an internal or external command, operable program or batch file.
	  [aot-compiler stderr] AOT of image E:\A\_work\169\s\bin\TestRelease\temp\BuildAotApplication AndÜmläüts_x86_True_True\obj\Release\android\assets\shrunk\Java.Interop.dll failed.
	  [aot-compiler stdout] Mono Ahead of Time compiler - compiling assembly E:\A\_work\169\s\bin\TestRelease\temp\BuildAotApplication AndÜmläüts_x86_True_True\obj\Release\android\assets\shrunk\Java.Interop.dll
	  [aot-compiler stdout] AOTID 8B487E2E-77E0-3CED-D551-4DA1A07E6AD6
	  [aot-compiler stdout] Executing opt: "opt" -f -O2 -disable-tail-calls -place-safepoints -spp-all-backedges -o "mono_aot_a21140\temp.opt.bc" "mono_aot_a21140\temp.bc"
	E:\A\_work\169\s\bin\Release\lib\xamarin.android\xbuild\Xamarin\Android\Xamarin.Android.Common.targets(2819,3): error XA3001: Could not AOT the assembly: Java.Interop.dll
	Done executing task "Aot" -- FAILED.

The path to `opt` is [computed based on `llvm_path`][1], so the lack
of *any* path before `opt` implies that the
`mono --aot=llvm-path=PATH` option isn't being parsed properly.

We believe that `llvm-path` isn't parsed properly because the parsing
for the `ld-flags` option somehow "screws things up".  Moving the
`ld-flags` option to be *last* allows `llvm-path` to be properly
parsed, which allows the correct path to `opt` to be used.

Finally, update `build-tools/automation/azure-pipelines.yaml` so that
the commercial integration tests are executed on *branches* of the
xamarin/xamarin-android repo, while forks of the repo are skipped.
This allows the **Integrated Regression Windows** job (3adbab5) to
be executed, allowing us to ensure that the fix actually works on the
PR, without needing a merge to master first.

[0]: #3653 (comment)
[1]: https://github.com/mono/mono/blob/7f7b5c9f3e521b1948e323d339f66172bcbc3cb2/mono/mini/aot-compiler.c#L9663
  • Loading branch information
radekdoulik authored and jonpryor committed Sep 23, 2019
1 parent c5121c8 commit 9b928f9
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 6 deletions.
4 changes: 2 additions & 2 deletions build-tools/automation/azure-pipelines.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -760,7 +760,7 @@ stages:
- android
timeoutInMinutes: 240
cancelTimeoutInMinutes: 5
condition: and(eq(variables['XA.Commercial.Build'], 'true'), ne(variables['Build.Reason'], 'PullRequest'))
condition: and(eq(variables['XA.Commercial.Build'], 'true'), ne(variables['System.PullRequest.IsFork'], 'True'))
workspace:
clean: all
steps:
Expand All @@ -775,7 +775,7 @@ stages:
- android
timeoutInMinutes: 240
cancelTimeoutInMinutes: 5
condition: and(eq(variables['XA.Commercial.Build'], 'true'), ne(variables['Build.Reason'], 'PullRequest'))
condition: and(eq(variables['XA.Commercial.Build'], 'true'), ne(variables['System.PullRequest.IsFork'], 'True'))
workspace:
clean: all
variables:
Expand Down
11 changes: 7 additions & 4 deletions src/Xamarin.Android.Build.Tasks/Tasks/Aot.cs
Original file line number Diff line number Diff line change
Expand Up @@ -367,9 +367,9 @@ IEnumerable<Config> GetAotConfigs ()
}
}

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);
}
Expand Down Expand Up @@ -405,9 +405,9 @@ IEnumerable<Config> GetAotConfigs ()
aotOptions.Add ("asmwriter");
aotOptions.Add ($"mtriple={mtriple}");
aotOptions.Add ($"tool-prefix={toolPrefix}");
aotOptions.Add ($"ld-flags={ldFlags}");
aotOptions.Add ($"llvm-path={sdkBinDirectory}");
aotOptions.Add ($"temp-path={tempDir}");
aotOptions.Add ($"ld-flags={ldFlags}");

// we need to quote the entire --aot arguments here to make sure it is parsed
// on windows as one argument. Otherwise it will be split up into multiple
Expand Down Expand Up @@ -469,6 +469,9 @@ bool RunAotCompiler (string assembliesPath, string aotCompiler, string aotOption
LogDebugMessage ("[AOT] MONO_PATH=\"{0}\" MONO_ENV_OPTIONS=\"{1}\" {2} {3}",
psi.EnvironmentVariables ["MONO_PATH"], psi.EnvironmentVariables ["MONO_ENV_OPTIONS"], psi.FileName, psi.Arguments);

if (!string.IsNullOrEmpty (responseFile))
LogDebugMessage ("[AOT] response file {0}: {1}", responseFile, File.ReadAllText (responseFile));

using (var proc = new Process ()) {
proc.OutputDataReceived += (s, e) => {
if (e.Data != null)
Expand Down

0 comments on commit 9b928f9

Please sign in to comment.