Skip to content

Commit

Permalink
Cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
nkolev92 committed Dec 16, 2024
1 parent 401cd34 commit 8c30394
Showing 1 changed file with 14 additions and 22 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -189,7 +189,7 @@ async static (state) =>

refImport.Clear();
chosenResolvedItems.Clear();

// TODO NK - Clear
refImport.Enqueue(rootProjectRefItem);

while (refImport.Count > 0)
Expand Down Expand Up @@ -618,7 +618,7 @@ async static (state) =>
suppressions = currentSuppressions;
}

List<int> ints = new List<int>();
List<int>? prunedPackageIndices = null;
for (int i = 0; i < refItemResult.Item.Data.Dependencies.Count; i++)
{
LibraryDependency dep = refItemResult.Item.Data.Dependencies[i];
Expand All @@ -627,7 +627,8 @@ async static (state) =>

if (ShouldPrunePackage(projectTargetFramework!, refItemResult, dep, isPackage, isDirectPackageReferenceFromRootProject))
{
ints.Add(i);
prunedPackageIndices = prunedPackageIndices ?? new List<int>();
prunedPackageIndices.Add(i);
continue;
}

Expand Down Expand Up @@ -697,7 +698,6 @@ async static (state) =>
token);
}

RemoveDependencies(refItemResult.Item.Data.Dependencies, ints);
// Add runtime dependencies of the current node if a runtime identifier has been specified.
if (!string.IsNullOrEmpty(pair.RuntimeIdentifier) && runtimeDependencies != null && runtimeDependencies.Count > 0)
{
Expand Down Expand Up @@ -736,13 +736,12 @@ async static (state) =>
// Enqueue each of the runtime dependencies, but only if they weren't already present in refItemResult before merging the runtime dependencies above.
if ((rootNode.Item.Data.Dependencies.Count - runtimeDependencyIndex) == runtimeDependencies!.Count)
{
List<int> runtimeInts = new List<int>();

foreach (var dep in runtimeDependencies)
{
if (ShouldPrunePackage(projectTargetFramework!, refItemResult, dep, isPackage: true, isDirectPackageReferenceFromRootProject: false))
{
runtimeInts.Add(runtimeDependencyIndex);
prunedPackageIndices = prunedPackageIndices ?? new List<int>();
prunedPackageIndices.Add(runtimeDependencyIndex);
continue;
}

Expand Down Expand Up @@ -777,10 +776,11 @@ async static (state) =>

runtimeDependencyIndex++;
}

RemoveDependencies(rootNode.Item.Data.Dependencies, runtimeInts);
}
}

// TODO NK - Should I updated chosen result item?
importRefItem.PrunedPackageIndices = prunedPackageIndices;
}

//Now that we've completed import, figure out the short real flattened list
Expand Down Expand Up @@ -824,7 +824,7 @@ async static (state) =>
LibraryRangeIndex[] pathToChosenRef = foundItem.Path;
bool directPackageReferenceFromRootProject = foundItem.IsDirectPackageReferenceFromRootProject;
List<HashSet<LibraryDependencyIndex>> chosenSuppressions = foundItem.Suppressions;

// TODO NK - findLibraryEntryCache is updated and this is how we get the list of dependencies.
if (findLibraryEntryCache.TryGetValue(chosenRefRangeIndex, out Task<FindLibraryEntryResult>? nodeTask))
{
FindLibraryEntryResult node = await nodeTask;
Expand All @@ -840,6 +840,8 @@ async static (state) =>
continue;
}

// TOOD NK - Determine whether to skip here.

if (StringComparer.OrdinalIgnoreCase.Equals(dep.Name, node.Item.Key.Name) || StringComparer.OrdinalIgnoreCase.Equals(dep.Name, rootGraphNode.Key.Name))
{
// Cycle
Expand Down Expand Up @@ -1199,18 +1201,6 @@ async static (state) =>
return (_success, allGraphs, allRuntimes);
}

private static void RemoveDependencies(List<LibraryDependency> dependencies, List<int> ints)
{
if (ints.Count > 0)
{
for (int i = ints.Count - 1; i >= 0; i--)
{
int index = ints[i];
dependencies.RemoveAt(index);
}
}
}

private bool ShouldPrunePackage(TargetFrameworkInformation projectTargetFramework, FindLibraryEntryResult refItemResult, LibraryDependency dep, bool isPackage, bool isDirectPackageReferenceFromRootProject)
{
if (projectTargetFramework!.PackagesToPrune.TryGetValue(dep.Name, out PrunePackageReference? prunableVersion))
Expand Down Expand Up @@ -1432,6 +1422,8 @@ private class DependencyGraphItem
public LibraryRangeIndex Parent { get; set; }

public HashSet<LibraryDependencyIndex>? Suppressions { get; set; }

public List<int>? PrunedPackageIndices { get; set; } // This needs to be moved to ChosenResolvedItem potentially?
}

private class FindLibraryEntryResult
Expand Down

0 comments on commit 8c30394

Please sign in to comment.