Skip to content

[xabt] Enable MT execution for ResolveAndroidTooling - #13323

Merged
jonathanpeppers merged 3 commits into
mainfrom
jonathanpeppers-mt-android-tooling
Oct 30, 2026
Merged

jonathanpeppers merged 3 commits into
mainfrom
jonathanpeppers-mt-android-tooling

Conversation

@jonathanpeppers

@jonathanpeppers jonathanpeppers commented Oct 29, 2026 •

Copy link
Copy Markdown
Member

Stacked on #13322. Reuse its MonoAndroidHelper.RunProcess(TaskEnvironment, …) overload for the aapt2 version probe.

ResolveAndroidTooling still requires process-wide working-directory and environment handling under -mt. Use MultithreadedAndroidTask and declare [MSBuildMultiThreadableTask] so it can run in-process with other tasks.

Resolve SDK and tool paths through TaskEnvironment, use project-specific PATHEXT, and start aapt2 with the project environment. Keep the existing tool search order and diagnostics. Extend the existing cache test to cover distinct project directories, relative paths, child-process environment and working directory, and cache reuse.

Validated on Windows with a locally built .NET 11 RC2 SDK after rebasing:

  • bin\Debug\dotnet\dotnet.exe build Microsoft.Android.slnx -m:4 -nr:false -v:minimal: passed, including the task-authoring analyzer; 0 errors.
  • dotnet-local.cmd test bin\TestDebug\net10.0\Xamarin.Android.Build.Tests.dll --filter "(FullyQualifiedName~ResolveSdksTaskTests|FullyQualifiedName~ValidateJavaVersionTests|Name~MigratedTasksHaveDirectAttribute)&Name!~ToolingTargetRejectsOldJavaForModernAndroidApi": passed, 62 tests. The two excluded parent integration cases failed before reaching the tasks with NETSDK1147 (missing Android workload). Local workload setup was attempted; it is blocked by the .NET 11 RC2 SDK lacking the microsoft-net-runtime-mono-tooling-net11 workload referenced by the current manifest.
  • bin\Debug\dotnet\dotnet.exe msbuild <validation>\parallel-tooling.proj -m -nr:false -v:minimal: passed. The local harness runs two actual task instances and checks API level, build-tools path, and aapt2 version.
  • The same harness with -m -mt -nr:false -warnaserror:MSB4286,MSB4287,MSB4288: passed. binlogtool found no TaskHost fallback or MT safety diagnostics.

Before rebasing, the 7 MultithreadedAndroidTaskTests passed, including file-lock diagnostics. The expanded cache test was also confirmed to fail separately for a wrong child working directory and a missing project environment variable.

Temporary .NET 11 build settings and the local test-only change that prevents teardown from killing shared adb processes were restored before commit. No device tests were needed for this tooling-only change.

Copilot AI balanced review requested due to automatic review settings October 29, 2026 16:01

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟡 Changes recommended

The expanded test would still pass with process-wide environment and working-directory values, leaving project-specific child-process execution without regression coverage.

1 open issue
What changed in this PR

Enables ResolveAndroidTooling to run in-process during multithreaded MSBuild execution by using project-specific paths and environment settings instead of process-wide state.

Changes:

  • Migrates the task to MultithreadedAndroidTask with a direct execution attribute.
  • Uses TaskEnvironment for tool discovery and aapt2 launches, and runtime platform detection for bundled tool paths.
  • Extends cache tests to cover separate project directories, relative paths, and project-specific PATHEXT.
File Description
src/​Xamarin.Android.Build.Tasks/​Utilities/​MonoAndroidHelper.Nullable.cs Adds executable lookup using the project environment.
src/​Xamarin.Android.Build.Tasks/​Utilities/​MonoAndroidHelper.cs Uses runtime platform detection for OS-specific tool paths.
src/​Xamarin.Android.Build.Tasks/​Tests/​Xamarin.Android.Build.Tests/​Tasks/​ResolveSdksTaskTests.cs Expands project-isolation and cache-reuse coverage.
src/​Xamarin.Android.Build.Tasks/​Tasks/​ResolveAndroidTooling.cs Enables multithreaded execution and project-scoped path and process handling.

Review effort: Balanced

@jonathanpeppers
jonathanpeppers force-pushed the jonathanpeppers-mt-android-tooling branch from 4edfa33 to cf6b539 Compare October 29, 2026 22:01
@jonathanpeppers
jonathanpeppers changed the base branch from main to jonathanpeppers-mt-java-version-validation October 29, 2026 22:02
Base automatically changed from jonathanpeppers-mt-java-version-validation to main October 30, 2026 14:51
jonathanpeppers and others added 3 commits October 30, 2026 09:51
Resolve tooling paths and PATHEXT against the project environment, and run aapt2 with that environment. Keep version caches isolated by absolute paths and extend the existing cache test to cover distinct projects and relative paths.

Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
Use a faux aapt2 whose version combines a project environment variable
with a file read from the project directory.  Keep the existing cache
reuse and project isolation checks.

Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
Use the TaskEnvironment overload supplied by the ValidateJavaVersion
change instead of keeping a second process-launch implementation.

Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
@jonathanpeppers
jonathanpeppers force-pushed the jonathanpeppers-mt-android-tooling branch from cf6b539 to ec61c11 Compare October 30, 2026 14:51
@jonathanpeppers

Copy link
Copy Markdown
Member Author

@dalexsoto review

@jonathanpeppers
jonathanpeppers enabled stacked auto-merge (squash) October 30, 2026 18:46
@jonathanpeppers
jonathanpeppers merged commit f018e4d into main Oct 30, 2026
41 checks passed
@jonathanpeppers
jonathanpeppers deleted the jonathanpeppers-mt-android-tooling branch October 30, 2026 19:34
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants