Repository navigation
[Xamarin.Android.Build.Tasks] Reuse tooling in nested builds - #13202
Conversation
There was a problem hiding this comment.
🟡 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
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
130979b to
43bab4a
Compare
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
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
|
@dalexsoto review |
dalexsoto
left a comment
There was a problem hiding this comment.
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.
|
🤖 @dalexsoto, regarding your review:
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 string propertyValue = EscapingUtilities.Escape(
propertyNameValueString.AsSpan(indexOfEqualsSign + 1).Trim().ToString());The 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
left a comment
There was a problem hiding this comment.
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.
|
/review |
|
✅ Android PR Reviewer completed successfully!
|
There was a problem hiding this comment.
✅ 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)] |
There was a problem hiding this comment.
🤖 💡 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}


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,ResolveAndroidToolingandValidateJavaVersionagain, even when the outer build has already resolved and validated the same inputs.SkipCompilerExecutiondoes 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
Propertiesparameter, notAdditionalPropertiesitem metadata, which can unescape and split semicolon-containing paths. Keep only the per-RID assignment in item metadata. Both_ResolveAssembliesand 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, MSBuild18.13.0-1.26509.101, and Android workload37.99.0, built on prerequisited4adb657332144dcfd1f33170b7e77837a56a650/ main12c2d573cea4794d3e6920d26df9764bb21000de. Build shells disabled MSBuild server/node reuse and telemetry, and setTEST_ANDROID_JDK_PATH=C:\Program Files\Android\openjdk\jdk-21.0.8. The SDK build used VS 18 InsidersVsDevCmd.batin the same CMD process.Passed: 0 errors, 92 existing warnings. Inspected the binlog with
binlogtool.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=1lint path and assert exact input/output forwarding, active reuse, and no separatetagproperty in every inner build. Both cases failed before the transport fix and pass after it. The fallback matrix also changesLatestSupportedJavaVersion=99.0only in the inner build and verifies a second Java validation call. The initial 15-case suite also passed before these review additions.git diff --checkand 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.mdworkflow documentation, and in particular should include:No issue is closed by this PR; #13201 is its prerequisite.