Skip to content

[Microsoft.Android.Build.Tasks] Move InstallAndroidDependencies into MABT - #13520

Open
simonrozsival wants to merge 3 commits into
mainfrom
simonrozsival-license-installer-process-pumps
Open

simonrozsival wants to merge 3 commits into
mainfrom
simonrozsival-license-installer-process-pumps

Conversation

@simonrozsival

@simonrozsival simonrozsival commented Nov 12, 2026 •

Copy link
Copy Markdown
Member

Context: #12981
Context: https://devblogs.microsoft.com/dotnet/process-api-improvements-in-dotnet-11/
Context: https://learn.microsoft.com/visualstudio/msbuild/update-task-multithreaded

After #13513, InstallAndroidDependencies uses Google's Android CLI but still lives in the netstandard2.0 installer task assembly. Move it, JavaDependencyInstaller, and OpenJdkSignatureVerifier into the net12.0 Microsoft.Android.Build.Tasks.dll, enabling modern .NET APIs and multithreaded MSBuild. Remove the old installer project while retaining its localized resources and shipped props/targets.

  • Replace /usr/bin/tar with GZipStream and TarFile.ExtractToDirectoryAsync(), and chmod with File.SetUnixFileMode().
  • Use Process.ReadAllLinesAsync() to drain stdout and stderr together, retaining only the last 4,096 characters for XA5308. RunAndCaptureTextAsync() would retain all progress output. Cancellation kills the CLI's process tree and waits for the CLI to exit.
  • Derive from MultithreadedAndroidTask, declare [MSBuildMultiThreadableTask], and use TaskEnvironment for project paths, environment variables, and child process configuration. Pair Yield()/Reacquire() around the async workflow. Use the thread-safe TaskLoggingHelper directly instead of recreating AsyncTask's legacy log-forwarding queues; full-framework MSBuild hosts this .NET-only task out of process.
  • Keep the paired Full/Core Runtime="NET" registration, using TaskHostFactory only for Full MSBuild. Retain justified analyzer suppressions for Process.Start() with task-supplied start info, scratch-file creation, and machine-wide Program Files discovery.

InstallAndroidDependenciesTests moves the existing fake-CLI and invalid-JDK tests out of Xamarin.Android.Build.Tests; OpenJdkSignatureTests also moves to the net12.0 test project. Extend the moved coverage with cancellation after child readiness, nonzero exits and output tails, and offline tar.gz extraction checking executable permissions, relative symlinks, replacement, staging cleanup, and trailing directory separators. The four unresolved review threads were two duplicated suggestions for this coverage.

The follow-up removes 91 lines from the task compared with the initial migration; the task is now only 15 lines longer than before the move.

Validation for 1ef0ba8226 on macOS arm64:

  • dotnet build build-tools/xa-prep-tasks/xa-prep-tasks.csproj --nologo -v:q: passed, 0 warnings/errors (required build prerequisite in this fresh worktree).
  • dotnet build src/Microsoft.Android.Build.Tasks/Tests/Microsoft.Android.Build.Tasks.Tests/Microsoft.Android.Build.Tasks.Tests.csproj --nologo -v:q: passed, 0 warnings/errors.
  • dotnet test src/Microsoft.Android.Build.Tasks/Tests/Microsoft.Android.Build.Tasks.Tests/Microsoft.Android.Build.Tasks.Tests.csproj --no-build --filter 'FullyQualifiedName~InstallAndroidDependenciesTests|FullyQualifiedName~OpenJdkSignatureTests' --nologo -v:minimal: passed 62/62.
  • A temporary MSBuild project invoking the production task with /usr/bin/true as the CLI passed ordinary execution and strict -m -mt -nr:false -warnaserror:MSB4286,MSB4287,MSB4288 execution. Both emitted the expected warning that the stub did not install the requested package; no real SDK packages were downloaded.

Full SDK/device tests and Windows/Linux execution were not rerun for this follow-up. Earlier full-SDK and integration results applied to an earlier revision, not this head.

Copilot AI balanced review requested due to automatic review settings November 12, 2026 12:04

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

A trailing separator in a valid JdkPath places staging inside the JDK directory, causing RemoveJdk() to delete both the existing JDK and newly extracted files before the move.

1 open issue
1 file not reviewed
  • src/Xamarin.Installer.AndroidSDK/Properties/Resources.Designer.cs: Generated file
What changed in this PR

This PR improves process and resource ownership in the legacy Android SDK installer, addressing the process-lifetime audit tracked in #12981.

