Skip to content

Commit

Permalink
Compute unique identifier (folder path) for each compilation
Browse files Browse the repository at this point in the history
  • Loading branch information
tamasvajk committed Jun 27, 2024
1 parent 4ee3f3f commit a57938d
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 9 deletions.
16 changes: 14 additions & 2 deletions csharp/extractor/Semmle.Extraction.CSharp/Extractor/Extractor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -155,8 +155,20 @@ static bool filter(CompilerCall compilerCall)

var compilerCall = compilationData.CompilerCall;
var diagnosticName = compilerCall.GetDiagnosticName();
logger.LogInfo($" Processing compilation {diagnosticName}");
logger.LogInfo($" Processing compilation {diagnosticName} at {compilerCall.ProjectDirectory}");
var compilerArgs = compilerCall.GetArguments();

var compilationIdentifierPath = string.Empty;
try
{
compilationIdentifierPath = FileUtils.ConvertPathToSafeRelativePath(
Path.GetRelativePath(Directory.GetCurrentDirectory(), compilerCall.ProjectDirectory));
}
catch (ArgumentException exc)
{
logger.LogWarning($" Failed to get relative path for {compilerCall.ProjectDirectory} from current working directory {Directory.GetCurrentDirectory()}: {exc.Message}");
}

var args = reader.ReadCommandLineArguments(compilerCall);

// Generated syntax trees are always added to the end of the list of syntax trees.
Expand All @@ -174,7 +186,7 @@ static bool filter(CompilerCall compilerCall)
TracingAnalyser.GetOutputName(compilation, args),
compilation,
generatedSyntaxTrees,
diagnosticName,
Path.Combine(compilationIdentifierPath, diagnosticName),
options),
() => { });

Expand Down
19 changes: 13 additions & 6 deletions csharp/extractor/Semmle.Util/FileUtils.cs
Original file line number Diff line number Diff line change
Expand Up @@ -113,17 +113,24 @@ private static async Task DownloadFileAsync(string address, string filename)
public static void DownloadFile(string address, string fileName) =>
DownloadFileAsync(address, fileName).GetAwaiter().GetResult();

public static string ConvertPathToSafeRelativePath(string path)
{
// Remove all leading path separators / or \
// For example, UNC paths have two leading \\
path = path.TrimStart(Path.DirectorySeparatorChar, Path.AltDirectorySeparatorChar);

if (path.Length > 1 && path[1] == ':')
path = path[0] + "_" + path.Substring(2);

return path;
}

public static string NestPaths(ILogger logger, string? outerpath, string innerpath)
{
var nested = innerpath;
if (!string.IsNullOrEmpty(outerpath))
{
// Remove all leading path separators / or \
// For example, UNC paths have two leading \\
innerpath = innerpath.TrimStart(Path.DirectorySeparatorChar, Path.AltDirectorySeparatorChar);

if (innerpath.Length > 1 && innerpath[1] == ':')
innerpath = innerpath[0] + "_" + innerpath.Substring(2);
innerpath = ConvertPathToSafeRelativePath(innerpath);

nested = Path.Combine(outerpath, innerpath);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,5 @@
| 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 |
| b/obj/Debug/net8.0/test.AssemblyInfo.cs:0:0:0:0 | b/obj/Debug/net8.0/test.AssemblyInfo.cs |
| b/obj/Debug/net8.0/test.GlobalUsings.g.cs:0:0:0:0 | b/obj/Debug/net8.0/test.GlobalUsings.g.cs |
| 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 |
| 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 |
| 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 comments on commit a57938d

Please sign in to comment.