Skip to content

Conversation

@akihikodaki
Copy link
Contributor

  • Remove an OS check preventing Linux from building the library
  • Fix OutputLibraryPath for Linux

@monojenkins
Copy link

Hello! I'm the build bot for the Mono project.

I need approval from a Mono team member to build this pull request. A team member should reply with "approve" to approve a build of this pull request, "whitelist" to whitelist this and all future pull requests from this contributor, or "build" to explicitly request a build, even if one has already been done.

Contributors can ignore this message.

@dnfclas
Copy link

dnfclas commented Aug 16, 2016

Hi @akihikodaki, I'm your friendly neighborhood .NET Foundation Pull Request Bot (You can call me DNFBOT). Thanks for your contribution!
You've already signed the contribution license agreement. Thanks!

The agreement was validated by .NET Foundation and real humans are currently evaluating your PR.

TTYL, DNFBOT;

@jonpryor
Copy link
Contributor

I believe that the intention on Linux is to use/require the distro-provided libzip.so, in which case the current behavior to not build it is the correct behavior.

@grendello?

@akihikodaki: Is there a reason you want to build libzip.so instead of relying on the distro-provided version?

@akihikodaki
Copy link
Contributor Author

The old OS check in BuildDependsOnLocal is different from #168, and it just breaks the build since it still tries to copy libzip.so.

@akihikodaki: Is there a reason you want to build libzip.so instead of relying on the distro-provided version?

No, I even wonder why it does have such a thing. It may be for a specific distribution (old Ubuntu?), but any guess on dependencies provided by distribution just doesn't make sense. If you still need to provide missing dependencies on a particular distribution, why don't you make a private repository (PPA for Ubuntu)?

@jonpryor
Copy link
Contributor

I even wonder why it does have such a thing.

I'm confused about what "it" refers to in this sentence. Is it the building of libzip at all?

We need to build libzip for macOS and Windows, neither of which include libzip.

@akihikodaki
Copy link
Contributor Author

@jonpryor I see. Not sure about macOS, but it may make sense for other OSes. Please don't mind.

@atsushieno
Copy link
Contributor

We have explicit package setup for Ubuntu for now, implying that we depend on distro-based libzip.
https://github.com/xamarin/xamarin-android/blob/master/Makefile#L62

There is no reason to provide our own libzip build. Either distros or linux users should be responsible to offer a working one.

@grendello
Copy link
Contributor

grendello commented Aug 18, 2016

@akihikodaki The build system is prepared to provide dependencies for any Linux distro, see the link provided by @atsushieno. What does not make sense is to build the libraries/code that's readily available from the Linux distro's repository. We have support for Ubuntu because that's what we use, but we welcome contributions to support any other Linux distro.
And as for your suspicion that libzip is for "old Ubuntu", here are links to the packages from the latest Ubuntu versions:

http://packages.ubuntu.com/xenial/libzip4
http://packages.ubuntu.com/wily/libzip4

Debian:

https://packages.debian.org/jessie/libzip2

@akihikodaki
Copy link
Contributor Author

Still _LinuxBuildLibZip property is available. Are you going to fix or remove it?

@atsushieno
Copy link
Contributor

We should not accept build-tools/libzip/libzip.mdproj as that just results in extraneous build.

The other change is okay IMO to have (in case we would like to change mind and bundle libzip, depending on the future situation) but so far it's totally optional.

@akihikodaki
Copy link
Contributor Author

We should not accept build-tools/libzip/libzip.mdproj as that just results in extraneous build.

Actually it builds nothing if '@(_LibZipTarget)' == '' ((host is not Darwin) AND ((host is not Linux) OR '$(_LinuxBuildLibZip)' == '')) because of Condition attributes of targets.

@grendello
Copy link
Contributor

_LinuxBuildLibZip is not broken and there's no need to remove it. It works as designed - currently it prevents building (or rather bundling) of libzip on Ubuntu.

@akihikodaki
Copy link
Contributor Author

_LinuxBuildLibZip intentionally forces to build it on other distributions and fails.

@grendello
Copy link
Contributor

@akihikodaki I'm not sure what you mean by "intentionally forces to build"? We don't use "other distributions" - that's where there's room for community contributions. Your distro build is broken? Extend the detection and configuration process to support it, open a PR and we'll review it.

@akihikodaki
Copy link
Contributor Author

@grendello Let me explain _LinuxBuildLibZip

 <_LinuxBuildLibZip Condition=" '$(_LinuxBuildLibZip)' == '' AND '$(HostOS)' == 'Linux' AND '$(HostOsName)' != 'Ubuntu' ">true</_LinuxBuildLibZip>

As you can see, if the host is Linux and the distribution is not Ubuntu, it tries to build libzip, but it always fails because of the bug this pull request fixes.

(Sorry I commented with a different identity by mistake)

@jonpryor
Copy link
Contributor

As you can see, if the host is Linux and the distribution is not Ubuntu, it tries to build libzip, but it always fails because of the bug this pull request fixes.

As stated in prior comments, the intention is to use the system libzip on Linux. Your patch is counter to that intention, as it causes libzip to be built on every Linux distro.

I see two plausible solutions:

  1. Fix the logic so that libzip is built on Linux distro's other than e.g. Ubuntu (and other "properly supported" distros).
  2. "Properly support" your distro. This would include, at minimum, updating Makefile and adding linux-prepare-$(LINUX_DISTRO) and linux-prepare-$(LINUX_DISTRO)-$(LINUX_DISTRO_RELEASE) targets, which would ensure that libzip is installed on your distro, and update libzip.mdproj so that it doesn't build libzip.so on your particular distro.

@akihikodaki
Copy link
Contributor Author

@jonpryor

As stated in prior comments, the intention is to use the system libzip on Linux. Your patch is counter to that intention, as it causes libzip to be built on every Linux distro.

Atcutally it's not to counter to the, as also stated:

Actually it builds nothing if '@(_LibZipTarget)' == '' ((host is not Darwin) AND ((host is not Linux) OR '$(_LinuxBuildLibZip)' == '')) because of Condition attributes of targets.

