Repository navigation
[Xamarin.Android.Build.Tasks] Move FindLayoutsToBind to Microsoft.Android.Build.Tasks - #13473
Conversation
…roid.Build.Tasks Context: #13460 `FindLayoutsToBind` matched resource paths with a `Regex` built at type initialization using `RegexOptions.Compiled`, which pays for pattern parsing and IL emission on first use in every build node. Microsoft.Android.Build.Tasks targets net12.0, so moving the task there lets it use source-generated regexes instead. Move `FindLayoutsToBind` into Microsoft.Android.Build.Tasks, keeping its `Xamarin.Android.Tasks` namespace and `AndroidTask` base class, and register it with the Full/Core `UsingTask` pair so `<FindLayoutsToBind/>` and `<Xamarin.Android.Tasks.FindLayoutsToBind/>` both continue to resolve. The pattern embedded `Path.DirectorySeparatorChar`, so it becomes two `[GeneratedRegex]` properties, one per separator, selected at runtime. Pattern text and `RegexOptions.IgnoreCase` are unchanged; the pattern contains no culture-sensitive letters (`i`/`I`), so the generated regex matches exactly like the runtime one under tr-TR, az, and en-US. There were no unit tests for this task; add tests to Microsoft.Android.Build.Tasks.Tests covering resource/bound/cached layout collection and name resolution through the targets' `UsingTask` entries. Co-authored-by: Copilot App <[email protected]>
…tsToBind Move FindLayoutsToBind into the Microsoft.Android.Tasks namespace, matching other MABT tasks such as BuildAppBundle, and register it with the existing Full/Core UsingTask pair. The short <FindLayoutsToBind/> name used by the targets is unchanged. Co-authored-by: Copilot App <[email protected]>
There was a problem hiding this comment.
🟢 Approval recommended
No active review issues are recorded for the task migration.
No open issues 🎉
What changed in this PR
Moves FindLayoutsToBind to Microsoft.Android.Build.Tasks so it can use source-generated regexes, reducing first-use overhead while preserving layout matching behavior. This follows the task-migration approach used for BuildAppBundle in #13460.
Changes:
- Replaces the runtime-compiled regex with Windows and Unix source-generated variants.
- Updates task registration to use the existing Full/Core MSBuild hosting pattern.
- Adds tests for layout collection, filtering, metadata, deduplication, disabled bindings, and short-name task resolution.
| File | Description |
|---|---|
src/Xamarin.Android.Build.Tasks/Xamarin.Android.Common.targets |
Registers the migrated task for Full and Core MSBuild. |
src/Microsoft.Android.Build.Tasks/Tests/Microsoft.Android.Build.Tasks.Tests/Tasks/FindLayoutsToBindTests.cs |
Adds task behavior and registration tests. |
src/Microsoft.Android.Build.Tasks/Tasks/FindLayoutsToBind.cs |
Moves the task namespace and introduces source-generated regexes. |
Review effort: Balanced
|
/review |
|
✅ Android PR Reviewer completed successfully!
|
There was a problem hiding this comment.
✅ LGTM on code
Findings: 0 errors, 0 warnings, 1 non-blocking inline testing suggestion.
Reviewed all three changed files in full, the task's caller, project configuration, shared task base, and neighboring registrations. I found no correctness regression in the move: both generated regex patterns preserve the original separator-specific expressions, and collection ordering, case-insensitive de-duplication, and bound-item metadata handling remain unchanged. The new tests cover collection/filtering and short-name task resolution; the inline suggestion adds coverage for project-relative paths across the hosting change.
CI evidence: All 41 GitHub checks on e956ead1ffafde54a113cf58663fb539e960d930 report success, including the aggregate dotnet-android check for Azure build 1674280. Independent Azure build/timeline verification was unavailable because the CLI required authentication and the timeline query also encountered a CLI initialization error; I cannot independently confirm the underlying Azure result. Local tests were not run: this checkout targets .NET 12, while the installed SDKs stop at .NET 10.
Generated by Android PR Reviewer for #13473 · copilot · gpt61 · 37 AIC · ⌖ 7.37 AIC · ⊞ 19.4K
Comment /review to run again
…paths Run the registration smoke test from a separate working directory with absolute and project-relative resource and dependency-cache inputs, preserving output item identities. Co-authored-by: Copilot App <[email protected]>
|
/review |
|
✅ Android PR Reviewer completed successfully!
|
There was a problem hiding this comment.
Code assessment: no blocking findings. 0 ❌ errors · 0
Reviewed all three changed files, the task's caller, project configuration, and surrounding hosting patterns at ac4de7ddf0e8b1c0d62104c82b8bd570f0e16190. The generated patterns preserve the original separator/qualifier matching, and the migration leaves collection, metadata, de-duplication, and output identities intact. The registration follows the existing modern-task Full/Core pattern. The new project-relative smoke-test coverage addresses the previous review comment.
CI: All 40 GitHub checks report success, including the aggregate dotnet-android check for Azure build 1677629. Independent Azure build/timeline verification was blocked because az devops invoke requires authentication in this environment, so full CI verification remains incomplete. This was a source review; I did not rerun the tests locally.
Generated by Android PR Reviewer for #13473 · copilot · gpt61 · 36.8 AIC · ⌖ 4.76 AIC · ⊞ 20.2K
Comment /review to run again
| var task = new FindLayoutsToBind { | ||
| BuildEngine = new MockBuildEngine (TestContext.Out), | ||
| GenerateLayoutBindings = false, | ||
| ResourceFiles = [new TaskItem (layout)], |
There was a problem hiding this comment.
🤖 💡 Testing — Consider adding a disabled-auto-binding case that also supplies an explicit BoundLayouts item and a valid dependency cache. GenerateLayoutBindings=false intentionally skips only ResourceFiles; explicit bindings and cached dependencies must still be collected. The current empty-output case would also pass if a future refactor incorrectly returned early when this flag is false. Assert that the explicit/cached layouts remain, their identities and explicit metadata are preserved, and the ordinary resource is excluded.
{Rule: Test edge cases and preserve existing task behavior}
Context: #13460
FindLayoutsToBindmatches resource paths with aRegexthat is built during type initialization withRegexOptions.Compiled. As a result, every build node pays for pattern parsing and IL emission the first time the task runs. Microsoft.Android.Build.Tasks targets net12.0, so moving the task there lets it use a source-generated regex instead.This follows the same pattern as #13460 (
BuildAppBundle):FindLayoutsToBindintosrc/Microsoft.Android.Build.Tasks/Tasks/under theMicrosoft.Android.Tasksnamespace. It keeps its existingAndroidTaskbase class, and the Xamarin.Android.Build.Tasks copy is removed.UsingTaskwith the existing Full/Core pair used for other MABT tasks. Full MSBuild usesRuntime="NET" TaskFactory="TaskHostFactory", while .NET MSBuild loads it in-proc withRuntime="NET". The short<FindLayoutsToBind/>invocation in_FindLayoutsForBindingis unchanged.Regex
The original pattern included
Path.DirectorySeparatorChar(\\or/), which isn't a compile-time constant. It is now two[GeneratedRegex]partial properties, one per separator, and the right one is selected at runtime. The pattern text andRegexOptions.IgnoreCaseare unchanged.RegexOptions.Compiledis dropped because the generator ignores it. The pattern doesn't containi/Ior any other letter with culture-sensitive case mapping, soCultureInvariantis not added and matching does not depend on culture. A throwaway harness that compared the runtime-built and generated regexes on 240 paths for each separator undertr-TR,az-Latn-AZ,en-US, and invariant culture found 0/960 mismatches.Tests
The task had no unit tests.
FindLayoutsToBindTestsin Microsoft.Android.Build.Tasks.Tests now covers:ResourceFiles,BoundLayouts(including metadata and case-insensitive de-duplication), and the dependency cache file, with non-layout, missing, and non-XML files filtered out;GenerateLayoutBindings=false;UsingTaskpair inXamarin.Android.Common.targets, and confirming that<FindLayoutsToBind/>resolves through it underdotnet msbuild.Validation
dotnet test src/Microsoft.Android.Build.Tasks/Tests/Microsoft.Android.Build.Tasks.Tests/Microsoft.Android.Build.Tasks.Tests.csproj --filter "FullyQualifiedName~FindLayoutsToBindTests": Passed 3/3dotnet test src/Microsoft.Android.Build.Tasks/Tests/Microsoft.Android.Build.Tasks.Tests/Microsoft.Android.Build.Tasks.Tests.csproj: Passed 867, Failed 0, Skipped 12 (run before the final namespace/registration commit)make prepare && make leeroy(Debug), followed by./dotnet-local.sh buildof Microsoft.Android.Build.Tasks and Xamarin.Android.Build.Tasks: succeeded. The deployedXamarin.Android.Common.targetscontains the new pair, andFindLayoutsToBindis present only intools/net/Microsoft.Android.Build.Tasks.dll../dotnet-local.sh test bin/TestDebug/net11.0/Xamarin.Android.Build.Tests.dll --filter "Name~SuccessfulBuildFew"(CodeBehind end-to-end,AndroidGenerateLayoutBindings=true, CoreCLR + NativeAOT, DTB and normal builds): Passed 4/4Full MSBuild (Visual Studio) /
TaskHostFactoryhosting was not exercised locally because this was done on macOS. Like the other net12.0 MABT tasks, this task does not load under .NET 11 MSBuild (MSB4061).Measurements
I measured first use in a fresh process (regex construction plus matching 400 representative resource paths, 130 of which match), running 30 alternating before/after processes on macOS arm64:
new Regex (…, Compiled | IgnoreCase)[GeneratedRegex]That saves about 3.4 ms per build node the first time the task runs, with identical match results.