mirror of
https://github.com/github/codeql.git
synced 2026-04-28 10:15:14 +02:00
Compute unique identifier (folder path) for each compilation
This commit is contained in:
@@ -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),
|
||||
() => { });
|
||||
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user