diff options
author | Vitek Karas <10670590+vitek-karas@users.noreply.github.com> | 2022-02-15 17:49:17 +0300 |
---|---|---|
committer | GitHub <noreply@github.com> | 2022-02-15 17:49:17 +0300 |
commit | 76ffc18a8e64ef4be91f2a267c21c7123f05e868 (patch) | |
tree | befb2353d4945c67f3d70e15e4e79379d8e9c722 /test | |
parent | 500f76bba438898ebacce096c2ed4d0d090b8295 (diff) |
Fix how test find the ref pack to compile test cases against (#2610)
With latest VS we get a 6.0.2 runtime but only 6.0.1 ref pack. The tests so far expected to use the exact same version, but there's no hard rule that it will be the case.
Change the algorithm to search for highest available major.minor.* ref pack if the matching one doesn't exist.
Diffstat (limited to 'test')
-rw-r--r-- | test/Mono.Linker.Tests/TestCasesRunner/TestCaseCompilationMetadataProvider.cs | 22 |
1 files changed, 21 insertions, 1 deletions
diff --git a/test/Mono.Linker.Tests/TestCasesRunner/TestCaseCompilationMetadataProvider.cs b/test/Mono.Linker.Tests/TestCasesRunner/TestCaseCompilationMetadataProvider.cs index 666377377..79e5b17a0 100644 --- a/test/Mono.Linker.Tests/TestCasesRunner/TestCaseCompilationMetadataProvider.cs +++ b/test/Mono.Linker.Tests/TestCasesRunner/TestCaseCompilationMetadataProvider.cs @@ -111,7 +111,27 @@ namespace Mono.Linker.Tests.TestCasesRunner string runtimeDir = Path.GetDirectoryName (typeof (object).Assembly.Location); string ncaVersion = Path.GetFileName (runtimeDir); var dotnetDir = Path.GetDirectoryName (Path.GetDirectoryName (Path.GetDirectoryName (runtimeDir))); - return Path.Combine (dotnetDir, "packs", "Microsoft.NETCore.App.Ref", ncaVersion, "ref", PathUtilities.TFMDirectoryName); + string candidatePath = Path.Combine (dotnetDir, "packs", "Microsoft.NETCore.App.Ref", ncaVersion, "ref", PathUtilities.TFMDirectoryName); + if (Directory.Exists (candidatePath)) + return candidatePath; + + // There's no rule that runtime version must match the reference pack version exactly. So in this case use the major.minor only + // and find the highest available patch version (since the runtime should also be the highest available patch version in that range) + string ncaVersionWithoutPatch = ncaVersion.Substring (0, ncaVersion.LastIndexOf ('.')); + candidatePath = null; + foreach (var dir in Directory.GetDirectories (Path.Combine (dotnetDir, "Packs", "Microsoft.NETCore.App.Ref"), ncaVersionWithoutPatch + ".*")) { + if (candidatePath == null || StringComparer.Ordinal.Compare (dir, candidatePath) > 0) + candidatePath = dir; + } + + if (candidatePath == null) + throw new InvalidOperationException ($"Could not determine ref pack path. Based on runtime directory {runtimeDir}."); + + candidatePath = Path.Combine (candidatePath, "ref", PathUtilities.TFMDirectoryName); + if (Directory.Exists (candidatePath)) + return candidatePath; + + throw new InvalidOperationException ($"Could not determine ref pack path. Computed path {candidatePath} doesn't exist."); } public virtual IEnumerable<string> GetCommonReferencedAssemblies (NPath workingDirectory) |