Skip to content

Commit 0b41d51

Browse files
committed
Compute unique identifier (folder path) for each compilation
1 parent 1ae40c9 commit 0b41d51

File tree

3 files changed

+29
-9
lines changed

3 files changed

+29
-9
lines changed

csharp/extractor/Semmle.Extraction.CSharp/Extractor/Extractor.cs

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -154,8 +154,20 @@ static bool filter(CompilerCall compilerCall)
154154

155155
var compilerCall = compilationData.CompilerCall;
156156
var diagnosticName = compilerCall.GetDiagnosticName();
157-
logger.LogInfo($" Processing compilation {diagnosticName}");
157+
logger.LogInfo($" Processing compilation {diagnosticName} at {compilerCall.ProjectDirectory}");
158158
var compilerArgs = compilerCall.GetArguments();
159+
160+
var compilationIdentifierPath = string.Empty;
161+
try
162+
{
163+
compilationIdentifierPath = FileUtils.ConvertPathToSafeRelativePath(
164+
Path.GetRelativePath(Directory.GetCurrentDirectory(), compilerCall.ProjectDirectory));
165+
}
166+
catch (ArgumentException exc)
167+
{
168+
logger.LogWarning($" Failed to get relative path for {compilerCall.ProjectDirectory} from current working directory {Directory.GetCurrentDirectory()}: {exc.Message}");
169+
}
170+
159171
var args = reader.ReadCommandLineArguments(compilerCall);
160172

161173
// Generated syntax trees are always added to the end of the list of syntax trees.
@@ -173,7 +185,7 @@ static bool filter(CompilerCall compilerCall)
173185
TracingAnalyser.GetOutputName(compilation, args),
174186
compilation,
175187
generatedSyntaxTrees,
176-
diagnosticName,
188+
Path.Combine(compilationIdentifierPath, diagnosticName),
177189
options),
178190
() => { });
179191

csharp/extractor/Semmle.Util/FileUtils.cs

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -113,17 +113,24 @@ private static async Task DownloadFileAsync(string address, string filename)
113113
public static void DownloadFile(string address, string fileName) =>
114114
DownloadFileAsync(address, fileName).GetAwaiter().GetResult();
115115

116+
public static string ConvertPathToSafeRelativePath(string path)
117+
{
118+
// Remove all leading path separators / or \
119+
// For example, UNC paths have two leading \\
120+
path = path.TrimStart(Path.DirectorySeparatorChar, Path.AltDirectorySeparatorChar);
121+
122+
if (path.Length > 1 && path[1] == ':')
123+
path = path[0] + "_" + path.Substring(2);
124+
125+
return path;
126+
}
127+
116128
public static string NestPaths(ILogger logger, string? outerpath, string innerpath)
117129
{
118130
var nested = innerpath;
119131
if (!string.IsNullOrEmpty(outerpath))
120132
{
121-
// Remove all leading path separators / or \
122-
// For example, UNC paths have two leading \\
123-
innerpath = innerpath.TrimStart(Path.DirectorySeparatorChar, Path.AltDirectorySeparatorChar);
124-
125-
if (innerpath.Length > 1 && innerpath[1] == ':')
126-
innerpath = innerpath[0] + "_" + innerpath.Substring(2);
133+
innerpath = ConvertPathToSafeRelativePath(innerpath);
127134

128135
nested = Path.Combine(outerpath, innerpath);
129136
}

csharp/ql/integration-tests/all-platforms/binlog/Files.expected

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,4 +6,5 @@
66
| b/obj/Debug/net8.0/.NETCoreApp,Version=v8.0.AssemblyAttributes.cs:0:0:0:0 | b/obj/Debug/net8.0/.NETCoreApp,Version=v8.0.AssemblyAttributes.cs |
77
| b/obj/Debug/net8.0/test.AssemblyInfo.cs:0:0:0:0 | b/obj/Debug/net8.0/test.AssemblyInfo.cs |
88
| b/obj/Debug/net8.0/test.GlobalUsings.g.cs:0:0:0:0 | b/obj/Debug/net8.0/test.GlobalUsings.g.cs |
9-
| generated/test.csproj (net8.0)/System.Text.RegularExpressions.Generator/System.Text.RegularExpressions.Generator.RegexGenerator/RegexGenerator.g.cs:0:0:0:0 | generated/test.csproj (net8.0)/System.Text.RegularExpressions.Generator/System.Text.RegularExpressions.Generator.RegexGenerator/RegexGenerator.g.cs |
9+
| generated/a/test.csproj (net8.0)/System.Text.RegularExpressions.Generator/System.Text.RegularExpressions.Generator.RegexGenerator/RegexGenerator.g.cs:0:0:0:0 | generated/a/test.csproj (net8.0)/System.Text.RegularExpressions.Generator/System.Text.RegularExpressions.Generator.RegexGenerator/RegexGenerator.g.cs |
10+
| generated/b/test.csproj (net8.0)/System.Text.RegularExpressions.Generator/System.Text.RegularExpressions.Generator.RegexGenerator/RegexGenerator.g.cs:0:0:0:0 | generated/b/test.csproj (net8.0)/System.Text.RegularExpressions.Generator/System.Text.RegularExpressions.Generator.RegexGenerator/RegexGenerator.g.cs |

0 commit comments

Comments
 (0)