Changes:

  • Replaces license busy-polling with prompt-driven answers, cancellable input, concurrent output capture, and bounded cleanup.
  • Moves Java extraction to native process capture with structured arguments, a deadline, diagnostics, and staging cleanup.
  • Removes unused command helpers and adds standalone regression coverage.
File Description
tests/​Xamarin.Android.Tools.AndroidSdk-Tests/​AndroidSdkInstallerTests.cs Adds license lifecycle and Java extraction regression tests.
src/​Xamarin.Installer.Common/​Xamarin.Installer.Common/​CommonUtilities.cs Removes unused RunCommand overloads.
src/​Xamarin.Installer.AndroidSDK/​Xamarin.Installer.AndroidSDK/​JavaDependencyInstaller.cs Adds bounded extraction, layout checks, and staging cleanup.
src/​Xamarin.Installer.AndroidSDK/​Xamarin.Installer.AndroidSDK/​Common/​AndroidLicensesStorage.cs Owns license process input, output, cancellation, and log lifetimes.
src/​Xamarin.Installer.AndroidSDK/​Properties/​Resources.resx Adds localized timeout and extraction error messages.
src/​Xamarin.Installer.AndroidSDK/​Properties/​Resources.Designer.cs Exposes the new resource strings.
.github/​skills/​tests/​references/​test-catalog.md Documents the focused installer test command.

Review effort: Balanced

@simonrozsival

Copy link
Copy Markdown
Member Author

/review

@github-actions

github-actions Bot commented Nov 13, 2026 •

Copy link
Copy Markdown
Contributor

✅ Android PR Reviewer completed successfully!

Generated by Android PR Reviewer for #13520

@github-actions github-actions Bot 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.

⚠️ Needs Changes

Findings: 1 ❌ error, 0 ⚠️ warnings, 0 💡 suggestions. The existing unresolved trailing-separator finding remains applicable: staging can land inside JdkPath, and committing an otherwise valid archive deletes both the installed JDK and its replacement. The inline comment describes the normalization and regression coverage needed.

The license changes improve ownership substantially: prompt-driven selective answers replace busy polling, stdout/stderr are consumed concurrently, sink access is synchronized, and process-exit/output-EOF handling has explicit deadlines. The new fixtures cover cancellation, blocked stdin, late diagnostics, sink failures, and repeated native-capture reader disposal. I reviewed all seven changed files, the affected callers, and the project target frameworks against the stacked PR diff.

CI: All 40 returned GitHub checks are completed/successful, including the aggregate dotnet-android check for build 1677892. Independent Azure build/timeline verification was blocked by Azure CLI initialization/authentication errors, so that verification remains incomplete.

Local validation: dotnet test tests/Xamarin.Android.Tools.AndroidSdk-Tests/Xamarin.Android.Tools.AndroidSdk-Tests.csproj -v minimal --filter FullyQualifiedName~AndroidSdkInstallerTests could not start: .NET CLI initialization failed creating the NuGet-Migrations mutex because its runtime directory was unavailable. No tests executed locally; the installed SDK also reports 10.0.403 while these projects target net11.0.

Generated by Android PR Reviewer for #13520 · copilot · gpt61 · 32.3 AIC · ⌖ 4.72 AIC · ⊞ 20.2K
Comment /review to run again

@simonrozsival
simonrozsival removed this pull request from stack #13517 November 13, 2026 09:57
@simonrozsival
simonrozsival changed the base branch from simonrozsival-process-resource-cleanup to simonrozsival-aapt2-daemon-lifetime November 13, 2026 09:59
@simonrozsival
simonrozsival marked this pull request as draft November 13, 2026 10:45
@simonrozsival
simonrozsival force-pushed the simonrozsival-license-installer-process-pumps branch from b4ba1ba to 7d5da70 Compare November 13, 2026 10:45
@simonrozsival simonrozsival changed the title [Xamarin.Installer.AndroidSDK] Own license and installer lifetimes [Microsoft.Android.Build.Tasks] Move InstallAndroidDependencies into MABT Nov 13, 2026
@simonrozsival
simonrozsival force-pushed the simonrozsival-license-installer-process-pumps branch from 7d5da70 to c545363 Compare November 13, 2026 10:51
@simonrozsival
simonrozsival marked this pull request as ready for review November 13, 2026 11:09
@simonrozsival
simonrozsival removed this pull request from stack #13545 November 13, 2026 11:21
@simonrozsival

Copy link
Copy Markdown
Member Author

/review

@github-actions

github-actions Bot commented Nov 13, 2026 •

Copy link
Copy Markdown
Contributor

✅ Android PR Reviewer completed successfully!

Generated by Android PR Reviewer for #13520

@github-actions github-actions Bot 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.

⚠️ Validation incomplete — no blocking code findings

