Skip to content

Commit 13a8168

Browse files
committed
C#: Improve log messages in standalone extractor
1 parent df8d453 commit 13a8168

File tree

12 files changed

+194
-318
lines changed

12 files changed

+194
-318
lines changed

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

+15-22
Original file line numberDiff line numberDiff line change
@@ -21,17 +21,18 @@ internal class AssemblyCache
2121
/// <param name="progressMonitor">Callback for progress.</param>
2222
public AssemblyCache(IEnumerable<string> paths, IEnumerable<string> frameworkPaths, ProgressMonitor progressMonitor)
2323
{
24+
this.progressMonitor = progressMonitor;
2425
foreach (var path in paths)
2526
{
2627
if (File.Exists(path))
2728
{
28-
pendingDllsToIndex.Enqueue(path);
29+
dllsToIndex.Add(path);
2930
continue;
3031
}
3132

3233
if (Directory.Exists(path))
3334
{
34-
progressMonitor.FindingFiles(path);
35+
progressMonitor.LogInfo($"Finding reference DLLs in {path}...");
3536
AddReferenceDirectory(path);
3637
}
3738
else
@@ -52,7 +53,7 @@ private void AddReferenceDirectory(string dir)
5253
{
5354
foreach (var dll in new DirectoryInfo(dir).EnumerateFiles("*.dll", SearchOption.AllDirectories))
5455
{
55-
pendingDllsToIndex.Enqueue(dll.FullName);
56+
dllsToIndex.Add(dll.FullName);
5657
}
5758
}
5859

@@ -62,12 +63,16 @@ private void AddReferenceDirectory(string dir)
6263
/// </summary>
6364
private void IndexReferences(IEnumerable<string> frameworkPaths)
6465
{
66+
progressMonitor.LogInfo($"Indexing {dllsToIndex.Count} assemblies...");
67+
6568
// Read all of the files
66-
foreach (var filename in pendingDllsToIndex)
69+
foreach (var filename in dllsToIndex)
6770
{
6871
IndexReference(filename);
6972
}
7073

74+
progressMonitor.LogInfo($"Read {assemblyInfoByFileName.Count} assembly infos");
75+
7176
foreach (var info in assemblyInfoByFileName.Values
7277
.OrderBy(info => info.Name)
7378
.OrderAssemblyInfosByPreference(frameworkPaths))
@@ -83,25 +88,16 @@ private void IndexReference(string filename)
8388
{
8489
try
8590
{
91+
progressMonitor.LogDebug($"Reading assembly info from {filename}");
8692
var info = AssemblyInfo.ReadFromFile(filename);
8793
assemblyInfoByFileName[filename] = info;
8894
}
8995
catch (AssemblyLoadException)
9096
{
91-
failedAssemblyInfoFileNames.Add(filename);
97+
progressMonitor.LogInfo($"Couldn't read assembly info from {filename}");
9298
}
9399
}
94100

95-
/// <summary>
96-
/// The number of DLLs which are assemblies.
97-
/// </summary>
98-
public int AssemblyCount => assemblyInfoByFileName.Count;
99-
100-
/// <summary>
101-
/// The number of DLLs which weren't assemblies. (E.g. C++).
102-
/// </summary>
103-
public int NonAssemblyCount => failedAssemblyInfoFileNames.Count;
104-
105101
/// <summary>
106102
/// Given an assembly id, determine its full info.
107103
/// </summary>
@@ -113,8 +109,7 @@ public AssemblyInfo ResolveReference(string id)
113109
if (failedAssemblyInfoIds.Contains(id))
114110
throw new AssemblyLoadException();
115111

116-
string assemblyName;
117-
(id, assemblyName) = AssemblyInfo.ComputeSanitizedAssemblyInfo(id);
112+
(id, var assemblyName) = AssemblyInfo.ComputeSanitizedAssemblyInfo(id);
118113

119114
// Look up the id in our references map.
120115
if (assemblyInfoById.TryGetValue(id, out var result))
@@ -164,17 +159,15 @@ public AssemblyInfo GetAssemblyInfo(string filepath)
164159
throw new AssemblyLoadException();
165160
}
166161

167-
private readonly Queue<string> pendingDllsToIndex = new Queue<string>();
162+
private readonly List<string> dllsToIndex = new List<string>();
168163

169164
private readonly Dictionary<string, AssemblyInfo> assemblyInfoByFileName = new Dictionary<string, AssemblyInfo>();
170165

171-
// List of DLLs which are not assemblies.
172-
// We probably don't need to keep this
173-
private readonly List<string> failedAssemblyInfoFileNames = new List<string>();
174-
175166
// Map from assembly id (in various formats) to the full info.
176167
private readonly Dictionary<string, AssemblyInfo> assemblyInfoById = new Dictionary<string, AssemblyInfo>();
177168

178169
private readonly HashSet<string> failedAssemblyInfoIds = new HashSet<string>();
170+
171+
private readonly ProgressMonitor progressMonitor;
179172
}
180173
}

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

-15
Original file line numberDiff line numberDiff line change
@@ -120,21 +120,6 @@ private AssemblyInfo(string filename, string name, Version version, string cultu
120120
NetCoreVersion = netCoreVersion;
121121
}
122122

123-
/// <summary>
124-
/// Get AssemblyInfo from a loaded Assembly.
125-
/// </summary>
126-
/// <param name="assembly">The assembly.</param>
127-
/// <returns>Info about the assembly.</returns>
128-
public static AssemblyInfo MakeFromAssembly(Assembly assembly)
129-
{
130-
if (assembly.FullName is null)
131-
{
132-
throw new InvalidOperationException("Assembly with empty full name is not expected.");
133-
}
134-
135-
return new AssemblyInfo(assembly.FullName, assembly.Location);
136-
}
137-
138123
/// <summary>
139124
/// Returns the id and name of the assembly that would be created from the received id.
140125
/// </summary>

0 commit comments

Comments
 (0)