Skip to content

[Xamarin.Android.Build.Tasks] Reuse tooling in nested builds - #13202

Merged
jonathanpeppers merged 4 commits into
mainfrom
jonathanpeppers-nested-sdk-resolution
Oct 22, 2026
Merged

jonathanpeppers merged 4 commits into
mainfrom
jonathanpeppers-nested-sdk-resolution

Conversation

@jonathanpeppers

@jonathanpeppers jonathanpeppers commented Oct 19, 2026 •

Copy link
Copy Markdown
Member

Depends on #13201. This is the second PR in the stack: main -> API-version state removal -> nested-build reuse. Its diff contains seven target/test files; the API-state changes belong to the lower PR.

RID-specific nested builds create new MSBuild project instances. Their reference-resolution dependencies run ResolveSdks, ResolveAndroidTooling and ValidateJavaVersion again, even when the outer build has already resolved and validated the same inputs. SkipCompilerExecution does not skip those dependencies.

Pass the resolved outputs through private properties at the assembly-resolution and trimmable-typemap MSBuild call sites. Reuse them only when the original project, configuration, target framework, API metadata, SDK inputs, tooling overrides and Java validation settings match. Compare escaped input values with ordinal equality, including paths with apostrophes, semicolons and equals signs. Keep the outer build's resolved NDK and escape its direct nested-property assignment.

Pass the common escaped values through the MSBuild task's Properties parameter, not AdditionalProperties item metadata, which can unescape and split semicolon-containing paths. Keep only the per-RID assignment in item metadata. Both _ResolveAssemblies and the NativeAOT R8 relink receive the common properties.

Skip only the three resolution/validation tasks, not their target bodies. RID-to-ABI conversion and the other per-inner-build work still run. Standalone resolution, changed inputs, design-time builds, missing-tooling mode, explicit NDK-resolution skipping and different referenced projects retain normal resolution/validation. The compression and NativeAOT R8 nested builds also receive the resolved values. No new public build property or initializer task is added. This PR does not claim a measured build-time improvement.

Local validation

Used this worktree's Debug SDK 12.0.100-alpha.1.26509.101, MSBuild 18.13.0-1.26509.101, and Android workload 37.99.0, built on prerequisite d4adb657332144dcfd1f33170b7e77837a56a650 / main 12c2d573cea4794d3e6920d26df9764bb21000de. Build shells disabled MSBuild server/node reuse and telemetry, and set TEST_ANDROID_JDK_PATH=C:\Program Files\Android\openjdk\jdk-21.0.8. The SDK build used VS 18 Insiders VsDevCmd.bat in the same CMD process.

.\dotnet-local.cmd build Microsoft.Android.slnx -t:BuildDotNet -nr:false -v:minimal -bl:C:\Users\jopepper\.copilot\session-state\d1403059-4a29-4416-81aa-6d66d0506b0d\files\review-transport-sdk-build.binlog

Passed: 0 errors, 92 existing warnings. Inspected the binlog with binlogtool.

.\dotnet-local.cmd test bin\TestDebug\net10.0\Xamarin.Android.Build.Tests.dll --filter "FullyQualifiedName~ResolvedToolingInputsEscapeApostrophes|FullyQualifiedName~NestedBuildReusesResolvedAndroidTooling|FullyQualifiedName~NestedBuildToolingFallsBackForChangedInputs|FullyQualifiedName~NestedBuildPreservesEscapedNdkPath|FullyQualifiedName~NestedToolingSnapshotDoesNotSkipProjectReferenceResolution|FullyQualifiedName~PublishReusesResolvedToolingInSpecializedInnerBuilds" --logger "trx;LogFileName=review-transport-after.trx" --results-directory "C:\Users\jopepper\.copilot\session-state\d1403059-4a29-4416-81aa-6d66d0506b0d\files\review-test-results"

Passed: 16 tests, 0 failures, 0 skips. This covers cold and incremental multi-RID builds in ordinary and multithreaded MSBuild, standalone Java validation, changed-input fallback, escaped/pinned NDK paths, project-reference isolation, CoreCLR compression/typemap publish, and NativeAOT R8 publish. The successful multi-RID builds assert one invocation of each resolution/validation task while both RID-specific target bodies still execute.

The CoreCLR and NativeAOT publish cases use an O'Brien;tag=1 lint path and assert exact input/output forwarding, active reuse, and no separate tag property in every inner build. Both cases failed before the transport fix and pass after it. The fallback matrix also changes LatestSupportedJavaVersion=99.0 only in the inner build and verifies a second Java validation call. The initial 15-case suite also passed before these review additions.

git diff --check and XML parsing of the changed targets passed. The lower PR records its separate API-state/cache/manifest/task validation.


Pull Request
title and
description
should follow the
commit-messages.md workflow documentation, and in particular should include:

  • Useful description of why the change is necessary.
  • Links to issues fixed
  • Unit tests

No issue is closed by this PR; #13201 is its prerequisite.

