Xamarin.Android build preparation utility#3051
Conversation
e8ae026 to
bc91e42
Compare
CODEOWNERS
Outdated
| /build-tools/manifest-attribute-codegen @jonpryor | ||
| /build-tools/scripts/PrepareWindows.targets @jonathanpeppers | ||
| /build-tools/timing @jonathanpeppers @radekdoulik | ||
| /build-tools/xabootstrap @grendello |
There was a problem hiding this comment.
Minor nitpick: should this be bootstrap or prepare? It's not like we're going to have multiple bootstrap systems in here...
Makefile
Outdated
| msbuild $(BOOTSTRAP_MSBUILD_ARGS) $(BOOTSTRAP_SOLUTION) | ||
|
|
||
| bootstrap: | ||
| $(MAKE) bootstrap-build |
There was a problem hiding this comment.
Why call $(MAKE) instead of depending on the bootstrap-build target?
ThirdPartyNotices.txt
Outdated
|
|
||
| 1. bazelbuild/bazel (https://github.com/bazelbuild/bazel/) | ||
| 2. google/desugar (https://android.googlesource.com/platform/external/desugar/+/master/) | ||
| 3. mono/boringssl (https://github.com/mono/boringssl) |
There was a problem hiding this comment.
These changes imply that we're doing the wrong thing for the repo ThirdPartyNotices.txt file. The purpose of the repo-level ThirdPartyNotices.txt are for third party dependencies copied into this repo, not from submodules or NuGet packages or the like.
boringssl is included via submodule. linker is included via submodule. etc. These do not need to be present within this ThirdPartyNotices.txt file.
Third party code such as this does need to be listed in the generated and included-within-the-installer bin/$(Configuration)/lib/xamarin.android/ThirdPartyNotices.txt file.
|
Why is |
| @@ -0,0 +1,2 @@ | |||
| http://www.kajabity.com | |||
There was a problem hiding this comment.
There should be a README.md in this directory with required documentation...
There was a problem hiding this comment.
Accidentally added, probably coming from the nuget
| @@ -0,0 +1,12 @@ | |||
| # Files to remove | |||
There was a problem hiding this comment.
This feels like material for README.md. Alternatively, more details need to be here.
For example, what constitutes "the migration"? How will this interact with checking out different branches?
There was a problem hiding this comment.
It's just notes to myself, so that I don't forget to remove stuff later on (there's a LOT of it around).
| { | ||
| partial class Windows : Dependencies | ||
| { | ||
| }; |
There was a problem hiding this comment.
This isn't C++; trailing ; isn't needed. :-)
| Dependencies.AddRange (programs); | ||
| Log.Todo ("special treatment for Mono - version checks and such"); | ||
| } | ||
| }; |
There was a problem hiding this comment.
This isn't C++; trailing ; isn't needed. :-)
| new AndroidPlatformComponent ("platform-28_r04", "28"), | ||
|
|
||
| // arguments are: string name, string destDir, Uri relativeUrl = null, bool isMultiVersion = false, bool noSubdirectory = false | ||
| { "docs-24_r01", "docs"}, |
There was a problem hiding this comment.
I think this would be easier to read & understand if the extension method weren't used here. I'd never previously considered adding an List<SpecificType>.Add(args...) extension method before, and had to pause for a bit to understand what was going on.
|
|
||
| public static readonly List<AndroidPlatform> AllPlatforms = new List<AndroidPlatform> { | ||
| // API, ID, Framework, Stable | ||
| { 0, "0", null, false }, |
There was a problem hiding this comment.
Likewise here: I'd never considered the ability to add a List<AndroidPlatform>.Add(...) extension method before. While "interesting", I'm not sure it's clearer than the alternative of new AndroidPlatform(...).
Additionally, while the extension method does add argument validation, ensuring that e.g. only one API-1 is added, that means each Add() call is O(n) instead of (amortized) O(1). This shouldn't matter with a list this small, but it is...odd.
| { | ||
| static readonly Uri url = new Uri ("http://not.an/item"); | ||
|
|
||
| public override string LicenseText => "not a license item"; |
There was a problem hiding this comment.
What happened with the indentation here?
| namespace Xamarin.Android.Bootstrap | ||
| { | ||
| [AttributeUsage (AttributeTargets.Class)] | ||
| class TPNAttribute : Attribute |
There was a problem hiding this comment.
Tabs, not spaces, please. :-)
| { "docs-24_r01", "docs"}, | ||
| { "android_m2repository_r16", Path.Combine ("extras", "android", "m2repository")}, | ||
| { "x86-28_r04", Path.Combine ("system-images", "android-28", "default", "x86"), new Uri ("sys-img/android/", UriKind.Relative)}, | ||
| {$"android-ndk-r{AndroidNdkVersion}-{osTag}-x86_64", AndroidNdkDirectory}, |
There was a problem hiding this comment.
Apparently AndroidNdkVersion isn't set when expected/required, because when the build attempts to download this url, it fails:
error : Unable to download URL `https://dl.google.com/android/repository/android-ndk-r-darwin-x86_64.zip` to `/Users/builder/android-archives/android-ndk-r-darwin-x86_64.zip`: Response status code does not indicate success: 404
There was a problem hiding this comment.
BuildAndroidPlatforms.AndroidNdkVersion is const; how could this not be set/available here?
There was a problem hiding this comment.
The build fails because it uses make prepare and not the new bootstrapper which changed the way NDK references work. At this moment the build failure is expected, until I make the new bootstrapper the "default" in this PR
|
Also needed is some form of documentation, not just in There's a new |
|
Given that e.g. |
3629b10 to
973368b
Compare
f19fb36 to
e0517cd
Compare
|
So... the commercial pipeline failure is very mysterious, with a possible workaround. The failure is: Time Elapsed 00:13:55.37
build-tools/scripts/BuildEverything.mk:12: *** non-numeric first argument to `word' function: ''. Stop.This is caused by the Running Having said that, I'm currently running local |
|
The local rebuild with make debugging didn't reveal much: |
|
Soooo... Clutching at straws at its best, but... it worked! The solution to the problem (at least locally) was to rename the |
|
Aaaand... it didn't work on the bot :( |
There was a problem hiding this comment.
I tried the latest changes on Windows again, as of 860732a.
I can build & run the bootstrapper:
# NOTE: I have a 'nuget' powershell alias that points to a NuGet.exe
> nuget restore .\build-tools\xaprepare\xaprepare.sln
> msbuild .\build-tools\xaprepare\xaprepare.sln
> .\build-tools\xaprepare\xaprepare\bin\Debug\xaprepare.exe
Unfortunately xaprepare.exe fails with:
Step Xamarin.Android.Prepare.Step_InstallCorrettoOpenJDK failed: The process cannot access the file because it is being used by another process. System.InvalidOperationException: Step Xamarin.Android.Prepare.Step_InstallCorrettoOpenJDK failed: The process cannot access the file because it is being used by another process. ---> System.IO.IOException: The process cannot access the file because it is being used by another process. at System.IO.__Error.WinIOError(Int32 errorCode, String maybeFullPath) at System.IO.__Error.WinIOError() at System.IO.File.InternalMove(String sourceFileName, String destFileName, Boolean checkHost) at System.IO.File.Move(String sourceFileName, String destFileName) at Xamarin.Android.Prepare.Utilities.MoveDirectory(String sourceDir, String destinationDir) in C:\src\xamarin-android\build-tools\xaprepare\xaprepare\Application\Utilities.cs:line 472 at Xamarin.Android.Prepare.Utilities.MoveDirectory(String sourceDir, String destinationDir) in C:\src\xamarin-android\build-tools\xaprepare\xaprepare\Application\Utilities.cs:line 464 at Xamarin.Android.Prepare.Utilities.MoveDirectoryContentsRecursively(String sourceDir, String destinationDir) in C:\src\xamarin-android\build-tools\xaprepare\xaprepare\Application\Utilities.cs:line 447 at Xamarin.Android.Prepare.Step_InstallCorrettoOpenJDK.<Execute>d__2.MoveNext() in C:\src\xamarin-android\build-tools\xaprepare\xaprepare\Steps\Step_InstallCorrettoOpenJDK.cs:line 61 --- End of stack trace from previous location where exception was thrown --- at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task) at System.Runtime.CompilerServices.TaskAwaiter`1.GetResult() at Xamarin.Android.Prepare.Step.<Run>d__17.MoveNext() in C:\src\xamarin-android\build-tools\xaprepare\xaprepare\Application\Step.cs:line 42 --- End of stack trace from previous location where exception was thrown --- at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task) at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task) at System.Runtime.CompilerServices.TaskAwaiter`1.GetResult() at Xamarin.Android.Prepare.Scenario.<Run>d__14.MoveNext() in C:\src\xamarin-android\build-tools\xaprepare\xaprepare\Application\Scenario.cs:line 33 --- End of inner exception stack trace --- at Xamarin.Android.Prepare.Scenario.<Run>d__14.MoveNext() in C:\src\xamarin-android\build-tools\xaprepare\xaprepare\Application\Scenario.cs:line 44 --- End of stack trace from previous location where exception was thrown --- at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task) at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task) at System.Runtime.CompilerServices.TaskAwaiter.GetResult() at Xamarin.Android.Prepare.Context.<Execute>d__182.MoveNext() in C:\src\xamarin-android\build-tools\xaprepare\xaprepare\Application\Context.cs:line 753 --- End of stack trace from previous location where exception was thrown --- at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task) at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task) at System.Runtime.CompilerServices.TaskAwaiter`1.GetResult() at Xamarin.Android.Prepare.App.<Run>d__3.MoveNext() in C:\src\xamarin-android\build-tools\xaprepare\xaprepare\Main.cs:line 154
Here are the logs I think it made: BuildDebug.zip
If I run it again, I get:
System.IO.IOException: The handle is invalid.
at System.IO.__Error.WinIOError(Int32 errorCode, String maybeFullPath)
at System.IO.__Error.WinIOError()
at System.Console.set_CursorVisible(Boolean value)
at Xamarin.Android.Prepare.App.Main(String[] args) in C:\src\xamarin-android\build-tools\xaprepare\xaprepare\Main.cs:line 37
build-tools/automation/build.groovy
Outdated
|
|
||
| utils.stageWithTimeout('build', 6, 'HOURS', XADir, true) { // Typically takes less than one hour except a build on a new bot to populate local caches can take several hours | ||
| sh "make prepare ${buildTarget} CONFIGURATION=${env.BuildFlavor} V=1 MSBUILD_ARGS='$EXTRA_MSBUILD_ARGS'" | ||
| sh "make prepare-update-mono CONFIGURATION=${env.BuildFlavor} V=1 PREPARE_CI=1 MSBUILD_ARGS='$EXTRA_MSBUILD_ARGS'" |
There was a problem hiding this comment.
Indentation is wrong here; looks like a tabs-vs-spaces problem.
| def XADir = "xamarin-android" | ||
| def buildTarget = 'jenkins' | ||
| def chRootPackages = 'xvfb xauth mono-devel autoconf automake build-essential vim-common p7zip-full cmake gettext libtool libgdk-pixbuf2.0-dev intltool pkg-config ruby scons wget xz-utils git nuget ca-certificates-mono clang g++-mingw-w64 gcc-mingw-w64 libzip-dev zulu-8 unzip lib32stdc++6 lib32z1 libtinfo-dev:i386 linux-libc-dev:i386 zlib1g-dev:i386 gcc-multilib g++-multilib referenceassemblies-pcl zip fsharp psmisc libz-mingw-w64-dev msbuild mono-csharp-shell devscripts fakeroot debhelper libsqlite3-dev sqlite3 libc++-dev cli-common-dev curl libncurses-dev' | ||
| def chRootPackages = 'ant xvfb xauth mono-devel autoconf automake build-essential vim-common p7zip-full cmake gettext libtool libtool-bin libgdk-pixbuf2.0-dev intltool pkg-config ruby scons wget xz-utils git nuget ca-certificates-mono clang g++-mingw-w64 gcc-mingw-w64 libzip-dev zulu-8 unzip lib32stdc++6 lib32z1 libtinfo-dev:i386 linux-libc-dev:i386 zlib1g-dev:i386 gcc-multilib g++-multilib referenceassemblies-pcl zip fsharp psmisc libz-mingw-w64-dev msbuild mono-csharp-shell devscripts fakeroot debhelper libsqlite3-dev sqlite3 libc++-dev cli-common-dev curl libncurses-dev ninja-build' |
There was a problem hiding this comment.
I know, I'm waiting for the current build to finish
build-tools/xaprepare/README.md
Outdated
|
|
||
| ## Introduction | ||
|
|
||
| The task and purpose of this utility is to prepare the ``Xamarin.Android` source tree for build by |
There was a problem hiding this comment.
Too many backticks, screwing up formatting, and I assume you mean "xamarin-android source tree".
There was a problem hiding this comment.
I meant the product name - Xamarin.Android - not GitHub repo name xamarin-android
build-tools/xaprepare/README.md
Outdated
| the repository is freshly cloned. | ||
|
|
||
| The utility is written in C# as a .NET 4.7 console app and does not depend on any other code within the | ||
| `Xamarin.Android` repository. |
There was a problem hiding this comment.
It's the xamarin-android repository.
jonathanpeppers
left a comment
There was a problem hiding this comment.
This time I was able to do:
- Downloaded this bundle and put it in
~\android-archives > msbuild Xamarin.Android.sln /t:Prepare> msbuild Xamarin.Android.sln-> this one didn't quite work
After step 2, I should have a Configuration.OperatingSystem.props, with the paths to java setup, etc. I get failures like:
"C:\src\xamarin-android\src\r8\r8.csproj" (default target) (26:2) ->
(_BuildR8 target) ->
EXEC : error : JAVA_HOME is not set and no 'java' command could be found in your PATH. [C:\src\xamarin-android\src\r8\r8.csproj]
C:\src\xamarin-android\src\r8\r8.targets(20,5): error MSB3073: The command ""C:\src\xamarin-android\build-tools\gradle\gradlew" jar --stacktrace --no-daemon" exited with code 1.
xamarin-android/master current generates this Configuration.OperatingSystem.props on my machine:
<?xml version="1.0" encoding="utf-8"?> <Project DefaultTargets="Build" ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<PropertyGroup>
<HostOS Condition=" '$(HostOS)' == '' ">Windows</HostOS>
<HostOsName Condition=" '$(HostOsName)' == '' ">Windows</HostOsName>
<HostOsRelease Condition=" '$(HostOsRelease)' == '' ">10</HostOsRelease>
<HostTriplet Condition=" '$(HostTriplet)' == '' ">x86_64-win32</HostTriplet>
<HostTriplet32 Condition=" '$(HostTriplet32)' == '' ">i386-win32</HostTriplet32>
<HostTriplet64 Condition=" '$(HostTriplet64)' == '' ">x86_64-win32</HostTriplet64>
<HostCpuCount Condition=" '$(HostCpuCount)' == '' ">$([System.Environment]::ProcessorCount)</HostCpuCount>
<HostBits Condition=" '$(HostBits)' == '' ">64</HostBits>
<JavaSdkDirectory Condition=" '$(JavaSdkDirectory)' == '' ">C:\Program Files (x86)\Java\jdk1.8.0_161</JavaSdkDirectory>
<JavaCPath Condition=" '$(JavaCPath)' == '' ">$(JavaSdkDirectory)\bin\javac.exe</JavaCPath>
<JarPath Condition=" '$(JarPath)' == '' ">$(JavaSdkDirectory)\bin\jar.exe</JarPath>
<JavaPath Condition=" '$(JavaPath)' == '' ">$(JavaSdkDirectory)\bin\java.exe</JavaPath>
</PropertyGroup>
</Project>I also get some NuGet-related failures like:
"C:\src\xamarin-android\external\xamarin-android-tools\src\Xamarin.Android.Tools.AndroidSdk\Tests\Xamarin.Android.Tools.AndroidSdk-Tests.csproj" (default target) (53) ->
(CoreCompile target) ->
AndroidVersionTests.cs(5,7): error CS0246: The type or namespace name 'NUnit' could not be found (are you missing a using directive or an assembly reference?)
Does anything run?
> nuget restore .\external\xamarin-android-tools\Xamarin.Android.Tools.sln
| <PropertyGroup> | ||
| <_AzureBaseUri>https://xamjenkinsartifact.azureedge.net/mono-jenkins/</_AzureBaseUri> | ||
| <_NuGetUri>https://dist.nuget.org/win-x86-commandline/v4.7.1/nuget.exe</_NuGetUri> | ||
| <_NuGetPath>$(MSBuildThisFileDirectory)\..\..\.nuget</_NuGetPath> |
There was a problem hiding this comment.
Can we remove all this nuget.exe stuff here?
| return false; | ||
| } | ||
|
|
||
| throw new InvalidOperationException ($"Failed to access bundle at {bundleUrl} (HTTP status: {status})"); |
There was a problem hiding this comment.
Could this use the error message we have here: https://github.com/xamarin/xamarin-android/blob/46b4c53dc69e41db905bc4b62393d9c8d064d425/build-tools/download-bundle/download-bundle.targets#L32
I think it explains to external contributors a little better.
There might be some other places in here that would hit, this too?
|
Actually @grendello it prints this: But then I see it doesn't have a Both Windows & macOS should have the path to the Coretto java that got installed I think? |
Updated the code to set |
|
@monojenkins build |
Testing: * Default mode: run `make prepare` * Verbose debug: run `make V=1 prepare` * CI mode: run `make PREPARE_CI=1 prepare` * Help: run `make prepare-help` * Logs: `bin/BuildDebug` Supported operating systems: * macOS * Linux Windows support is planned, present but not fully implemented or tested. This commit implements a `make prepare` replacement that does not rely on shell scripts or MSBuild. The idea is that a standalone C# program can perform all the steps in a more streamlined, more clear way than the current solution. One of the main goals is to make the process more approachable by external contributors, but also by the core developers who may want to change some aspects of XA build preparation (e.g. Android platforms, Mono version etc) but are not familiar with the build system. Towards that goal, the codebase is designed so that the minimum amount of searching around it is necessary to figure out where to make the desired change. Main location serving this purpose is the `build-tools/xaprepare/xaprepare/ConfigAndData` directory. It should be the *only* location where one needs to look in order to change all and any aspects of XA preparation. [TBC]
Usage: `xaprepare.exe -s=AndroidToolchain` The step will *only* install Android SDK+NDK as well as the OpenJDK distribution we provision. No other programs are installed or updated.
Allows a non-authorized https-based clone for local use cases, and cleans up various logging events to ensure we don't leak secrets. Also includes some minor azure-pipelines.yaml cleanup.
Testing:
make preparemake V=1 preparemake PREPARE_CI=1 preparemake prepare-helpbin/BuildDebugSupported operating systems:
Windows support is planned, present but not fully implemented or tested.
This commit implements a
make preparereplacement that does not rely on shellscripts or MSBuild. The idea is that a standalone C# program can perform all the
steps in a more streamlined, more clear way than the current solution. One of
the main goals is to make the process more approachable by external
contributors, but also by the core developers who may want to change some
aspects of XA build preparation (e.g. Android platforms, Mono version etc) but
are not familiar with the build system. Towards that goal, the codebase is
designed so that the minimum amount of searching around it is necessary to
figure out where to make the desired change. Main location serving this purpose
is the
build-tools/xaprepare/xaprepare/ConfigAndDatadirectory. It shouldbe the only location where one needs to look in order to change all and any
aspects of XA preparation.
[TBC]