From aa1a4d1443bd6773ca05baa8d3fc21d460470bfa Mon Sep 17 00:00:00 2001 From: Simon Rozsival Date: Wed, 11 Nov 2026 01:16:11 +0100 Subject: [PATCH 1/4] [Xamarin.Android.Build.Tasks] Move Lint to Microsoft.Android.Build.Tasks MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Context: #13460 Move the `` task from Xamarin.Android.Build.Tasks (netstandard2.0) into Microsoft.Android.Build.Tasks (net12.0) so its fixed regular expressions can use the `[GeneratedRegex]` source generator instead of `RegexOptions.Compiled`, following the BuildAppBundle move in #13460. The task now lives in the `Microsoft.Android.Tasks` namespace, keeps its `AndroidToolTask` base class, and is registered through the existing Full/Core `` pair; the unqualified `` invocation in `Xamarin.Android.Common.targets` is unchanged. Regex changes: * `CodeErrorRegEx`, `NoFileWarningOrErrorRegEx`, and `LintVersionRegex` become `[GeneratedRegex]` partial properties with the same pattern text and no options (`RegexOptions.Compiled` is ignored by the generator). None use `IgnoreCase`, so there is no culture-casing concern. * The two parsing regexes were per-instance fields; they are now static, which is safe because `Regex` is thread-safe. * The runtime-built `issueReplaceRegex` in `CleanIssues()` stays a runtime `Regex`. Helpers: `MonoAndroidHelper.cs` is not linked into Microsoft.Android.Build.Tasks, so `MonoAndroidHelper.RunProcess()` (both overloads), `ItemGroupToCaseMap()`, and `FixUpAndroidResourcePath()` move verbatim into a new `MonoAndroidHelper.Shared.cs`, which both assemblies compile. Aapt2, ConvertResourcesCases, ConvertCustomView, ValidateJavaVersion, ResolveAndroidTooling, and GetAvailableAndroidDevices still use them from Xamarin.Android.Build.Tasks. The new file is `#nullable enable`, so it uses the `IsNullOrEmpty()` extension for netstandard2.0 flow analysis. The net12.0 nullable annotations surfaced five warnings-as-errors in `Lint.cs`. They are fixed without `!` and without changing reachable behavior: `Version?` locals, `Path.GetDirectoryName (tool) ?? ""`, an explicit `ArgumentNullException` where `Regex.Match (null)` already threw one, and an `InvalidOperationException` instead of a `NullReferenceException` for a `@(AndroidLintConfig)` file without a `` root. There were no Lint unit tests. The new `LintTests` in Microsoft.Android.Build.Tasks.Tests: * pins `LogEventsFromTextOutput()` parsing (file/line/column/message for file and file-less warnings and errors); * checks the Full/Core registration pair; * runs both `` and `` through `dotnet msbuild` against a fake `lint` script, which covers task resolution, `lint --version` parsing (`LintVersionRegex`), and output parsing end-to-end. Known limitation: like the other Microsoft.Android.Build.Tasks tasks, Lint now needs .NET 12 MSBuild (Core) or the .NET 12 task host (Full); it fails with MSB4061 under .NET 11 MSBuild. Performance: a fresh-process harness loaded each optimized task assembly (`-p:Optimize=true`), created `Lint` instances, and fed 100 lines of representative lint output through `LogEventsFromTextOutput()`. 20 interleaved before/after process pairs on macOS arm64, medians (p25-p75): | Metric (per 100 lines) | Before (XABT) | After (MABT) | | ------------------------------------ | ------------------------ | ------------------------ | | First task in a fresh process | 15,975 µs (15,899-16,240) | 14,232 µs (14,066-14,458) | | Second task instance, same process | 2,467 µs (2,450-2,517) | 2,228 µs (2,220-2,253) | | Next 200 batches (tier-0 window) | 580 µs (579-582) | 1,740 µs (1,717-2,048) | | Steady state after warm-up | 548 µs (547-550) | 405 µs (404-407) | Emitted diagnostics were byte-identical before and after. `RegexOptions.Compiled` emits optimized dynamic methods up front, while the generated matcher is ordinary IL that starts at tier 0, so output parsing is about 3x slower until tiered compilation catches up, then about 26% faster. A build parses lint output once, so the realistic gain is the 1.7 ms first-use saving, which is small next to the cost of running `lint` itself. No meaningful build-time change is claimed. Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com> --- .../Microsoft.Android.Build.Tasks.csproj | 2 + .../Tasks/Lint.cs | 31 ++-- .../Tasks/LintTests.cs | 158 ++++++++++++++++++ .../Utilities/MonoAndroidHelper.Shared.cs | 77 +++++++++ .../Utilities/MonoAndroidHelper.cs | 65 ------- .../Xamarin.Android.Common.targets | 3 +- 6 files changed, 257 insertions(+), 79 deletions(-) rename src/{Xamarin.Android.Build.Tasks => Microsoft.Android.Build.Tasks}/Tasks/Lint.cs (93%) create mode 100644 src/Microsoft.Android.Build.Tasks/Tests/Microsoft.Android.Build.Tasks.Tests/Tasks/LintTests.cs create mode 100644 src/Xamarin.Android.Build.Tasks/Utilities/MonoAndroidHelper.Shared.cs diff --git a/src/Microsoft.Android.Build.Tasks/Microsoft.Android.Build.Tasks.csproj b/src/Microsoft.Android.Build.Tasks/Microsoft.Android.Build.Tasks.csproj index 7a28da06c17..8aec2b62fc2 100644 --- a/src/Microsoft.Android.Build.Tasks/Microsoft.Android.Build.Tasks.csproj +++ b/src/Microsoft.Android.Build.Tasks/Microsoft.Android.Build.Tasks.csproj @@ -76,6 +76,8 @@ + +