Compute unique identifier (folder path) for each compilation

This commit is contained in:
Tamas Vajk
2024-06-21 10:11:45 +02:00
parent 1ae40c95b1
commit 0b41d5121a
3 changed files with 29 additions and 9 deletions

View File

@@ -154,8 +154,20 @@ namespace Semmle.Extraction.CSharp
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.
@@ -173,7 +185,7 @@ namespace Semmle.Extraction.CSharp
TracingAnalyser.GetOutputName(compilation, args),
compilation,
generatedSyntaxTrees,
diagnosticName,
Path.Combine(compilationIdentifierPath, diagnosticName),
options),
() => { });

View File

@@ -113,17 +113,24 @@ namespace Semmle.Util
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);
}