Skip to content

Commit 983ac7e

Browse files
committed
C#: Add tool status page information and compilation info for unreachable explicit feeds.
1 parent 00816ca commit 983ac7e

1 file changed

Lines changed: 16 additions & 10 deletions

File tree

csharp/extractor/Semmle.Extraction.CSharp.DependencyFetching/NugetPackageRestorer.cs

Lines changed: 16 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -127,8 +127,8 @@ public HashSet<AssemblyLookupLocation> Restore()
127127
compilationInfoContainer.CompilationInfos.Add(("Inherited NuGet feed count", inheritedFeeds.Count.ToString()));
128128
}
129129

130-
var allExplicitReachable = explicitFeeds.Count == feedManager.ReachableExplicitFeeds.Count;
131-
EmitUnreachableFeedsDiagnostics(allExplicitReachable);
130+
var unreachableExplicitFeeds = explicitFeeds.Except(feedManager.ReachableExplicitFeeds).ToImmutableHashSet();
131+
EmitFeedReachabilityDiagnostics(unreachableExplicitFeeds);
132132
}
133133

134134
try
@@ -536,25 +536,31 @@ private void TryChangeProjectFile(DirectoryInfo projectDir, Regex pattern, strin
536536
}
537537

538538
/// <summary>
539-
/// If <paramref name="allFeedsReachable"/> is `false`, logs this and emits a diagnostic.
539+
/// If <paramref name="unreachableFeeds"/> is not empty, logs this and emits a diagnostic.
540540
/// Adds a `CompilationInfos` entry either way.
541541
/// </summary>
542-
/// <param name="allFeedsReachable">Whether all feeds were reachable or not.</param>
543-
private void EmitUnreachableFeedsDiagnostics(bool allFeedsReachable)
542+
/// <param name="unreachableFeeds">The feeds that were not reachable.</param>
543+
private void EmitFeedReachabilityDiagnostics(ImmutableHashSet<string> unreachableFeeds)
544544
{
545-
if (!allFeedsReachable)
545+
if (unreachableFeeds.Count > 0)
546546
{
547-
logger.LogWarning("Found unreachable NuGet feed in C# analysis with build-mode 'none'. This may cause missing dependencies in the analysis.");
547+
var orderedUnreachableFeeds = unreachableFeeds.OrderBy(feed => feed).ToList();
548+
var unreachableFeedList = string.Join(", ", orderedUnreachableFeeds);
549+
logger.LogWarning($"Found unreachable NuGet feeds in C# analysis with build-mode 'none': {unreachableFeedList}. This may cause missing dependencies in the analysis.");
550+
compilationInfoContainer.CompilationInfos.Add(("Unreachable NuGet feeds", unreachableFeedList));
548551
diagnosticsWriter.AddEntry(new DiagnosticMessage(
549552
Language.CSharp,
550553
"buildless/unreachable-feed",
551-
"Found unreachable NuGet feed in C# analysis with build-mode 'none'",
554+
"Found unreachable NuGet feeds in C# analysis with build-mode 'none'",
552555
visibility: new DiagnosticMessage.TspVisibility(statusPage: true, cliSummaryTable: true, telemetry: true),
553-
markdownMessage: "Found unreachable NuGet feed in C# analysis with build-mode 'none'. This may cause missing dependencies in the analysis.",
556+
markdownMessage: string.Format(
557+
"Found unreachable NuGet feeds in C# analysis with build-mode 'none':\n\n{0}\n\nThis may cause missing dependencies in the analysis.",
558+
string.Join("\n", orderedUnreachableFeeds.Select(feed => $"- `{feed}`"))
559+
),
554560
severity: DiagnosticMessage.TspSeverity.Note
555561
));
556562
}
557-
compilationInfoContainer.CompilationInfos.Add(("All NuGet feeds reachable", allFeedsReachable ? "1" : "0"));
563+
compilationInfoContainer.CompilationInfos.Add(("All NuGet feeds reachable", unreachableFeeds.Count == 0 ? "1" : "0"));
558564
}
559565

560566
private void EmitNugetConfigDiagnostics()

0 commit comments

Comments
 (0)