Doesn't the logic make sense?

@grendello
Copy link
Contributor

@akihikodaki This PR doesn't fix the problem you indicate. If you could, please, re-read the comments (and especially the last comment by @jonpryor above which nicely and accurately outlines what needs to be done) and make the changes in the correct places to support your distribution, then we'd have a working solution instead of a discussion that appears to linger and lead nowhere. Locations of code to modify:

  1. https://github.com/xamarin/xamarin-android/blob/master/build-tools/libzip/libzip.props#L4
  2. https://github.com/xamarin/xamarin-android/blob/master/Makefile#L48-L124

Tip: run make prepare and then look at the generated Configuration.OperatingSystem.props file to see what OS detection capabilities you have for #1 above (code which generates the props file is right here)

@akihikodaki
Copy link
Contributor Author

I'm quite a confident that I understand what you mean, but please let me explain my understanding to make sure that.

This pull request includes the following change:

-    <BuildDependsOnLocal Condition="'$(HostOS)' == 'Windows' OR '$(HostOS)' == 'Darwin'">
+    <BuildDependsOnLocal>

You suspect this change "causes libzip to be built on every Linux distro." If it should be built on other distributions, I should modify but should not remove BuildDependsOnLocal according to what you say. If I want to affirm builds on other distributions, I should also modify Makefile.

That's your opinion. However, I do NOT think it's correct. I explain why and would like you to correct if I am wrong.
Consider this pull request is applied and you are building it on Ubuntu.

LinuxBuildLibZip is 'true' only if it's being built on Linux distributions other than Ubuntu. In this case, $(LinuxBuildLibZip) is ''.

 <_LinuxBuildLibZip Condition=" '$(_LinuxBuildLibZip)' == '' AND '$(HostOS)' == 'Linux' AND '$(HostOsName)' != 'Ubuntu' ">true</_LinuxBuildLibZip>

_LibZipTarget will be defined only if '$(_LinuxBuildLibZip)' == 'true', so @(_LibZipTarget) will also be ''.

 <_LibZipTarget Include="host-Linux" Condition="$(AndroidSupportedHostJitAbisForConditionalChecks.Contains (':Linux:')) AND '$(_LinuxBuildLibZip)' == 'true' ">
(snip)
</_LibZipTarget>

As you say, BuildDependsOnLocal is defined even on Ubuntu if this pull request is applied, so the three targets (ResolveReferences, _Configure, and _Make) will be referred.

    <BuildDependsOnLocal>
      ResolveReferences;
      _Configure;
      _Make
    </BuildDependsOnLocal>

_Configure and _Make will output intermediate files and built binaries, so let's have a look at them.

  <Target Name="_Configure"
      Condition=" '@(_LibZipTarget)' != '' "
      DependsOnTargets="_SetCMakeListsTxtTimeToLastCommitTimestamp"
      Inputs="$(LibZipSourceFullPath)\CMakeLists.txt"
Outputs="$(IntermediateOutputPath)\%(_LibZipTarget.Identity)\Makefile">
    (snip)
  </Target>

" '@(_LibZipTarget)' != '' " is FALSE in this case, so _Configure won't run.

  <Target Name="_Make"
      Condition=" '@(_LibZipTarget)' != '' "
      Inputs="$(IntermediateOutputPath)\%(_LibZipTarget.Identity)\Makefile"
Outputs="@(Content)">
    (snip)
  </Target>

The Condition of _Make is also FALSE, so _Make won't run.

As the result, NOTHING will be built.

@borgdylan
Copy link

The last time I built XA, libzip was not automatically buillt yet was expected to be inside a particular directory. The build system did not copy the system's libzip to the correct place, if it copied it at all.

- Remove an OS check making Linux distributions other than Ubuntu fail to
build the library
- Fix OutputLibraryPath
@akihikodaki
Copy link
Contributor Author

83e3185: rebased to 3c55f93 and changed the commit message accordingly. The old commit message was confusing for the latest code base.

@akihikodaki
Copy link
Contributor Author

Tested on Ubuntu 16.04 Xenial Xerus and it didn't build libzip as expected. (For curious people, I tested on WSL of build 14936, and the entire build failed because linker got aborted.)

@jonpryor jonpryor merged commit fb06875 into dotnet:master Nov 18, 2016
radical pushed a commit that referenced this pull request May 8, 2018
Context: https://github.com/mono/Embeddinator-4000

Embeddinator-4000 will bring a lot more developers to consume C#
objects from their Java code. One pain point here is that all
constructors are generating `throws java.lang.Throwable` regardless of
the `[Export]` declaration. Looking into it further, there was also the
issue if you declared an empty Type[], jcw-gen was not handling that
case.

Changes:
 - Added `ThrowsDeclaration` property for reuse, which also handles the
    case of empty `Type[]`
 - Constructors now use `ThrowsDeclaration` along with methods
 - New test cases: a class with constructors with plain `[Export]` and a
    class with `[Export]` declaring `Throws`
 - Expanded methods test case: method with `Throws` and method with
    `Throws` and an empty `Type[]`
jonpryor added a commit to jonpryor/xamarin-android that referenced this pull request Jun 14, 2022
Context: 70272db
Context: 38b1236
Context: https://github.com/actions/virtual-environments/blob/9cf1ebd754807fba137c8ce9fa2140311609fdd6/images/win/Windows2022-Readme.md
Context: actions/runner-images@2950cbf