Reviewed all 15 changed files, including the full moved implementations, project/packaging wiring, task registrations, and test coverage. Findings: 0 errors, 0 warnings, 2 non-blocking suggestions, posted inline for deterministic extraction and process-lifecycle coverage.

The migration keeps signature/hash verification intact, resolves project-relative installation paths through TaskEnvironment, uses structured process arguments, and preserves calling-thread logging. Linking the installer resources into MABT and retaining the shipped props/targets is consistent with the surrounding migration pattern.

CI: All 40 GitHub checks for head 07c58d96 report success, including the aggregate dotnet-android check and Windows/Linux/macOS lanes. I could not independently verify Azure build 1679429: the Azure CLI required authentication and the direct public REST read was denied. Consequently, this is not an unconditional CI-green/LGTM verdict.

Local validation: Attempted dotnet test src/Microsoft.Android.Build.Tasks/Tests/Microsoft.Android.Build.Tasks.Tests/Microsoft.Android.Build.Tasks.Tests.csproj --filter 'FullyQualifiedName~InstallAndroidDependenciesTests|FullyQualifiedName~OpenJdkSignatureTests' -v minimal; the .NET CLI failed during NuGet first-use initialization before building or executing tests. No local test pass is claimed. The worktree was left unchanged.

Generated by Android PR Reviewer for #13520 · copilot · gpt61 · 48.3 AIC · ⌖ 7.51 AIC · ⊞ 19.5K
Comment /review to run again

@github-actions github-actions Bot 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.

⚠️ Validation incomplete — no blocking code findings

Reviewed all 15 changed files, including the full moved implementations, project/packaging wiring, task registrations, and test coverage. Findings: 0 errors, 0 warnings, 2 non-blocking suggestions, posted inline for deterministic extraction and process-lifecycle coverage.

The migration keeps signature/hash verification intact, resolves project-relative installation paths through TaskEnvironment, uses structured process arguments, and preserves calling-thread logging. Linking the installer resources into MABT and retaining the shipped props/targets is consistent with the surrounding migration pattern.

CI: All 40 GitHub checks for head 07c58d96 report success, including the aggregate dotnet-android check and Windows/Linux/macOS lanes. I could not independently verify Azure build 1679429: the Azure CLI required authentication and the direct public REST read was denied. Consequently, this is not an unconditional CI-green/LGTM verdict.

Local validation: Attempted dotnet test src/Microsoft.Android.Build.Tasks/Tests/Microsoft.Android.Build.Tasks.Tests/Microsoft.Android.Build.Tasks.Tests.csproj --filter 'FullyQualifiedName~InstallAndroidDependenciesTests|FullyQualifiedName~OpenJdkSignatureTests' -v minimal; the .NET CLI failed during NuGet first-use initialization before building or executing tests. No local test pass is claimed. The worktree was left unchanged.

Generated by Android PR Reviewer for #13520 · copilot · gpt61 · 48.3 AIC · ⌖ 7.51 AIC · ⊞ 19.5K
Comment /review to run again

@simonrozsival simonrozsival added the ready-to-review This PR is ready to review/merge, I think any CI failures are just flaky (ignorable). label Nov 13, 2026
Base automatically changed from simonrozsival-aapt2-daemon-lifetime to main November 17, 2026 20:55
simonrozsival and others added 2 commits November 21, 2026 09:27
…MABT

Context: #12981
Context: https://devblogs.microsoft.com/dotnet/process-api-improvements-in-dotnet-11/
Context: https://learn.microsoft.com/visualstudio/msbuild/update-task-multithreaded

After #13513, `InstallAndroidDependencies` installs SDK packages with Google's Android CLI, but it still lived in the netstandard2.0 `Xamarin.Installer.Build.Tasks.dll`. There it had to start the Android CLI, `/usr/bin/tar`, and `chmod` through `ProcessUtils`, and it could not run in multithreaded MSBuild (`-mt`).

Move the task, `JavaDependencyInstaller`, and `OpenJdkSignatureVerifier` into `Microsoft.Android.Build.Tasks.dll`, which runs on .NET:

  * Register the task with the paired Full/Core `Runtime="NET"` `<UsingTask/>`. MABT links the existing localized messages and deploys `Xamarin.Installer.Common.props` and `.targets` to `tools`, so `Xamarin.Android.Common.targets` and the localization files are unchanged. Remove `Xamarin.Installer.Build.Tasks.csproj`.
  * Run the Android CLI with `Process.ReadAllLinesAsync()` and `WaitForExitAsync()`, keeping only the tail of its output as before, and kill its process tree when the task fails or is canceled. Extract JDK `.tar.gz` archives with `TarFile`, and mark the downloaded Android CLI executable with `File.SetUnixFileMode()`.
  * Derive from `MultithreadedAndroidTask` with `[MSBuildMultiThreadableTask]` and `ICancelableTask`. `RunTask()` runs the existing async workflow on the thread pool and forwards log messages to the thread that called `Execute()`, as `AsyncTask` did. Environment variables, the child process start info, and all paths come from `TaskEnvironment`; resolved paths are passed around as `AbsolutePath`. The default SDK and JDK locations come from the task's `LOCALAPPDATA` or `HOME`.

