Skip to content

[Xamarin.Android.Build.Tasks] Enable MT resource directory collection - #13602

Merged
jonathanpeppers merged 2 commits into
mainfrom
jonathanpeppers-mt-resource-directory-collection
Nov 19, 2026
Merged

jonathanpeppers merged 2 commits into
mainfrom
jonathanpeppers-mt-resource-directory-collection

Conversation

@jonathanpeppers

Copy link
Copy Markdown
Member

CollectNonEmptyDirectories is still sent to a TaskHost in -mt builds. Mark it multithreadable and resolve file access through TaskEnvironment so it can run in-process without changing resource paths or cache behavior.

Tested on Windows with the local SDK:

  • .\dotnet-local.cmd build src\Xamarin.Android.Build.Tasks\Tests\Xamarin.Android.Build.Tests\Xamarin.Android.Build.Tests.csproj -c Debug -m:4 -nr:false: passed, no warnings.
  • .\dotnet-local.cmd test bin\TestDebug\net11.0\Xamarin.Android.Build.Tests.dll --filter FullyQualifiedName~CollectNonEmptyDirectoriesTests: 4 passed, including strict -mt execution.

CollectNonEmptyDirectories runs in a TaskHost under -mt. Opt it into in-process execution and resolve file I/O through TaskEnvironment, keeping logical resource paths, cache names, timestamps, and metadata unchanged.

Validation: the local test-project build and all four CollectNonEmptyDirectoriesTests passed on Windows, including strict MT execution.

Co-authored-by: Copilot App <[email protected]>
Copilot AI balanced review requested due to automatic review settings November 17, 2026 22:31

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

The negative assertion checks stdout/stderr instead of BuildLogFile, so it can pass even when the TaskHost diagnostic is emitted.

1 open issue
What changed in this PR

Enables CollectNonEmptyDirectories to run in-process during multithreaded MSBuild builds, using project-specific paths while preserving resource output and cache behavior.

Changes:

  • Marks the task multithreadable and resolves filesystem access through TaskEnvironment.
  • Preserves input path forms when collecting resource files.
  • Adds tests for parallel projects, cache timestamps, metadata preservation, and empty or missing directories.
File Description
src/​Xamarin.Android.Build.Tasks/​Tests/​Xamarin.Android.Build.Tests/​Tasks/​CollectNonEmptyDirectoriesTests.cs Adds strict multithreaded execution and resource-cache regression tests.
src/​Xamarin.Android.Build.Tasks/​Tasks/​CollectNonEmptyDirectories.cs Enables multithreaded execution with project-relative filesystem access.

Review effort: Balanced

DotNetCLI disables console logging, so ProcessLogFile does not contain MSBuild task diagnostics. Read BuildLogFile and require a task diagnostic before checking that it did not run in TaskHost.

Validation: local test-project build passed without warnings; all four CollectNonEmptyDirectoriesTests passed.

Co-authored-by: Copilot App <[email protected]>
@jonathanpeppers jonathanpeppers added the ready-to-review This PR is ready to review/merge, I think any CI failures are just flaky (ignorable). label Nov 18, 2026
@jonathanpeppers
jonathanpeppers enabled auto-merge (squash) November 18, 2026 16:01
@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.

Reviewed af6c38ce against main at e92065fc (merge-base 46c6a36f). This is a static, read-only review; I did not build or run tests.

LGTM.

  • Follows the established MT pattern. [MSBuildMultiThreadableTask] is on the concrete class and the task now derives from MultithreadedAndroidTask, matching AndroidComputeResPaths and the rules enforced by MultiThreadedMigrationTests.
  • No file access depends on the process CWD any more. Directory.Exists, the stamp/cache File.Exists/GetLastWriteTimeUtc/ReadAllLines/WriteAllLines, EnumerateFiles, and the library-project prefix check all go through TaskEnvironment.GetAbsolutePath(...). Without -mt, the fallback environment resolves against the CWD, so behavior there is unchanged.
  • Outputs and cache contents keep their original form. The hash still uses the raw ItemSpec. StampFile/FilesCache metadata store the original strings, not the resolved paths. Enumerated files are re-rooted onto the original ItemSpec, so files.cache contents (and caches from older builds) stay identical. The consumers in Xamarin.Android.Aapt2.targets (_CollectLibraryResourceDirectories inputs/outputs, %(_ArchiveDirectory)%(_FlatFile), ResourceDirectories, AdditionalAndroidResourcePaths) see the same values as before.
  • Tests exercise the change. RelativeCacheUsesStampTimestamp would fail on the merge-base, because the directory resolved against the runner CWD. The fixed TaskHost assertion now reads BuildLogFile, checks that the task-start line is present, and then checks that MSBuild's ran in TaskHost message is absent, so it can't pass vacuously. The -m:2 -mt -nr:false -warnaserror:MSB4286,MSB4287,MSB4288 setup matches the sibling -mt tests already merged.
  • No conflicting drift on main. None of the 22 commits since the merge-base touch this task, its targets consumers, the MT base class, or DotNetCLI.

I didn't find any thread-safety concerns: the task has no static or shared state, and the helpers it calls (Files.HashString, IsInvalidFilename, CalculateAapt2FlatArchiveFileName) are pure.

@jonathanpeppers
jonathanpeppers merged commit 5b32fb1 into main Nov 19, 2026
38 checks passed
@jonathanpeppers
jonathanpeppers deleted the jonathanpeppers-mt-resource-directory-collection branch November 19, 2026 15:42
simonrozsival added a commit that referenced this pull request Nov 21, 2026
The rebase onto cc7cbf6 kept the pre-rebase MSTest conversions of
files that main had changed since aa688ac, which reverted those
changes and broke the build. For each affected file, convert main's
old and new NUnit versions with the same converter and merge the
difference into the MSTest file:

  * cca255c (#13592): drop the Android lint tests and assertions.
  * 5b32fb1 (#13602): add RelativeDirectoriesUseProjectDirectory and
    the -mt CollectNonEmptyDirectories coverage.
  * 78ef747 (#13655): add OpenGenericProxiesKeepTheReflectionActivationConstructor.
  * 18b8940 (#13585): add the generator nullability/obsolete tests.
  * dcbd008 (#13580): add the AmbiguousFunctionMetadata_* tests.
  * 667e27a (#13621): add the sdkmanager package ID tests.
  * 5ecb8f7 (#13614): drop RunWithLoggingEnablesManagedTimingLogger.
  * 8287b17 (#13680), 4bfcc92 (#13681): restore the re-enabled
    tests and removed TODOs.
  * 5d81a0f (#13666): expect platform-tools 37.0.3.
  * 8442c75 (#13601): assert the pulled device TRX is deleted.

Also drop the EnableNUnitRunner/OutputType lines that 857f463
(#13563) added to Xamarin.Android.Build.Tests and MSBuildDeviceIntegration;
MSTestReferences.projitems sets both.

Co-authored-by: Copilot App <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

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