Copilot AI balanced review requested due to automatic review settings October 19, 2026 18:03

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

Metadata forwarding can corrupt escaped SDK and tooling paths before nested builds reuse them.

2 open issues
What changed in this PR

Builds on #13201 to reuse resolved Android tooling in nested builds while preserving per-RID work.

Changes:

  • Captures SDK/tooling inputs and reuses outputs when inputs match.
  • Forwards resolved values to assembly-resolution and typemap builds.
  • Adds reuse, fallback, escaping, and project-isolation tests.
File Description
src/​Xamarin.Android.Build.Tasks/​Xamarin.Android.Tooling.targets Captures and restores SDK resolution state.
src/​Xamarin.Android.Build.Tasks/​Tests/​Xamarin.Android.Build.Tests/​XASdkTests.cs Adds nested-build integration coverage.
src/​Xamarin.Android.Build.Tasks/​Tests/​Xamarin.Android.Build.Tests/​Tasks/​ResolveSdksTaskTests.cs Tests escaped, ordinal input comparisons.
src/​Xamarin.Android.Build.Tasks/​Microsoft.Android.Sdk/​targets/​Microsoft.Android.Sdk.TypeMap.Trimmable.targets Forwards tooling state to typemap builds.
src/​Xamarin.Android.Build.Tasks/​Microsoft.Android.Sdk/​targets/​Microsoft.Android.Sdk.Tooling.targets Conditionally reuses tooling and Java validation outputs.
src/​Xamarin.Android.Build.Tasks/​Microsoft.Android.Sdk/​targets/​Microsoft.Android.Sdk.AssemblyResolution.targets Forwards tooling state to assembly-resolution builds.

Review effort: Balanced

Base automatically changed from jonathanpeppers-api-version-state-isolation to main October 20, 2026 06:55
Forward resolved SDK, Android tooling and Java outputs to same-context RID-specific builds. Match the original project inputs before reusing outputs, and keep normal resolution and validation for changed inputs, project references and design-time builds. Preserve the resolved NDK and escape it when passing nested properties.

Cover ordinary and multithreaded multi-RID builds, input changes, escaped paths, standalone validation, project references, CoreCLR compression/typemap and NativeAOT R8 publish.

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

Copilot-Session: d1403059-4a29-4416-81aa-6d66d0506b0d
Pass common resolved properties through the MSBuild task Properties parameter instead of AdditionalProperties item metadata, which can unescape and split semicolon-containing values. Retain per-RID metadata and supply the common properties to both assembly resolution and NativeAOT R8 relinking.

Reproduce the regression through real CoreCLR and NativeAOT publish builds with an escaped lint path. Add an inner-only Java limit change to the snapshot fallback matrix.

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

Copilot-Session: d1403059-4a29-4416-81aa-6d66d0506b0d
@simonrozsival
simonrozsival force-pushed the jonathanpeppers-nested-sdk-resolution branch from 130979b to 43bab4a Compare October 20, 2026 06:55
The input-escaping test creates a ProjectInstance that imports environment properties. CI sets JavaSdkDirectory, but the synthetic outer snapshot left it empty, causing two SDK cases to report an extra changed input on both Windows and macOS.

Set explicit defaults for every declared input and its outer alias, while preserving the tested values and reserved MSBuildProjectFullPath. This makes the test independent of machine SDK/tooling settings without changing product resolution.

Validation: reproduced both failing SDK cases with the CI JavaSdkDirectory. After the fix, all four cases pass with that value and with multiple SDK/tooling environment values; the combined SDK/Java/nested-build suite passes 68/68.

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

Copilot-Session: d1403059-4a29-4416-81aa-6d66d0506b0d
@jonathanpeppers jonathanpeppers added the ready-to-review This PR is ready to review/merge, I think any CI failures are just flaky (ignorable). label Oct 20, 2026
Put each tooling and SDK input on its own line so the two new lists are easier to read and edit. Preserve input identities, ordering and aliases.

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

Copilot-Session: d1403059-4a29-4416-81aa-6d66d0506b0d
@jonathanpeppers

Copy link
Copy Markdown
Member Author

@dalexsoto review

@dalexsoto dalexsoto left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

The earlier escaped-common-property transport and inner-only Java-validation fixes are verified; those findings are not being reopened.

Preserve auto-discovered SDK-directory whitespace in the snapshot (Xamarin.Android.Tooling.targets:127). With AndroidSdkDirectory initially unset, a valid Unix SDK discovered at /opt/android-sdk<space> (trailing U+0020) is captured as _AndroidOuterSdkDirectory, then the MSBuild task Properties parser trims it to /opt/android-sdk. The outer discovered public value is local, not an inherited global, and none of the four explicit nested-call property lists forwards it. The inner original input consequently remains empty and matches the saved empty input; the nonempty trimmed snapshot passes the reuse guard, which has no existence check. ResolveSdks is skipped and a different or nonexistent SDK root is restored. Adding a directory separator later cannot recover the removed character.

