Skip to content

Fix locating files in GetCommonSourceFiles#125123

Merged
sbomer merged 1 commit intodotnet:mainfrom
Unity-Technologies:linker-fix-locating-source-files
Mar 4, 2026
Merged

Fix locating files in GetCommonSourceFiles#125123
sbomer merged 1 commit intodotnet:mainfrom
Unity-Technologies:linker-fix-locating-source-files

Conversation

@mrvoorhe
Copy link
Contributor

@mrvoorhe mrvoorhe commented Mar 3, 2026

_testCase.RootCasesDirectory is meant to be configurable. For example, Unity uses the same test framework to run tests that live in Unity.Linker.Tests.Cases. When we run tests, _testCase.RootCasesDirectory is going to be the path to our Unity.Linker.Tests.Cases directory. When that happens GetCommonSourceFiles cannot locate the files relative to _testCase.RootCasesDirectory.

Since GetCommonSourceFiles is trying to explicitly locate files relative to the ILLink test case directory structure the code should be using a known directory to start from rather than a path that is configurable.

I added the new helper methods to PathUtilities and followed the AppContext.GetData pattern. I tried to use [CallerFilePath] but I couldn't get that to work on CI.

While I was here I thought I'd make GetCommonSourceFiles virtual just in case Unity needs to override it in the future.

Copilot AI review requested due to automatic review settings March 3, 2026 14:50
@mrvoorhe mrvoorhe requested a review from sbomer as a code owner March 3, 2026 14:50
@mrvoorhe
Copy link
Contributor Author

mrvoorhe commented Mar 3, 2026

@sbomer please take a look

@github-actions github-actions bot added the area-Tools-ILLink .NET linker development as well as trimming analyzers label Mar 3, 2026
@dotnet-policy-service dotnet-policy-service bot added linkable-framework Issues associated with delivering a linker friendly framework community-contribution Indicates that the PR has been added by a community member labels Mar 3, 2026
@dotnet-policy-service
Copy link
Contributor

Tagging subscribers to this area: @agocke, @dotnet/illink
See info in area-owners.md if you want to be subscribed.

Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR updates the ILLink test framework’s GetCommonSourceFiles path resolution so it doesn’t depend on the configurable _testCase.RootCasesDirectory, which can point at non-ILLink test case trees (e.g., Unity’s).

Changes:

  • Switch GetCommonSourceFiles to compute paths from a “known” test framework directory rather than _testCase.RootCasesDirectory.
  • Add GetMonoLinkerTestsDirectory helper (via CallerFilePath) to find the Mono.Linker.Tests directory.
  • Make GetCommonSourceFiles virtual to allow downstream override.

@mrvoorhe
Copy link
Contributor Author

mrvoorhe commented Mar 3, 2026

I'm looking into the failures

@mrvoorhe
Copy link
Contributor Author

mrvoorhe commented Mar 3, 2026

I haven't figured out the issue yet. Locally when I run tests from Rider they all pass. And when I run from the command line using dotnet they all pass

E:\dev\unity-runtime-1\src\tools\illink>..\..\..\dotnet.cmd test test\Mono.Linker.Tests\Mono.Linker.Tests.csproj -c Release

They do fail when I run the way CI does using

build.cmd -ci -arch x64 -os windows -s tools.illinktests -test -c Release

And I get errors such as

System.IO.DirectoryNotFoundException : Could not find a part of the path 'E:\_\src\tools\illink\test\Mono.Linker.Tests.Cases.Expectations\Support\DynamicallyAccessedMembersAttribute.cs'.

`_testCase.RootCasesDirectory` is meant to be configurable.  For example, Unity uses the same test framework to run tests that live in `Unity.Linker.Tests.Cases`.  When we run tests, `_testCase.RootCasesDirectory` is going to be the path to our `Unity.Linker.Tests.Cases` directory.  When that happens `GetCommonSourceFiles` cannot locate the files relative to `_testCase.RootCasesDirectory`.

Since `GetCommonSourceFiles` is trying to explicitly locate files relative to the ILLink test case directory structure the code should be using a known directory to start from rather than a path that is configurable.

I added the new `GetMonoLinkerTestsDirectory` directory to `TestCaseCompilationMetadataProvider.cs` instead of adding it to `PathUtilities` because it makes life a little easier.  Unity has to provide it's own copy of `PathUtilities` in order to add the `bin` directory in the path returned by `GetTestAssemblyRoot`.  Which means having this path location in `PathUtilities` leads to more wire up work for us.  That said, if you'd prefer `GetMonoLinkerTestsDirectory` be in `PathUtilities` I can move it there and deal with the extra wiring on our end.

While I was here I thought I'd make `GetCommonSourceFiles` virtual just in case Unity needs to override it in the future.
@mrvoorhe mrvoorhe force-pushed the linker-fix-locating-source-files branch from 2716f6f to cf83bba Compare March 4, 2026 14:57
@mrvoorhe
Copy link
Contributor Author

mrvoorhe commented Mar 4, 2026

@sbomer I changed the approach. I'm now using AppContext.GetData instead of [CallerFilePath] and I believe this should pass CI now.

@sbomer sbomer enabled auto-merge (squash) March 4, 2026 23:22
@sbomer
Copy link
Member

sbomer commented Mar 4, 2026

/ba-g "timeouts"

@sbomer sbomer merged commit 8ffb906 into dotnet:main Mar 4, 2026
83 of 87 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area-Tools-ILLink .NET linker development as well as trimming analyzers community-contribution Indicates that the PR has been added by a community member linkable-framework Issues associated with delivering a linker friendly framework

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants