Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add RID specific packages to dotnet nuget why #6154

Merged
merged 5 commits into from
Nov 22, 2024
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
cleanup
  • Loading branch information
Nigusu-Allehu committed Nov 19, 2024
commit dc25cf286cea3947465c61556c306f38f7f85b1f
Original file line number Diff line number Diff line change
@@ -8,7 +8,6 @@
using System.IO;
using System.Linq;
using NuGet.ProjectModel;
using NuGet.RuntimeModel;

namespace NuGet.CommandLine.XPlat.Commands.Why
{
@@ -32,16 +31,20 @@ internal static class DependencyGraphFinder
var dependencyGraphPerFramework = new Dictionary<string, List<DependencyNode>?>(assetsFile.Targets.Count);
bool doesProjectHaveDependencyOnPackage = false;

// add null to the list of runtime identifiers to account for projects that do not have a runtime identifier
var runtimeIdentifiers = assetsFile.PackageSpec.RuntimeGraph.Runtimes.Keys
.Append(null)
.ToList();
// get all top-level package and project references for the project, categorized by target framework alias
Dictionary<string, List<string>> topLevelReferencesByFramework = GetTopLevelPackageAndProjectReferences(assetsFile, userInputFrameworks);

if (topLevelReferencesByFramework.Count > 0)
{
foreach (KeyValuePair<string, RuntimeDescription> keyValuePair in assetsFile.PackageSpec.RuntimeGraph.Runtimes)
foreach (var (targetFrameworkAlias, topLevelReferences) in topLevelReferencesByFramework)
{
foreach (var (targetFrameworkAlias, topLevelReferences) in topLevelReferencesByFramework)
foreach (var runtimeIdentifier in runtimeIdentifiers)
{
LockFileTarget? target = assetsFile.GetTarget(targetFrameworkAlias, runtimeIdentifier: keyValuePair.Key);
LockFileTarget? target = assetsFile.GetTarget(targetFrameworkAlias, runtimeIdentifier: runtimeIdentifier);
Nigusu-Allehu marked this conversation as resolved.
Show resolved Hide resolved

// get all package libraries for the framework
IList<LockFileTargetLibrary>? packageLibraries = target?.Libraries;
Nigusu-Allehu marked this conversation as resolved.
Show resolved Hide resolved
@@ -50,35 +53,23 @@ internal static class DependencyGraphFinder
if (packageLibraries?.Any(l => l?.Name?.Equals(targetPackage, StringComparison.OrdinalIgnoreCase) == true) == true)
{
doesProjectHaveDependencyOnPackage = true;
dependencyGraphPerFramework.Add($"{targetFrameworkAlias} / {keyValuePair.Key}",
if (runtimeIdentifier != null)
{
dependencyGraphPerFramework.Add($"{targetFrameworkAlias}/{runtimeIdentifier}",
GetDependencyGraphForTargetPerFramework(topLevelReferences, packageLibraries, targetPackage));
}
else
{
dependencyGraphPerFramework.Add(targetFrameworkAlias,
GetDependencyGraphForTargetPerFramework(topLevelReferences, packageLibraries, targetPackage));
}
}
else
{
dependencyGraphPerFramework.Add(targetFrameworkAlias, null);
Nigusu-Allehu marked this conversation as resolved.
Show resolved Hide resolved
}
}
}

foreach (var (targetFrameworkAlias, topLevelReferences) in topLevelReferencesByFramework)
{
LockFileTarget? target = assetsFile.GetTarget(targetFrameworkAlias, runtimeIdentifier: null);

// get all package libraries for the framework
IList<LockFileTargetLibrary>? packageLibraries = target?.Libraries;

// if the project has a dependency on the target package, get the dependency graph
if (packageLibraries?.Any(l => l?.Name?.Equals(targetPackage, StringComparison.OrdinalIgnoreCase) == true) == true)
{
doesProjectHaveDependencyOnPackage = true;
dependencyGraphPerFramework.Add(targetFrameworkAlias,
GetDependencyGraphForTargetPerFramework(topLevelReferences, packageLibraries, targetPackage));
}
else
{
dependencyGraphPerFramework.Add(targetFrameworkAlias, null);
}
}
}

return doesProjectHaveDependencyOnPackage
Original file line number Diff line number Diff line change
@@ -226,10 +226,10 @@ public void GetAllDependencyGraphsForTarget_WithWinX64Runtime_FindsRIDSpecificPa
var dependencyGraphs = DependencyGraphFinder.GetAllDependencyGraphsForTarget(assetsFile, targetPackage, frameworks);

// Assert
Assert.Contains(dependencyGraphs["net9.0 / win-x64"], dep => (dep.Id == "System.AppContext") && (dep.Version == "4.3.0"));
Assert.Contains(dependencyGraphs["net9.0 / win-x64"].First().Children, dep => (dep.Id == "System.Runtime") && (dep.Version == "4.3.0"));
Assert.Contains(dependencyGraphs["net9.0 / win-x64"].First().Children.First().Children, dep => (dep.Id == "runtime.any.System.Runtime") && (dep.Version == "4.3.0"));
Assert.Contains(dependencyGraphs["net9.0 / win-x64"].First().Children.First().Children.First().Children, dep => (dep.Id == "System.Private.Uri") && (dep.Version == "4.3.0"));
Assert.Contains(dependencyGraphs["net9.0/win-x64"], dep => (dep.Id == "System.AppContext") && (dep.Version == "4.3.0"));
Assert.Contains(dependencyGraphs["net9.0/win-x64"].First().Children, dep => (dep.Id == "System.Runtime") && (dep.Version == "4.3.0"));
Assert.Contains(dependencyGraphs["net9.0/win-x64"].First().Children.First().Children, dep => (dep.Id == "runtime.any.System.Runtime") && (dep.Version == "4.3.0"));
Assert.Contains(dependencyGraphs["net9.0/win-x64"].First().Children.First().Children.First().Children, dep => (dep.Id == "System.Private.Uri") && (dep.Version == "4.3.0"));
}

private static void ConvertRelevantWindowsPathsToUnix(LockFile assetsFile)