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 3 commits
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
Original file line number Diff line number Diff line change
@@ -31,28 +31,43 @@ 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 (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
foreach (var runtimeIdentifier in runtimeIdentifiers)
{
dependencyGraphPerFramework.Add(targetFrameworkAlias, null);
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

// 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;
if (runtimeIdentifier != null)
{
dependencyGraphPerFramework.Add($"{targetFrameworkAlias}/{runtimeIdentifier}",
GetDependencyGraphForTargetPerFramework(topLevelReferences, packageLibraries, targetPackage));
}
else
{
dependencyGraphPerFramework.Add(targetFrameworkAlias,
GetDependencyGraphForTargetPerFramework(topLevelReferences, packageLibraries, targetPackage));
}
Nigusu-Allehu marked this conversation as resolved.
Show resolved Hide resolved
}
else
{
dependencyGraphPerFramework.Add(targetFrameworkAlias, null);
Nigusu-Allehu marked this conversation as resolved.
Show resolved Hide resolved
}
}
}
}
Original file line number Diff line number Diff line change
@@ -206,6 +206,32 @@ public void DifferentCaseUsedForTargetPackageId_MatchesAreCaseInsensitive_AllPat
Assert.Contains(dependencyGraphs["net472"].First(dep => dep.Id == "DotnetNuGetWhyPackage").Children, dep => (dep.Id == "System.Text.Json") && (dep.Version == "8.0.0"));
}

[Fact]
public void GetAllDependencyGraphsForTarget_WithWinX64Runtime_FindsRIDSpecificPackages()
Nigusu-Allehu marked this conversation as resolved.
Show resolved Hide resolved
{
// Arrange
var lockFileFormat = new LockFileFormat();
var lockFileContent = ProtocolUtility.GetResource("NuGet.CommandLine.Xplat.Tests.compiler.resources.Test.SampleProject2.project.assets.json", GetType());
var assetsFile = lockFileFormat.Parse(lockFileContent, "In Memory");

if (XunitAttributeUtility.CurrentPlatform == Platform.Linux || XunitAttributeUtility.CurrentPlatform == Platform.Darwin)
{
ConvertRelevantWindowsPathsToUnix(assetsFile);
}

string targetPackage = "system.private.uri";
var frameworks = new List<string>();

// Act
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"));
}

private static void ConvertRelevantWindowsPathsToUnix(LockFile assetsFile)
{
assetsFile.PackageSpec.FilePath = ConvertWindowsPathToUnix(assetsFile.PackageSpec.FilePath);
Original file line number Diff line number Diff line change
@@ -17,11 +17,8 @@
<PackageReference Include="System.CommandLine" />
</ItemGroup>

<ItemGroup>
<Folder Include="compiler\resources\" />
</ItemGroup>

<ItemGroup>
<EmbeddedResource Include="compiler\resources\DNW.Test.SampleProject1.project.assets.json" />
<EmbeddedResource Include="compiler\resources\Test.SampleProject2.project.assets.json" />
</ItemGroup>
</Project>
Loading
Loading