Skip to content

Commit

Permalink
Proper warning if a root is removed
Browse files Browse the repository at this point in the history
  • Loading branch information
0xced committed Mar 5, 2024
1 parent dbbd8e8 commit afcf8bf
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 9 deletions.
11 changes: 8 additions & 3 deletions src/ChiselTask.cs
Original file line number Diff line number Diff line change
Expand Up @@ -86,13 +86,18 @@ public override bool Execute()
try
{
var graph = new DependencyGraph(ProjectAssetsFile, TargetFramework, RuntimeIdentifier);
var (removed, notFound) = graph.Remove(ChiselPackages.Select(e => e.ItemSpec));
var (removed, notFound, removedRoots) = graph.Remove(ChiselPackages.Select(e => e.ItemSpec));

foreach (var packageName in notFound)
{
Log.LogWarning($"The package {packageName} (defined in ChiselPackages) was not found in the dependency graph");
}

foreach (var packageName in removedRoots)
{
Log.LogWarning($"The package {packageName} (defined in ChiselPackages) can't be removed from the dependency graph because it's a root");
}

RemoveRuntimeAssemblies = RuntimeAssemblies.Where(item => removed.Contains(item.GetMetadata("NuGetPackageId"))).ToArray();
RemoveNativeLibraries = NativeLibraries.Where(item => removed.Contains(item.GetMetadata("NuGetPackageId"))).ToArray();

Expand All @@ -103,13 +108,13 @@ public override bool Execute()

if (Graph != Path.GetFileName(Graph))
{
Log.LogWarning($"The ChiselGraph property ({Graph}) must be a file name that does not include a directory.");
Log.LogWarning($"The ChiselGraph property ({Graph}) must be a file name that does not include a directory");
return true;
}

if (!Directory.Exists(IntermediateOutputPath))
{
Log.LogWarning($"The IntermediateOutputPath property ({IntermediateOutputPath}) must point to an existing directory.");
Log.LogWarning($"The IntermediateOutputPath property ({IntermediateOutputPath}) must point to an existing directory");
return true;
}

Expand Down
19 changes: 13 additions & 6 deletions src/DependencyGraph.cs
Original file line number Diff line number Diff line change
Expand Up @@ -66,17 +66,24 @@ public DependencyGraph(string projectAssetsFile, string tfm, string rid)
}
}

internal (HashSet<string> Removed, HashSet<string> NotFound) Remove(IEnumerable<string> packages)
internal (HashSet<string> Removed, HashSet<string> NotFound, HashSet<string> RemovedRoots) Remove(IEnumerable<string> packages)
{
var notFound = new HashSet<string>();
var dependencies = new HashSet<Package>();
var notFound = new HashSet<string>(StringComparer.OrdinalIgnoreCase);
var removedRoots = new HashSet<string>(StringComparer.OrdinalIgnoreCase);
var dependencies = new HashSet<Package>(PackageComparer.Instance);
foreach (var packageName in packages.Distinct())
{
var packageDependency = _reverseGraph.Keys.SingleOrDefault(e => e.Name.Equals(packageName, StringComparison.OrdinalIgnoreCase));
if (packageDependency == null)
{
if (_roots)
notFound.Add(packageName);
if (_roots.Any(e => e.Name.Equals(packageName, StringComparison.OrdinalIgnoreCase)))
{
removedRoots.Add(packageName);
}
else
{
notFound.Add(packageName);
}
}
else
{
Expand All @@ -90,7 +97,7 @@ public DependencyGraph(string projectAssetsFile, string tfm, string rid)
Restore(dependency, dependencies);
}

return ([.._reverseGraph.Keys.Where(e => !e.Keep).Select(e => e.Name)], notFound);
return ([.._reverseGraph.Keys.Where(e => !e.Keep).Select(e => e.Name)], notFound, removedRoots);
}

private void Remove(Package package)
Expand Down

0 comments on commit afcf8bf

Please sign in to comment.