-
Notifications
You must be signed in to change notification settings - Fork 1.6k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
C#: Adjust trap location, database ID and archiving of generated sources
- Loading branch information
Showing
8 changed files
with
124 additions
and
42 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
60 changes: 60 additions & 0 deletions
60
csharp/extractor/Semmle.Extraction/Extractor/BinaryLogExtractionContext.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
using System.Collections.Generic; | ||
using System.IO; | ||
using System.Linq; | ||
using Microsoft.CodeAnalysis; | ||
using Semmle.Util.Logging; | ||
|
||
namespace Semmle.Extraction | ||
{ | ||
public class BinaryLogExtractionContext : ExtractionContext | ||
{ | ||
private readonly IEnumerable<SyntaxTree> generatedSyntaxTrees; | ||
private readonly string compilationIdentifier; | ||
private readonly string generatedFolderName; | ||
|
||
public BinaryLogExtractionContext(string cwd, string[] args, string outputPath, | ||
IEnumerable<SyntaxTree> generatedSyntaxTrees, string compilationIdentifier, | ||
ILogger logger, PathTransformer pathTransformer, bool isQlTest) | ||
: base(cwd, args, outputPath, [], logger, pathTransformer, ExtractorMode.BinaryLog, isQlTest) | ||
{ | ||
this.generatedSyntaxTrees = generatedSyntaxTrees; | ||
this.compilationIdentifier = compilationIdentifier; | ||
|
||
// Compute a unique folder name for the generated files: | ||
generatedFolderName = "generated"; | ||
|
||
if (Directory.Exists(generatedFolderName)) | ||
{ | ||
var counter = 0; | ||
do | ||
{ | ||
generatedFolderName = $"generated{counter++}"; | ||
} | ||
while (Directory.Exists(generatedFolderName)); | ||
} | ||
} | ||
|
||
private string? GetAdjustedPath(string path) | ||
{ | ||
var syntaxTree = generatedSyntaxTrees.FirstOrDefault(t => t.FilePath == path); | ||
if (syntaxTree is null) | ||
{ | ||
return null; | ||
} | ||
|
||
return Path.Join(generatedFolderName, compilationIdentifier, path); | ||
} | ||
|
||
public static string? GetAdjustedPath(ExtractionContext extractionContext, string sourcePath) | ||
{ | ||
if (extractionContext.Mode.HasFlag(ExtractorMode.BinaryLog) | ||
&& extractionContext is BinaryLogExtractionContext binaryLogExtractionContext | ||
&& binaryLogExtractionContext.GetAdjustedPath(sourcePath) is string adjustedPath) | ||
{ | ||
return adjustedPath; | ||
} | ||
|
||
return null; | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
2 changes: 1 addition & 1 deletion
2
csharp/ql/integration-tests/all-platforms/binlog/Files.expected
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,5 @@ | ||
| Program.cs:0:0:0:0 | Program.cs | | ||
| System.Text.RegularExpressions.Generator/System.Text.RegularExpressions.Generator.RegexGenerator/RegexGenerator.g.cs:0:0:0:0 | System.Text.RegularExpressions.Generator/System.Text.RegularExpressions.Generator.RegexGenerator/RegexGenerator.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 | | ||
| obj/Debug/net8.0/.NETCoreApp,Version=v8.0.AssemblyAttributes.cs:0:0:0:0 | obj/Debug/net8.0/.NETCoreApp,Version=v8.0.AssemblyAttributes.cs | | ||
| obj/Debug/net8.0/test.AssemblyInfo.cs:0:0:0:0 | obj/Debug/net8.0/test.AssemblyInfo.cs | | ||
| obj/Debug/net8.0/test.GlobalUsings.g.cs:0:0:0:0 | obj/Debug/net8.0/test.GlobalUsings.g.cs | |