Repository navigation
[Xamarin.Android.Build.Tasks] Enable MT resource directory collection - #13602
Conversation
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]>
There was a problem hiding this comment.
🟡 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]>
|
@dalexsoto review |
dalexsoto
left a comment
There was a problem hiding this comment.
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 fromMultithreadedAndroidTask, matchingAndroidComputeResPathsand the rules enforced byMultiThreadedMigrationTests. - No file access depends on the process CWD any more.
Directory.Exists, the stamp/cacheFile.Exists/GetLastWriteTimeUtc/ReadAllLines/WriteAllLines,EnumerateFiles, and the library-project prefix check all go throughTaskEnvironment.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/FilesCachemetadata store the original strings, not the resolved paths. Enumerated files are re-rooted onto the original ItemSpec, sofiles.cachecontents (and caches from older builds) stay identical. The consumers inXamarin.Android.Aapt2.targets(_CollectLibraryResourceDirectoriesinputs/outputs,%(_ArchiveDirectory)%(_FlatFile),ResourceDirectories,AdditionalAndroidResourcePaths) see the same values as before. - Tests exercise the change.
RelativeCacheUsesStampTimestampwould fail on the merge-base, because the directory resolved against the runner CWD. The fixed TaskHost assertion now readsBuildLogFile, checks that the task-start line is present, and then checks that MSBuild'sran in TaskHostmessage is absent, so it can't pass vacuously. The-m:2 -mt -nr:false -warnaserror:MSB4286,MSB4287,MSB4288setup matches the sibling-mttests 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, orDotNetCLI.
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.
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]>

CollectNonEmptyDirectoriesis still sent to a TaskHost in-mtbuilds. Mark it multithreadable and resolve file access throughTaskEnvironmentso 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-mtexecution.