Changes: http://github.com/xamarin/xamarin-android-tools/compare/20f611202bef0fc7c1659366dd38865eb119dde5...ec346d07cf3ac7fc74d08eae4f19043b51485724

  * dotnet/android-tools@ec346d0: [Xamarin.Android.Tools.AndroidSdk] Permit NDK r24 (dotnet#171)
  * dotnet/android-tools@47832f1: [Xamarin.Android.Tools.AndroidSdk] AndroidSdkInfo validation locator (dotnet#170)

We've had an "inadvertent thinko" for the past couple of months:
in commit 70272db we updated the default `$(AndroidNdkDirectory)`
value to be `$(ANDROID_NDK_LATEST_HOME)`, if set.  *At the time*,
we think this was NDK r23.

In commit 38b1236, we updated `xaprepare` to install NDK r24.

The "thinko" is that commit 38b1236 was *irrelevant*, as commit
70272db was "in control".  The Windows **Prepare Solution** log
would contain e.g.:

	  Checking if android-ndk-r24-windows exists in C:\Android\android-sdk\ndk\23.2.8568313
	  Component 'android-ndk-r24-windows' requires Pkg.Revision to be '24.0.8215888', verifying
	      installed

It also *mis-detected* NDK r23 as r24 (?!).

It "worked" only by coincidence.

Around 2022-Jun-09, GitHub actions updated the default NDK installed
on their Windows images; previously, `$(ANDROID_NDK_LATEST_HOME)` was
NDK r23 or earlier (we're not sure); *now*, it is NDK r24.

This subtle change -- invisible!  The build environment changed! --
*introduced* unit test failures, of two patterns.

Pattern 1 is that `readelf` could not be found:

	System.ComponentModel.Win32Exception : An error occurred trying to start process
	'C:\Android\android-sdk\ndk-bundle\toolchains\llvm\prebuilt\windows-x86_64\bin\readelf'
	with working directory 'C:\a_work\1\s\xamarin-android\bin\TestRelease\net6.0'.
	The system cannot find the file specified.
	   at System.Diagnostics.Process.StartWithCreateProcess(ProcessStartInfo startInfo)
	   at Xamarin.Android.Build.Tests.EnvironmentHelper.RunCommand(String executablePath, String arguments) in C:\a\_work\1\s\src\Xamarin.Android.Build.Tasks\Tests\Xamarin.Android.Build.Tests\Utilities\EnvironmentHelper.cs:line 550
	   at Xamarin.Android.Build.Tests.EnvironmentHelper.AssertSharedLibraryHasRequiredSymbols(String dsoPath, String readElfPath) in C:\a\_work\1\s\src\Xamarin.Android.Build.Tasks\Tests\Xamarin.Android.Build.Tests\Utilities\EnvironmentHelper.cs:line 495
	   at Xamarin.Android.Build.Tests.EnvironmentHelper.AssertValidEnvironmentSharedLibrary(String outputDirectoryRoot, String sdkDirectory, String ndkDirectory, String supportedAbis) in C:\a\_work\1\s\src\Xamarin.Android.Build.Tasks\Tests\Xamarin.Android.Build.Tests\Utilities\EnvironmentHelper.cs:line 489

	-or-
	System.ComponentModel.Win32Exception : The system cannot find the file specified
	   at System.Diagnostics.Process.StartWithCreateProcess(ProcessStartInfo startInfo)
	   at Xamarin.Android.Build.Tests.EnvironmentHelper.RunCommand(String executablePath, String arguments) in /Users/builder/azdo/_work/1/s/xamarin-android/src/Xamarin.Android.Build.Tasks/Tests/Xamarin.Android.Build.Tests/Utilities/EnvironmentHelper.cs:line 551
	   at Xamarin.Android.Build.Tests.EnvironmentHelper.AssertSharedLibraryHasRequiredSymbols(String dsoPath, String readElfPath) in /Users/builder/azdo/_work/1/s/xamarin-android/src/Xamarin.Android.Build.Tasks/Tests/Xamarin.Android.Build.Tests/Utilities/EnvironmentHelper.cs:line 495
	   at Xamarin.Android.Build.Tests.EnvironmentHelper.AssertValidEnvironmentSharedLibrary(String outputDirectoryRoot, String sdkDirectory, String ndkDirectory, String supportedAbis) in /Users/builder/azdo/_work/1/s/xamarin-android/src/Xamarin.Android.Build.Tasks/Tests/Xamarin.Android.Build.Tests/Utilities/EnvironmentHelper.cs:line 489

This happened because `readelf` was *removed* in NDK r24.

Fix this pattern by updating `$(AndroidNdkDirectory)` to instead
default to `$(ANDROID_NDK_HOME)`, which is now NDK r23.
Additionally, update
`EnvironmentHelper.AssertValidEnvironmentSharedLibrary()` to also
look for `llvm-readelf`, the replacement for `readelf` in NDK r24+.

Pattern 2 is that the `aarch64-linux-android28-clang.cmd` & related
scripts on Windows don't support being run from a directory
containing spaces:

	CC="C:\a\_work\1\a\TestRelease\06-13_18.07.09\temp\SDK Ümläüts\ndk\toolchains\llvm\prebuilt\windows-x86_64\bin\armv7a-linux-androideabi19-clang.CMD"
	AS="C:\Program Files\Microsoft Visual Studio\2022\Enterprise\MSBuild\Xamarin\Android\binutils\bin\arm-linux-androideabi-as.CMD"
	…
	[CC] "C:\a\_work\1\a\TestRelease\06-13_18.07.09\temp\SDK Ümläüts\ndk\toolchains\llvm\prebuilt\windows-x86_64\bin\armv7a-linux-androideabi19-clang.CMD" ^
	  -c -D__ANDROID_API__=19 -DANDROID -o obj\Release\bundles\armeabi-v7a\temp.o ^
	  -I "C:\a\_work\1\a\TestRelease\06-13_18.07.09\temp\SDK Ümläüts\ndk\toolchains\llvm\prebuilt\windows-x86_64\sysroot\usr\include\arm-linux-androideabi" ^
	  -I "C:\a\_work\1\a\TestRelease\06-13_18.07.09\temp\SDK Ümläüts\ndk\toolchains\llvm\prebuilt\windows-x86_64\sysroot\usr\include" ^
	  obj\Release\bundles\armeabi-v7a\temp.c
	[cc stderr] 'C:\a\_work\1\a\TestRelease\06-13_18.07.09\temp\SDK' is not recognized as an internal or external command,
	[cc stderr] operable program or batch file.

Fix this pattern by updating `NdkToolsWithClangNoBinutils` to
override the C and C++ compiler toolnames, a'la: 71ae556.
jonpryor added a commit to jonpryor/xamarin-android that referenced this pull request Jun 14, 2022
Context: 70272db
Context: 38b1236
Context: https://github.com/actions/virtual-environments/blob/9cf1ebd754807fba137c8ce9fa2140311609fdd6/images/win/Windows2022-Readme.md
Context: actions/runner-images@2950cbf

Changes: http://github.com/xamarin/xamarin-android-tools/compare/20f611202bef0fc7c1659366dd38865eb119dde5...ec346d07cf3ac7fc74d08eae4f19043b51485724

  * dotnet/android-tools@ec346d0: [Xamarin.Android.Tools.AndroidSdk] Permit NDK r24 (dotnet#171)
  * dotnet/android-tools@47832f1: [Xamarin.Android.Tools.AndroidSdk] AndroidSdkInfo validation locator (dotnet#170)

We've had an "inadvertent thinko" for the past couple of months:
in commit 70272db we updated the default `$(AndroidNdkDirectory)`
value to be `$(ANDROID_NDK_LATEST_HOME)`, if set.  *At the time*,
we think this was NDK r23.

In commit 38b1236, we updated `xaprepare` to install NDK r24.

The "thinko" is that commit 38b1236 was *irrelevant*, as commit
70272db was "in control".  The Windows **Prepare Solution** log
would contain e.g.:

	  Checking if android-ndk-r24-windows exists in C:\Android\android-sdk\ndk\23.2.8568313
	  Component 'android-ndk-r24-windows' requires Pkg.Revision to be '24.0.8215888', verifying
	      installed

It also *mis-detected* NDK r23 as r24 (?!).

It "worked" only by coincidence.

Around 2022-Jun-09, GitHub actions updated the default NDK installed
on their Windows images; previously, `$(ANDROID_NDK_LATEST_HOME)` was
NDK r23 or earlier (we're not sure); *now*, it is NDK r24.

This subtle change -- invisible!  The build environment changed! --
*introduced* unit test failures, of two patterns.

Pattern 1 is that `readelf` could not be found:

	System.ComponentModel.Win32Exception : An error occurred trying to start process
	'C:\Android\android-sdk\ndk-bundle\toolchains\llvm\prebuilt\windows-x86_64\bin\readelf'
	with working directory 'C:\a_work\1\s\xamarin-android\bin\TestRelease\net6.0'.
	The system cannot find the file specified.
	   at System.Diagnostics.Process.StartWithCreateProcess(ProcessStartInfo startInfo)
	   at Xamarin.Android.Build.Tests.EnvironmentHelper.RunCommand(String executablePath, String arguments) in C:\a\_work\1\s\src\Xamarin.Android.Build.Tasks\Tests\Xamarin.Android.Build.Tests\Utilities\EnvironmentHelper.cs:line 550
	   at Xamarin.Android.Build.Tests.EnvironmentHelper.AssertSharedLibraryHasRequiredSymbols(String dsoPath, String readElfPath) in C:\a\_work\1\s\src\Xamarin.Android.Build.Tasks\Tests\Xamarin.Android.Build.Tests\Utilities\EnvironmentHelper.cs:line 495
	   at Xamarin.Android.Build.Tests.EnvironmentHelper.AssertValidEnvironmentSharedLibrary(String outputDirectoryRoot, String sdkDirectory, String ndkDirectory, String supportedAbis) in C:\a\_work\1\s\src\Xamarin.Android.Build.Tasks\Tests\Xamarin.Android.Build.Tests\Utilities\EnvironmentHelper.cs:line 489

	-or-
	System.ComponentModel.Win32Exception : The system cannot find the file specified
	   at System.Diagnostics.Process.StartWithCreateProcess(ProcessStartInfo startInfo)
	   at Xamarin.Android.Build.Tests.EnvironmentHelper.RunCommand(String executablePath, String arguments) in /Users/builder/azdo/_work/1/s/xamarin-android/src/Xamarin.Android.Build.Tasks/Tests/Xamarin.Android.Build.Tests/Utilities/EnvironmentHelper.cs:line 551
	   at Xamarin.Android.Build.Tests.EnvironmentHelper.AssertSharedLibraryHasRequiredSymbols(String dsoPath, String readElfPath) in /Users/builder/azdo/_work/1/s/xamarin-android/src/Xamarin.Android.Build.Tasks/Tests/Xamarin.Android.Build.Tests/Utilities/EnvironmentHelper.cs:line 495
	   at Xamarin.Android.Build.Tests.EnvironmentHelper.AssertValidEnvironmentSharedLibrary(String outputDirectoryRoot, String sdkDirectory, String ndkDirectory, String supportedAbis) in /Users/builder/azdo/_work/1/s/xamarin-android/src/Xamarin.Android.Build.Tasks/Tests/Xamarin.Android.Build.Tests/Utilities/EnvironmentHelper.cs:line 489

This happened because `readelf` was *removed* in NDK r24.

Fix this pattern updating
`EnvironmentHelper.AssertValidEnvironmentSharedLibrary()` to also
look for `llvm-readelf`, the replacement for `readelf` in NDK r24+.

Pattern 2 is that the `aarch64-linux-android28-clang.cmd` & related
scripts on Windows don't support being run from a directory
containing spaces:

	CC="C:\a\_work\1\a\TestRelease\06-13_18.07.09\temp\SDK Ümläüts\ndk\toolchains\llvm\prebuilt\windows-x86_64\bin\armv7a-linux-androideabi19-clang.CMD"
	AS="C:\Program Files\Microsoft Visual Studio\2022\Enterprise\MSBuild\Xamarin\Android\binutils\bin\arm-linux-androideabi-as.CMD"
	…
	[CC] "C:\a\_work\1\a\TestRelease\06-13_18.07.09\temp\SDK Ümläüts\ndk\toolchains\llvm\prebuilt\windows-x86_64\bin\armv7a-linux-androideabi19-clang.CMD" ^
	  -c -D__ANDROID_API__=19 -DANDROID -o obj\Release\bundles\armeabi-v7a\temp.o ^
	  -I "C:\a\_work\1\a\TestRelease\06-13_18.07.09\temp\SDK Ümläüts\ndk\toolchains\llvm\prebuilt\windows-x86_64\sysroot\usr\include\arm-linux-androideabi" ^
	  -I "C:\a\_work\1\a\TestRelease\06-13_18.07.09\temp\SDK Ümläüts\ndk\toolchains\llvm\prebuilt\windows-x86_64\sysroot\usr\include" ^
	  obj\Release\bundles\armeabi-v7a\temp.c
	[cc stderr] 'C:\a\_work\1\a\TestRelease\06-13_18.07.09\temp\SDK' is not recognized as an internal or external command,
	[cc stderr] operable program or batch file.

Fix this pattern by updating `NdkToolsWithClangNoBinutils` to
override the C and C++ compiler toolnames, a'la: 71ae556.
jonpryor added a commit to jonpryor/xamarin-android that referenced this pull request Jun 15, 2022
Context: 70272db
Context: 38b1236
Context: https://github.com/actions/virtual-environments/blob/9cf1ebd754807fba137c8ce9fa2140311609fdd6/images/win/Windows2022-Readme.md
Context: actions/runner-images@2950cbf

Changes: http://github.com/xamarin/xamarin-android-tools/compare/20f611202bef0fc7c1659366dd38865eb119dde5...ec346d07cf3ac7fc74d08eae4f19043b51485724

  * dotnet/android-tools@ec346d0: [Xamarin.Android.Tools.AndroidSdk] Permit NDK r24 (dotnet#171)
  * dotnet/android-tools@47832f1: [Xamarin.Android.Tools.AndroidSdk] AndroidSdkInfo validation locator (dotnet#170)

We've had an "inadvertent thinko" for the past couple of months:
in commit 70272db we updated the default `$(AndroidNdkDirectory)`
value to be `$(ANDROID_NDK_LATEST_HOME)`, if set.  *At the time*,
we think this was NDK r23.

In commit 38b1236, we updated `xaprepare` to install NDK r24.

The "thinko" is that commit 38b1236 was *irrelevant*, as commit
70272db was "in control".  The Windows **Prepare Solution** log
would contain e.g.:

	  Checking if android-ndk-r24-windows exists in C:\Android\android-sdk\ndk\23.2.8568313
	  Component 'android-ndk-r24-windows' requires Pkg.Revision to be '24.0.8215888', verifying
	      installed

It also *mis-detected* NDK r23 as r24 (?!).

It "worked" only by coincidence.

Around 2022-Jun-09, GitHub actions updated the default NDK installed
on their Windows images; previously, `$(ANDROID_NDK_LATEST_HOME)` was
NDK r23 or earlier (we're not sure); *now*, it is NDK r24.

This subtle change -- invisible!  The build environment changed! --
*introduced* unit test failures, of two patterns.

Pattern 1 is that `readelf` could not be found:

	System.ComponentModel.Win32Exception : An error occurred trying to start process
	'C:\Android\android-sdk\ndk-bundle\toolchains\llvm\prebuilt\windows-x86_64\bin\readelf'
	with working directory 'C:\a_work\1\s\xamarin-android\bin\TestRelease\net6.0'.
	The system cannot find the file specified.
	   at System.Diagnostics.Process.StartWithCreateProcess(ProcessStartInfo startInfo)
	   at Xamarin.Android.Build.Tests.EnvironmentHelper.RunCommand(String executablePath, String arguments) in C:\a\_work\1\s\src\Xamarin.Android.Build.Tasks\Tests\Xamarin.Android.Build.Tests\Utilities\EnvironmentHelper.cs:line 550
	   at Xamarin.Android.Build.Tests.EnvironmentHelper.AssertSharedLibraryHasRequiredSymbols(String dsoPath, String readElfPath) in C:\a\_work\1\s\src\Xamarin.Android.Build.Tasks\Tests\Xamarin.Android.Build.Tests\Utilities\EnvironmentHelper.cs:line 495
	   at Xamarin.Android.Build.Tests.EnvironmentHelper.AssertValidEnvironmentSharedLibrary(String outputDirectoryRoot, String sdkDirectory, String ndkDirectory, String supportedAbis) in C:\a\_work\1\s\src\Xamarin.Android.Build.Tasks\Tests\Xamarin.Android.Build.Tests\Utilities\EnvironmentHelper.cs:line 489

	-or-
	System.ComponentModel.Win32Exception : The system cannot find the file specified
	   at System.Diagnostics.Process.StartWithCreateProcess(ProcessStartInfo startInfo)
	   at Xamarin.Android.Build.Tests.EnvironmentHelper.RunCommand(String executablePath, String arguments) in /Users/builder/azdo/_work/1/s/xamarin-android/src/Xamarin.Android.Build.Tasks/Tests/Xamarin.Android.Build.Tests/Utilities/EnvironmentHelper.cs:line 551
	   at Xamarin.Android.Build.Tests.EnvironmentHelper.AssertSharedLibraryHasRequiredSymbols(String dsoPath, String readElfPath) in /Users/builder/azdo/_work/1/s/xamarin-android/src/Xamarin.Android.Build.Tasks/Tests/Xamarin.Android.Build.Tests/Utilities/EnvironmentHelper.cs:line 495
	   at Xamarin.Android.Build.Tests.EnvironmentHelper.AssertValidEnvironmentSharedLibrary(String outputDirectoryRoot, String sdkDirectory, String ndkDirectory, String supportedAbis) in /Users/builder/azdo/_work/1/s/xamarin-android/src/Xamarin.Android.Build.Tasks/Tests/Xamarin.Android.Build.Tests/Utilities/EnvironmentHelper.cs:line 489

This happened because `readelf` was *removed* in NDK r24.

Fix this pattern updating
`EnvironmentHelper.AssertValidEnvironmentSharedLibrary()` to also
look for `llvm-readelf`, the replacement for `readelf` in NDK r24+.

Pattern 2 is that the `aarch64-linux-android28-clang.cmd` & related
scripts on Windows don't support being run from a directory
containing spaces:

	CC="C:\a\_work\1\a\TestRelease\06-13_18.07.09\temp\SDK Ümläüts\ndk\toolchains\llvm\prebuilt\windows-x86_64\bin\armv7a-linux-androideabi19-clang.CMD"
	AS="C:\Program Files\Microsoft Visual Studio\2022\Enterprise\MSBuild\Xamarin\Android\binutils\bin\arm-linux-androideabi-as.CMD"
	…
	[CC] "C:\a\_work\1\a\TestRelease\06-13_18.07.09\temp\SDK Ümläüts\ndk\toolchains\llvm\prebuilt\windows-x86_64\bin\armv7a-linux-androideabi19-clang.CMD" ^
	  -c -D__ANDROID_API__=19 -DANDROID -o obj\Release\bundles\armeabi-v7a\temp.o ^
	  -I "C:\a\_work\1\a\TestRelease\06-13_18.07.09\temp\SDK Ümläüts\ndk\toolchains\llvm\prebuilt\windows-x86_64\sysroot\usr\include\arm-linux-androideabi" ^
	  -I "C:\a\_work\1\a\TestRelease\06-13_18.07.09\temp\SDK Ümläüts\ndk\toolchains\llvm\prebuilt\windows-x86_64\sysroot\usr\include" ^
	  obj\Release\bundles\armeabi-v7a\temp.c
	[cc stderr] 'C:\a\_work\1\a\TestRelease\06-13_18.07.09\temp\SDK' is not recognized as an internal or external command,
	[cc stderr] operable program or batch file.

Fix this pattern by updating `NdkToolsWithClangNoBinutils` to
override the C and C++ compiler toolnames, a'la: 71ae556.
jonpryor added a commit that referenced this pull request Jun 15, 2022
Context: 70272db
Context: 38b1236
Context: https://github.com/actions/virtual-environments/blob/9cf1ebd754807fba137c8ce9fa2140311609fdd6/images/win/Windows2022-Readme.md
Context: actions/runner-images@2950cbf

Changes: http://github.com/xamarin/xamarin-android-tools/compare/20f611202bef0fc7c1659366dd38865eb119dde5...ec346d07cf3ac7fc74d08eae4f19043b51485724

  * dotnet/android-tools@ec346d0: [Xamarin.Android.Tools.AndroidSdk] Permit NDK r24 (#171)
  * dotnet/android-tools@47832f1: [Xamarin.Android.Tools.AndroidSdk] AndroidSdkInfo validation locator (#170)

We've had an "inadvertent behavior" for the past couple of months:
in commit 70272db we updated the default `$(AndroidNdkDirectory)`
value to be `$(ANDROID_NDK_LATEST_HOME)`, if set.  *At the time*,
we think this was NDK r23.

In commit 38b1236, we updated `xaprepare` to install NDK r24.

This appears to have caused `xaprepare` to update the *system*
`$(ANDROID_NDK_LATEST_HOME)` location, not a xamarin-android-specific
NDK installation.  The Windows **Prepare Solution** log would
contain e.g.:

	  Checking if android-ndk-r24-windows exists in C:\Android\android-sdk\ndk\23.2.8568313
	  Component 'android-ndk-r24-windows' requires Pkg.Revision to be '24.0.8215888', verifying
	      installed

This appears to imply that `C:\Android\android-sdk\ndk\23.2.8568313`
was updated to have NDK 24.0.8215888.

Meanwhile, *unit tests* were using `$(ANDROID_SDK_PATH)` and
`$(ANDROID_NDK_PATH)`, which had been using NDK *r21*.

Around 2022-Jun-09, GitHub actions updated the default NDK installed
on their Windows images; previously, `$(ANDROID_NDK_LATEST_HOME)` was
NDK r23 or earlier (we're not sure); *now*, it is NDK r24.
`$(ANDROID_NDK_PATH)` had been NDK r21; now it is NDK r23.

This subtle change -- invisible!  The build environment changed! --
*introduced* unit test failures, of two patterns.

Scenario 1 is that `readelf` could not be found:

	System.ComponentModel.Win32Exception : An error occurred trying to start process
	'C:\Android\android-sdk\ndk-bundle\toolchains\llvm\prebuilt\windows-x86_64\bin\readelf'
	with working directory 'C:\a_work\1\s\xamarin-android\bin\TestRelease\net6.0'.
	The system cannot find the file specified.
	   at System.Diagnostics.Process.StartWithCreateProcess(ProcessStartInfo startInfo)
	   at Xamarin.Android.Build.Tests.EnvironmentHelper.RunCommand(String executablePath, String arguments) in C:\a\_work\1\s\src\Xamarin.Android.Build.Tasks\Tests\Xamarin.Android.Build.Tests\Utilities\EnvironmentHelper.cs:line 550
	   at Xamarin.Android.Build.Tests.EnvironmentHelper.AssertSharedLibraryHasRequiredSymbols(String dsoPath, String readElfPath) in C:\a\_work\1\s\src\Xamarin.Android.Build.Tasks\Tests\Xamarin.Android.Build.Tests\Utilities\EnvironmentHelper.cs:line 495
	   at Xamarin.Android.Build.Tests.EnvironmentHelper.AssertValidEnvironmentSharedLibrary(String outputDirectoryRoot, String sdkDirectory, String ndkDirectory, String supportedAbis) in C:\a\_work\1\s\src\Xamarin.Android.Build.Tasks\Tests\Xamarin.Android.Build.Tests\Utilities\EnvironmentHelper.cs:line 489

	-or-
	System.ComponentModel.Win32Exception : The system cannot find the file specified
	   at System.Diagnostics.Process.StartWithCreateProcess(ProcessStartInfo startInfo)
	   at Xamarin.Android.Build.Tests.EnvironmentHelper.RunCommand(String executablePath, String arguments) in /Users/builder/azdo/_work/1/s/xamarin-android/src/Xamarin.Android.Build.Tasks/Tests/Xamarin.Android.Build.Tests/Utilities/EnvironmentHelper.cs:line 551
	   at Xamarin.Android.Build.Tests.EnvironmentHelper.AssertSharedLibraryHasRequiredSymbols(String dsoPath, String readElfPath) in /Users/builder/azdo/_work/1/s/xamarin-android/src/Xamarin.Android.Build.Tasks/Tests/Xamarin.Android.Build.Tests/Utilities/EnvironmentHelper.cs:line 495
	   at Xamarin.Android.Build.Tests.EnvironmentHelper.AssertValidEnvironmentSharedLibrary(String outputDirectoryRoot, String sdkDirectory, String ndkDirectory, String supportedAbis) in /Users/builder/azdo/_work/1/s/xamarin-android/src/Xamarin.Android.Build.Tasks/Tests/Xamarin.Android.Build.Tests/Utilities/EnvironmentHelper.cs:line 489

This happened because `readelf` was *removed* in NDK r24.

Fix this scenario updating
`EnvironmentHelper.AssertValidEnvironmentSharedLibrary()` to also
look for `llvm-readelf`, the replacement for `readelf` in NDK r24+.

Scenario 2 is that the `aarch64-linux-android28-clang.cmd` & related
scripts on Windows in NDK r23+ don't support being run from a
directory containing spaces:

	CC="C:\a\_work\1\a\TestRelease\06-13_18.07.09\temp\SDK Ümläüts\ndk\toolchains\llvm\prebuilt\windows-x86_64\bin\armv7a-linux-androideabi19-clang.CMD"
	AS="C:\Program Files\Microsoft Visual Studio\2022\Enterprise\MSBuild\Xamarin\Android\binutils\bin\arm-linux-androideabi-as.CMD"
	…
	[CC] "C:\a\_work\1\a\TestRelease\06-13_18.07.09\temp\SDK Ümläüts\ndk\toolchains\llvm\prebuilt\windows-x86_64\bin\armv7a-linux-androideabi19-clang.CMD" ^
	  -c -D__ANDROID_API__=19 -DANDROID -o obj\Release\bundles\armeabi-v7a\temp.o ^
	  -I "C:\a\_work\1\a\TestRelease\06-13_18.07.09\temp\SDK Ümläüts\ndk\toolchains\llvm\prebuilt\windows-x86_64\sysroot\usr\include\arm-linux-androideabi" ^
	  -I "C:\a\_work\1\a\TestRelease\06-13_18.07.09\temp\SDK Ümläüts\ndk\toolchains\llvm\prebuilt\windows-x86_64\sysroot\usr\include" ^
	  obj\Release\bundles\armeabi-v7a\temp.c
	[cc stderr] 'C:\a\_work\1\a\TestRelease\06-13_18.07.09\temp\SDK' is not recognized as an internal or external command,
	[cc stderr] operable program or batch file.

Fix this scenario by updating `NdkToolsWithClangNoBinutils` to
override the C and C++ compiler toolnames, a'la commit 71ae556.

To help make investigating
`AndroidDependenciesTests.InstallAndroidDependenciesTest()` tests
failures easier, send the `InstallAndroidDependencies` target
execution output to an `install-deps.log` file.  Previously, the
subsequent `Build` target would *overwrite* the output of the
`InstallAndroidDependencies` output, as they both shared `build.log`.

Finally, update `AndroidSdkResolver.GetAndroidSdkPath()` and
`AndroidSdkResolver.GetAndroidNdkPath()` to *stop* looking at the
`$(ANDROID_SDK_PATH)` and `$(ANDROID_NDK_PATH)` environment variables.
Instead, unit tests should use the `$(TEST_ANDROID_SDK_PATH)`
environment variable, which is managed by the unit test
infrastructure.
jonathanpeppers pushed a commit that referenced this pull request Jun 16, 2022
Context: 70272db
Context: 38b1236
Context: https://github.com/actions/virtual-environments/blob/9cf1ebd754807fba137c8ce9fa2140311609fdd6/images/win/Windows2022-Readme.md
Context: actions/runner-images@2950cbf

Changes: http://github.com/xamarin/xamarin-android-tools/compare/20f611202bef0fc7c1659366dd38865eb119dde5...ec346d07cf3ac7fc74d08eae4f19043b51485724

  * dotnet/android-tools@ec346d0: [Xamarin.Android.Tools.AndroidSdk] Permit NDK r24 (#171)
  * dotnet/android-tools@47832f1: [Xamarin.Android.Tools.AndroidSdk] AndroidSdkInfo validation locator (#170)

We've had an "inadvertent behavior" for the past couple of months:
in commit 70272db we updated the default `$(AndroidNdkDirectory)`
value to be `$(ANDROID_NDK_LATEST_HOME)`, if set.  *At the time*,
we think this was NDK r23.

In commit 38b1236, we updated `xaprepare` to install NDK r24.

This appears to have caused `xaprepare` to update the *system*
`$(ANDROID_NDK_LATEST_HOME)` location, not a xamarin-android-specific
NDK installation.  The Windows **Prepare Solution** log would
contain e.g.:

	  Checking if android-ndk-r24-windows exists in C:\Android\android-sdk\ndk\23.2.8568313
	  Component 'android-ndk-r24-windows' requires Pkg.Revision to be '24.0.8215888', verifying
	      installed

This appears to imply that `C:\Android\android-sdk\ndk\23.2.8568313`
was updated to have NDK 24.0.8215888.

Meanwhile, *unit tests* were using `$(ANDROID_SDK_PATH)` and
`$(ANDROID_NDK_PATH)`, which had been using NDK *r21*.

Around 2022-Jun-09, GitHub actions updated the default NDK installed
on their Windows images; previously, `$(ANDROID_NDK_LATEST_HOME)` was
NDK r23 or earlier (we're not sure); *now*, it is NDK r24.
`$(ANDROID_NDK_PATH)` had been NDK r21; now it is NDK r23.

This subtle change -- invisible!  The build environment changed! --
*introduced* unit test failures, of two patterns.

Scenario 1 is that `readelf` could not be found:

	System.ComponentModel.Win32Exception : An error occurred trying to start process
	'C:\Android\android-sdk\ndk-bundle\toolchains\llvm\prebuilt\windows-x86_64\bin\readelf'
	with working directory 'C:\a_work\1\s\xamarin-android\bin\TestRelease\net6.0'.
	The system cannot find the file specified.
	   at System.Diagnostics.Process.StartWithCreateProcess(ProcessStartInfo startInfo)
	   at Xamarin.Android.Build.Tests.EnvironmentHelper.RunCommand(String executablePath, String arguments) in C:\a\_work\1\s\src\Xamarin.Android.Build.Tasks\Tests\Xamarin.Android.Build.Tests\Utilities\EnvironmentHelper.cs:line 550
	   at Xamarin.Android.Build.Tests.EnvironmentHelper.AssertSharedLibraryHasRequiredSymbols(String dsoPath, String readElfPath) in C:\a\_work\1\s\src\Xamarin.Android.Build.Tasks\Tests\Xamarin.Android.Build.Tests\Utilities\EnvironmentHelper.cs:line 495
	   at Xamarin.Android.Build.Tests.EnvironmentHelper.AssertValidEnvironmentSharedLibrary(String outputDirectoryRoot, String sdkDirectory, String ndkDirectory, String supportedAbis) in C:\a\_work\1\s\src\Xamarin.Android.Build.Tasks\Tests\Xamarin.Android.Build.Tests\Utilities\EnvironmentHelper.cs:line 489

	-or-
	System.ComponentModel.Win32Exception : The system cannot find the file specified
	   at System.Diagnostics.Process.StartWithCreateProcess(ProcessStartInfo startInfo)
	   at Xamarin.Android.Build.Tests.EnvironmentHelper.RunCommand(String executablePath, String arguments) in /Users/builder/azdo/_work/1/s/xamarin-android/src/Xamarin.Android.Build.Tasks/Tests/Xamarin.Android.Build.Tests/Utilities/EnvironmentHelper.cs:line 551
	   at Xamarin.Android.Build.Tests.EnvironmentHelper.AssertSharedLibraryHasRequiredSymbols(String dsoPath, String readElfPath) in /Users/builder/azdo/_work/1/s/xamarin-android/src/Xamarin.Android.Build.Tasks/Tests/Xamarin.Android.Build.Tests/Utilities/EnvironmentHelper.cs:line 495
	   at Xamarin.Android.Build.Tests.EnvironmentHelper.AssertValidEnvironmentSharedLibrary(String outputDirectoryRoot, String sdkDirectory, String ndkDirectory, String supportedAbis) in /Users/builder/azdo/_work/1/s/xamarin-android/src/Xamarin.Android.Build.Tasks/Tests/Xamarin.Android.Build.Tests/Utilities/EnvironmentHelper.cs:line 489

This happened because `readelf` was *removed* in NDK r24.

Fix this scenario updating
`EnvironmentHelper.AssertValidEnvironmentSharedLibrary()` to also
look for `llvm-readelf`, the replacement for `readelf` in NDK r24+.

Scenario 2 is that the `aarch64-linux-android28-clang.cmd` & related
scripts on Windows in NDK r23+ don't support being run from a
directory containing spaces:

	CC="C:\a\_work\1\a\TestRelease\06-13_18.07.09\temp\SDK Ümläüts\ndk\toolchains\llvm\prebuilt\windows-x86_64\bin\armv7a-linux-androideabi19-clang.CMD"
	AS="C:\Program Files\Microsoft Visual Studio\2022\Enterprise\MSBuild\Xamarin\Android\binutils\bin\arm-linux-androideabi-as.CMD"
	…
	[CC] "C:\a\_work\1\a\TestRelease\06-13_18.07.09\temp\SDK Ümläüts\ndk\toolchains\llvm\prebuilt\windows-x86_64\bin\armv7a-linux-androideabi19-clang.CMD" ^
	  -c -D__ANDROID_API__=19 -DANDROID -o obj\Release\bundles\armeabi-v7a\temp.o ^
	  -I "C:\a\_work\1\a\TestRelease\06-13_18.07.09\temp\SDK Ümläüts\ndk\toolchains\llvm\prebuilt\windows-x86_64\sysroot\usr\include\arm-linux-androideabi" ^
	  -I "C:\a\_work\1\a\TestRelease\06-13_18.07.09\temp\SDK Ümläüts\ndk\toolchains\llvm\prebuilt\windows-x86_64\sysroot\usr\include" ^
	  obj\Release\bundles\armeabi-v7a\temp.c
	[cc stderr] 'C:\a\_work\1\a\TestRelease\06-13_18.07.09\temp\SDK' is not recognized as an internal or external command,
	[cc stderr] operable program or batch file.

Fix this scenario by updating `NdkToolsWithClangNoBinutils` to
override the C and C++ compiler toolnames, a'la commit 71ae556.

To help make investigating
`AndroidDependenciesTests.InstallAndroidDependenciesTest()` tests
failures easier, send the `InstallAndroidDependencies` target
execution output to an `install-deps.log` file.  Previously, the
subsequent `Build` target would *overwrite* the output of the
`InstallAndroidDependencies` output, as they both shared `build.log`.

Finally, update `AndroidSdkResolver.GetAndroidSdkPath()` and
`AndroidSdkResolver.GetAndroidNdkPath()` to *stop* looking at the
`$(ANDROID_SDK_PATH)` and `$(ANDROID_NDK_PATH)` environment variables.
Instead, unit tests should use the `$(TEST_ANDROID_SDK_PATH)`
environment variable, which is managed by the unit test
infrastructure.
@github-actions github-actions bot locked and limited conversation to collaborators Feb 6, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

7 participants