Three analyzer findings are suppressed with justifications: `Process.Start()` (its `ProcessStartInfo` comes from `TaskEnvironment.GetProcessStartInfo()`), `Path.GetTempFileName()` (no `TaskEnvironment` alternative yet), and `Environment.GetFolderPath(ProgramFiles)` (a machine location).

`OpenJdkSignatureTests` and the unit tests that create the task move to the net12.0 `Microsoft.Android.Build.Tasks.Tests`. The fake Android CLI test now also checks that a relative `AndroidSdkPath` resolves against the project directory and that messages are logged on the `Execute()` thread.

Co-authored-by: Copilot App <[email protected]>
@simonrozsival
simonrozsival force-pushed the simonrozsival-license-installer-process-pumps branch from 07c58d9 to 209dbea Compare November 21, 2026 13:16
@simonrozsival simonrozsival removed the ready-to-review This PR is ready to review/merge, I think any CI failures are just flaky (ignorable). label Nov 23, 2026
Remove the custom logging queue: TaskLoggingHelper supports logging from any thread, and this .NET-only task runs out of process when hosted by full-framework MSBuild. Pair Yield/Reacquire around the async workflow.

Keep Process.ReadAllLinesAsync to drain both streams while retaining only 4096 characters, instead of capturing unbounded CLI progress. Replace the locked TextWriter with a local StringBuilder and wait for the CLI after cancellation kills it.

Keep the moved installer unit tests and add offline coverage for cancellation after startup, XA5308 output tails, executable permissions, relative symlinks, replacement, staging cleanup, and trailing directory separators.

Validation on macOS: standalone task/test build passed without warnings; 62 focused installer/signature tests passed; ordinary and strict -m -mt -nr:false -warnaserror:MSB4286,MSB4287,MSB4288 task execution passed using /usr/bin/true as the CLI (expected missing-package warnings). Windows and Linux were not run.

Co-authored-by: Copilot App <[email protected]>
@simonrozsival

Copy link
Copy Markdown
Member Author

/review

@github-actions

github-actions Bot commented Nov 23, 2026 •

Copy link
Copy Markdown
Contributor

✅ Android PR Reviewer completed successfully!

Generated by Android PR Reviewer for #13520

@github-actions github-actions Bot 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.

✅ LGTM — code review

0 errors · 0 warnings · 1 non-blocking suggestion, posted inline.

Reviewed all 15 changed files in full, the task's base-class behavior, callers/registrations, resource wiring, and packaging changes at 1ef0ba822696a83046332e5065d174e071b7779e. No blocking correctness issues found. The offline extraction tests now cover executable permissions, relative symlinks, replacement, staging cleanup, and trailing separators; the CLI tests cover cancellation after readiness and failure-output retention. These address the earlier review suggestions without repeating them here.

CI: All 38 GitHub checks report success, including the aggregate dotnet-android check for Azure build 1694617. Direct Azure build/timeline verification was blocked because az devops invoke requires authentication in this environment, so that result was not independently confirmed through Azure. Local tests were not rerun; the installed SDKs stop at .NET 11, while the moved test project targets .NET 12.

Generated by Android PR Reviewer for #13520 · copilot · gpt61 · 45.6 AIC · ⌖ 4.44 AIC · ⊞ 21K
Comment /review to run again

var task = new InstallAndroidDependencies {
BuildEngine = new MockBuildEngine (TestContext.Out, errors, [], []),
// Relative paths resolve against the project directory, not the process working directory.
TaskEnvironment = TaskEnvironment.CreateWithProjectDirectoryAndEnvironment (root, new Dictionary<string, string> ()),

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.

🤖 💡 Testing — Consider supplying a unique test-only environment variable here and having the fake CLI write its value to a file for assertion. The relative paths already exercise project-relative path resolution, but the empty environment means this test would still pass if process creation accidentally inherited the node's environment instead of the task's. An explicit value would protect the environment-isolation part of this multithreaded migration without changing the parent process environment.

{Rule: Test project-specific environment isolation}

This branch has not been deployed

No deployments
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.

2 participants