mirror of
https://github.com/github/codeql.git
synced 2025-12-17 01:03:14 +01:00
C#: Improve log messages in standalone extractor
This commit is contained in:
@@ -21,17 +21,18 @@ namespace Semmle.Extraction.CSharp.DependencyFetching
|
||||
/// <param name="progressMonitor">Callback for progress.</param>
|
||||
public AssemblyCache(IEnumerable<string> paths, IEnumerable<string> frameworkPaths, ProgressMonitor progressMonitor)
|
||||
{
|
||||
this.progressMonitor = progressMonitor;
|
||||
foreach (var path in paths)
|
||||
{
|
||||
if (File.Exists(path))
|
||||
{
|
||||
pendingDllsToIndex.Enqueue(path);
|
||||
dllsToIndex.Add(path);
|
||||
continue;
|
||||
}
|
||||
|
||||
if (Directory.Exists(path))
|
||||
{
|
||||
progressMonitor.FindingFiles(path);
|
||||
progressMonitor.LogInfo($"Finding reference DLLs in {path}...");
|
||||
AddReferenceDirectory(path);
|
||||
}
|
||||
else
|
||||
@@ -52,7 +53,7 @@ namespace Semmle.Extraction.CSharp.DependencyFetching
|
||||
{
|
||||
foreach (var dll in new DirectoryInfo(dir).EnumerateFiles("*.dll", SearchOption.AllDirectories))
|
||||
{
|
||||
pendingDllsToIndex.Enqueue(dll.FullName);
|
||||
dllsToIndex.Add(dll.FullName);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -62,12 +63,16 @@ namespace Semmle.Extraction.CSharp.DependencyFetching
|
||||
/// </summary>
|
||||
private void IndexReferences(IEnumerable<string> frameworkPaths)
|
||||
{
|
||||
progressMonitor.LogInfo($"Indexing {dllsToIndex.Count} assemblies...");
|
||||
|
||||
// Read all of the files
|
||||
foreach (var filename in pendingDllsToIndex)
|
||||
foreach (var filename in dllsToIndex)
|
||||
{
|
||||
IndexReference(filename);
|
||||
}
|
||||
|
||||
progressMonitor.LogInfo($"Read {assemblyInfoByFileName.Count} assembly infos");
|
||||
|
||||
foreach (var info in assemblyInfoByFileName.Values
|
||||
.OrderBy(info => info.Name)
|
||||
.OrderAssemblyInfosByPreference(frameworkPaths))
|
||||
@@ -83,25 +88,16 @@ namespace Semmle.Extraction.CSharp.DependencyFetching
|
||||
{
|
||||
try
|
||||
{
|
||||
progressMonitor.LogDebug($"Reading assembly info from {filename}");
|
||||
var info = AssemblyInfo.ReadFromFile(filename);
|
||||
assemblyInfoByFileName[filename] = info;
|
||||
}
|
||||
catch (AssemblyLoadException)
|
||||
{
|
||||
failedAssemblyInfoFileNames.Add(filename);
|
||||
progressMonitor.LogInfo($"Couldn't read assembly info from {filename}");
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// The number of DLLs which are assemblies.
|
||||
/// </summary>
|
||||
public int AssemblyCount => assemblyInfoByFileName.Count;
|
||||
|
||||
/// <summary>
|
||||
/// The number of DLLs which weren't assemblies. (E.g. C++).
|
||||
/// </summary>
|
||||
public int NonAssemblyCount => failedAssemblyInfoFileNames.Count;
|
||||
|
||||
/// <summary>
|
||||
/// Given an assembly id, determine its full info.
|
||||
/// </summary>
|
||||
@@ -113,8 +109,7 @@ namespace Semmle.Extraction.CSharp.DependencyFetching
|
||||
if (failedAssemblyInfoIds.Contains(id))
|
||||
throw new AssemblyLoadException();
|
||||
|
||||
string assemblyName;
|
||||
(id, assemblyName) = AssemblyInfo.ComputeSanitizedAssemblyInfo(id);
|
||||
(id, var assemblyName) = AssemblyInfo.ComputeSanitizedAssemblyInfo(id);
|
||||
|
||||
// Look up the id in our references map.
|
||||
if (assemblyInfoById.TryGetValue(id, out var result))
|
||||
@@ -164,17 +159,15 @@ namespace Semmle.Extraction.CSharp.DependencyFetching
|
||||
throw new AssemblyLoadException();
|
||||
}
|
||||
|
||||
private readonly Queue<string> pendingDllsToIndex = new Queue<string>();
|
||||
private readonly List<string> dllsToIndex = new List<string>();
|
||||
|
||||
private readonly Dictionary<string, AssemblyInfo> assemblyInfoByFileName = new Dictionary<string, AssemblyInfo>();
|
||||
|
||||
// List of DLLs which are not assemblies.
|
||||
// We probably don't need to keep this
|
||||
private readonly List<string> failedAssemblyInfoFileNames = new List<string>();
|
||||
|
||||
// Map from assembly id (in various formats) to the full info.
|
||||
private readonly Dictionary<string, AssemblyInfo> assemblyInfoById = new Dictionary<string, AssemblyInfo>();
|
||||
|
||||
private readonly HashSet<string> failedAssemblyInfoIds = new HashSet<string>();
|
||||
|
||||
private readonly ProgressMonitor progressMonitor;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user