Please reject snapshot reuse for resolved values that cannot round-trip unchanged, or serialize/restore them without trimming. A regression should use an auto-discovered trailing-space root with the public input unset: an explicitly supplied public/global path can correctly fall back and would not exercise this defect.

This is the sole consolidated source blocker. No build, test or MSBuild evaluation was executed. The existing ResolveSdkTiming assertion (3.407697 seconds against a 2-second limit) remains unmatched and is not the basis for this finding or classified as flaky/infrastructure.

@jonathanpeppers

jonathanpeppers commented Oct 22, 2026 •

Copy link
Copy Markdown
Member Author

🤖 @dalexsoto, regarding your review:

Please reject snapshot reuse for resolved values that cannot round-trip unchanged, or serialize/restore them without trimming.

I reproduced the trimming, so the edge case is real: an auto-discovered Unix SDK directory whose name actually ends in a space can reach the inner build with a different path.

The trimming happens in MSBuild's PropertyParser.GetTableWithEscaping(), which parses the task's Properties parameter:

string propertyValue = EscapingUtilities.Escape(
    propertyNameValueString.AsSpan(indexOfEqualsSign + 1).Trim().ToString());

The .Trim() removes whitespace before MSBuild re-escapes the value. The source comment says this is intentional to allow readable multiline property lists; our [MSBuild]::Escape(...) does not encode spaces.

However, none of the normal values we forward is expected to contain meaningful trailing whitespace. They are SDK/JDK/NDK/tool paths, version/API values, and booleans. The whitespace used to format the property lists is intentionally trimmed by MSBuild.

I'm concerned that adding special transport or fallback rules for this unusual directory-name case would complicate the code without a demonstrated user need. I'd prefer to leave that edge case outside this PR rather than add whitespace-preserving serialization. This is a scope decision, not a claim that the current code handles such paths correctly.

@dalexsoto dalexsoto left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

I accept the maintainer's scope decision to leave meaningful trailing-whitespace directory names outside this PR; no additional serialization or fallback is requested for that accepted tradeoff.

The retained seven-file review and bounded current-main reconciliation preserve the escaped common-property transport, Java-setting invalidation, per-RID work and source-to-pack contracts. No independent blocker remains within the accepted scope.

Static source review of b829635839c480df9d3ce4aa48649b0fbe35be92 against main 8137fd0424af1263256a965ecd5543bc34b1e911, with a uniquely applied in-memory source composition. This approval is not an installed-SDK, native-product or shipping-execution certificate.

@jonathanpeppers

Copy link
Copy Markdown
Member Author

/review

@github-actions

github-actions Bot commented Oct 22, 2026 •

Copy link
Copy Markdown
Contributor

✅ Android PR Reviewer completed successfully!

Generated by Android PR Reviewer for #13202

@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 — no new correctness findings. Reviewed the seven-file diff and full changed files, resolution-task implementations, nested-build consumers, and project configuration. 0 errors · 0 warnings · 1 optional testing suggestion posted inline.

The snapshot gates compare the original inputs before restoring outputs, preserve normal fallback behavior, and leave RID-to-ABI conversion active. The earlier semicolon-forwarding and inner-only Java-invalidation findings are addressed, with regression coverage for the specialized CoreCLR and NativeAOT paths. Prerequisite #13201 is merged.

CI: All 41 GitHub-reported checks succeeded, including the aggregate dotnet-android check for Azure build 1642298. Direct Azure build/timeline verification was unavailable because az devops invoke required authentication. No local tests were run during this review; this checkout has no built SDK/test output.

Generated by Android PR Reviewer for #13202 · copilot · gpt61 · 37.4 AIC · ⌖ 8.12 AIC · ⊞ 19.1K
Comment /review to run again

[TestCase ("_SkipNdkResolution=true", 2)]
[TestCase ("_AndroidAllowMissingSdkTooling=true", 2)]
[TestCase ("Configuration=Release", 2)]
[TestCase ("AndroidSdkBuildToolsVersion=0.0.0", 2)]

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 adding an inner-only Aapt2ToolPath override pointing to a nonexistent directory and asserting XA0112. The current matrix verifies task re-execution for changed inputs, and the direct task test verifies rejection of a missing aapt2 override, but neither combines snapshot invalidation with that rejection. A negative nested-build case would protect against accidentally restoring the outer aapt2 path and masking an invalid inner override.

{Rule: Test edge cases and error paths}

@jonathanpeppers
jonathanpeppers merged commit a7b3884 into main Oct 22, 2026
41 checks passed
@jonathanpeppers
jonathanpeppers deleted the jonathanpeppers-nested-sdk-resolution branch October 22, 2026 20:46
@github-actions github-actions Bot locked and limited conversation to collaborators Nov 22, 2026
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

ready-to-review This PR is ready to review/merge, I think any CI failures are just flaky (ignorable).

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants