-
Notifications
You must be signed in to change notification settings - Fork 540
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[release/8.2] Fix RID regression by adding a task that calculates the…
… best matching RID for platform (#5807) * Fix RID regression by adding a task that calculates the best matching RID for each platform. * Use out-of-proc instead of MSBuild task * Do not show the output of running the tool as 'High' importance * PR Feedback * PR Feedback * Fix package authoring * Fix TFM on rid tool * Fix issues with wrong variable names * Address PR feedback
- Loading branch information
Showing
13 changed files
with
311 additions
and
10 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
2 changes: 1 addition & 1 deletion
2
...k/Aspire.Hosting.Orchestration.in.targets → ...pack/Aspire.Hosting.Orchestration.targets
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
17 changes: 17 additions & 0 deletions
17
src/Aspire.Hosting.Sdk/Aspire.RuntimeIdentifier.Tool/Aspire.RuntimeIdentifier.Tool.csproj
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
<Project Sdk="Microsoft.NET.Sdk"> | ||
|
||
<PropertyGroup> | ||
<OutputType>Exe</OutputType> | ||
<TargetFramework>$(NetCurrent)</TargetFramework> | ||
<RollForward>Major</RollForward> | ||
<UsePublicApiAnalyzers>false</UsePublicApiAnalyzers> | ||
<IsPackable>false</IsPackable> | ||
<UseAppHost>false</UseAppHost> | ||
</PropertyGroup> | ||
|
||
<ItemGroup> | ||
<PackageReference Include="System.CommandLine" /> | ||
<PackageReference Include="NuGet.ProjectModel" /> | ||
</ItemGroup> | ||
|
||
</Project> |
50 changes: 50 additions & 0 deletions
50
src/Aspire.Hosting.Sdk/Aspire.RuntimeIdentifier.Tool/NuGetUtils.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
// Licensed to the .NET Foundation under one or more agreements. | ||
// The .NET Foundation licenses this file to you under the MIT license. | ||
|
||
using NuGet.RuntimeModel; | ||
|
||
namespace Aspire.Hosting.Sdk; | ||
|
||
/* | ||
* These utility methods were copied from the sdk repository to mimic the behavior used when selecting the best matching RID | ||
* for a given runtime identifier. For more information, please see the original source code at: | ||
* https://github.com/dotnet/sdk/blob/e6da8ca6de3ec8f392dc87b8529415e1ef59b7ea/src/Tasks/Microsoft.NET.Build.Tasks/NuGetUtils.NuGet.cs#L76-L109 | ||
*/ | ||
|
||
internal static class NuGetUtils | ||
{ | ||
public static string? GetBestMatchingRid(RuntimeGraph runtimeGraph, string runtimeIdentifier, | ||
IEnumerable<string> availableRuntimeIdentifiers, out bool wasInGraph) | ||
{ | ||
return GetBestMatchingRidWithExclusion(runtimeGraph, runtimeIdentifier, | ||
runtimeIdentifiersToExclude: null, | ||
availableRuntimeIdentifiers, out wasInGraph); | ||
} | ||
|
||
public static string? GetBestMatchingRidWithExclusion(RuntimeGraph runtimeGraph, string runtimeIdentifier, | ||
IEnumerable<string>? runtimeIdentifiersToExclude, | ||
IEnumerable<string> availableRuntimeIdentifiers, out bool wasInGraph) | ||
{ | ||
wasInGraph = runtimeGraph.Runtimes.ContainsKey(runtimeIdentifier); | ||
|
||
string? bestMatch = null; | ||
|
||
HashSet<string> availableRids = new(availableRuntimeIdentifiers, StringComparer.Ordinal); | ||
HashSet<string>? excludedRids = runtimeIdentifiersToExclude switch { null => null, _ => new HashSet<string>(runtimeIdentifiersToExclude, StringComparer.Ordinal) }; | ||
foreach (var candidateRuntimeIdentifier in runtimeGraph.ExpandRuntime(runtimeIdentifier)) | ||
{ | ||
if (bestMatch == null && availableRids.Contains(candidateRuntimeIdentifier)) | ||
{ | ||
bestMatch = candidateRuntimeIdentifier; | ||
} | ||
|
||
if (excludedRids != null && excludedRids.Contains(candidateRuntimeIdentifier)) | ||
{ | ||
// Don't treat this as a match | ||
return null; | ||
} | ||
} | ||
|
||
return bestMatch; | ||
} | ||
} |
87 changes: 87 additions & 0 deletions
87
src/Aspire.Hosting.Sdk/Aspire.RuntimeIdentifier.Tool/Program.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,87 @@ | ||
// Licensed to the .NET Foundation under one or more agreements. | ||
// The .NET Foundation licenses this file to you under the MIT license. | ||
|
||
using System.CommandLine; | ||
using System.CommandLine.Parsing; | ||
using System.Diagnostics; | ||
using System.Reflection; | ||
using Aspire.Hosting.Sdk; | ||
using NuGet.RuntimeModel; | ||
|
||
namespace Aspire.RuntimeIdentifier.Tool; | ||
|
||
sealed class Program | ||
{ | ||
static int Main(string[] args) | ||
{ | ||
CliRootCommand rootCommand = new("Aspire.RuntimeIdentifier.Tool v" + FileVersionInfo.GetVersionInfo(Assembly.GetExecutingAssembly().Location).ProductVersion) | ||
{ | ||
TreatUnmatchedTokensAsErrors = true | ||
}; | ||
|
||
CliOption<string?> runtimeGraphPathOption = new("--runtimeGraphPath") | ||
{ | ||
Description = "Path to runtime graph path to use for RID mapping.", | ||
Required = true | ||
}; | ||
|
||
CliOption<string?> netcoreSdkRuntimeIdentifierOption = new("--netcoreSdkRuntimeIdentifier") | ||
{ | ||
Description = "RID to use for finding the best applicable RID from mapping.", | ||
Required = true | ||
}; | ||
|
||
CliOption<string[]> supportedRidsOption = new("--supportedRids") | ||
{ | ||
Description = "List of RIDs that are supported. Comma-separated.", | ||
Required = true, | ||
Arity = ArgumentArity.OneOrMore, | ||
CustomParser = ParseSupportedRidsArgument | ||
}; | ||
|
||
rootCommand.Options.Add(runtimeGraphPathOption); | ||
rootCommand.Options.Add(netcoreSdkRuntimeIdentifierOption); | ||
rootCommand.Options.Add(supportedRidsOption); | ||
rootCommand.SetAction((ParseResult parseResult) => | ||
{ | ||
string rgp = parseResult.GetValue(runtimeGraphPathOption) ?? throw new InvalidOperationException("The --runtimeGraphPath argument is required."); | ||
|
||
if (!File.Exists(rgp)) | ||
{ | ||
Console.WriteLine($"File {rgp} does not exist. Please ensure the runtime graph path exists."); | ||
return -1; | ||
} | ||
|
||
RuntimeGraph graph = JsonRuntimeFormat.ReadRuntimeGraph(rgp); | ||
|
||
var ridToUse = parseResult.GetValue(netcoreSdkRuntimeIdentifierOption); | ||
|
||
var supportedRids = parseResult.GetValue(supportedRidsOption); | ||
|
||
string? bestRidForPlatform = NuGetUtils.GetBestMatchingRid(graph, ridToUse!, supportedRids!, out bool wasInGraph); | ||
|
||
if (!wasInGraph) | ||
{ | ||
Console.WriteLine("Unable to find the best rid to use"); | ||
return -1; | ||
} | ||
|
||
Console.WriteLine(bestRidForPlatform); | ||
return 0; | ||
}); | ||
|
||
return rootCommand.Parse(args).Invoke(); | ||
} | ||
|
||
private static string[]? ParseSupportedRidsArgument(ArgumentResult result) | ||
{ | ||
List<string> args = new(); | ||
|
||
foreach (var token in result.Tokens) | ||
{ | ||
args.AddRange(token.Value.Split(',')); | ||
} | ||
|
||
return args.ToArray(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.