Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[create-android-api] Centralize API*.xml file generation (#7054)
Context: 5432886 *One* issue with running `dotnet build Xamarin.Android.sln` without `-m:1` (5432886) is that it attempts to run our Android API extraction process multiple times simultaneously. This results in file locking issues: C:\code\xamarin-android\src\Mono.Android\Mono.Android.targets(409,5): "C:\code\xamarin-android\src\Mono.Android\..\..\bin\Debug\lib\xamarin.android\xbuild\Xamarin\Android\class-parse.exe C:\…\android-toolchain\sdk\platforms\android-26\android.jar -platform=26 -parameter-names="C:\code\xamarin-android\src\Mono.Android\..\..\src\Mono.Android\Profiles\api-26.params.txt" -o="C:\code\xamarin-android\src\Mono.Android\..\..\bin\BuildDebug\api\api-26.xml.class-parse"" failed with code: -532462766 Error output: Unhandled Exception: System.IO.IOException: The process cannot access the file 'C:\code\xamarin-android\bin\BuildDebug\api\api-26.xml.class-parse' because it is being used by another process. at System.IO.__Error.WinIOError(Int32 errorCode, String maybeFullPath) at System.IO.FileStream.Init(String path, FileMode mode, FileAccess access, Int32 rights, Boolean useRights, FileShare share, Int32 bufferSize, FileOptions options, SECURITY_ATTRIBUTES secAttrs, String msgPath, Boolean bFromProxy, Boolean useLongPath, Boolean checkHost) at System.IO.FileStream..ctor(String path, FileMode mode, FileAccess access, FileShare share, Int32 bufferSize, FileOptions options, String msgPath, Boolean bFromProxy, Boolean useLongPath, Boolean checkHost) at System.IO.StreamWriter.CreateFile(String path, Boolean append, Boolean checkHost) at System.IO.StreamWriter..ctor(String path, Boolean append, Encoding encoding, Int32 bufferSize, Boolean checkHost) at System.IO.StreamWriter..ctor(String path, Boolean append, Encoding encoding) at Xamarin.Android.Tools.App.Main(String[] args) in C:\code\xamarin-android\external\Java.Interop\tools\class-parse\Program.cs:line 68 [C:\code\xamarin-android\src\Mono.Android\Mono.Android.csproj] This seems to be a result of running the process as an `AfterTargets="Build"` target in `api-xml-adjuster.csproj`. By moving it to a `NoTargets` project, we can eliminate MSBuild trying to run it multiple times. Move the `class-parse` execution to a new `create-android-api.csproj` project. Also, move the `api-merge` step into `create-android-api.csproj`, from `Mono.Android.targets`. Currently the `pai-merge` process runs twice, once for `monoandroid10` and once for `net7.0`. However, the output is not dependent on `TargetFramework`. Instead of generating: - `src\Mono.Android\obj\Debug\monoandroid10\android-32\mcw\api.xml` - `src\Mono.Android\obj\Debug\net7.0\android-32\mcw\api.xml` we will now generate: - `bin\Build$(Configuration)\api\api-32.xml` Calling `api-merge` only once saves ~25s from build time. Note that `generator` writes intermediate files (eg: `api.xml.fixed`) to the directory containing `api.xml`, so `Mono.Android.targets` will copy the `api-X.xml` file to its eg: `obj\Debug\net7.0\android-32\mcw` directory to work from. Without this, both `monoadroid10` and `net7.0` would write to the common location, causing possible file sharing conflicts. Additionally, let VS2022 rewrite `Xamarin.Android.sln` to its preferred format in order to add the new project.
- Loading branch information