Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit ffc2a64

Browse files
committed
C#: do not discard duplicate trapfiles for compilation parameter extraction
1 parent 1094d19 commit ffc2a64

5 files changed

Lines changed: 9 additions & 9 deletions

File tree

csharp/extractor/Semmle.Extraction.CIL/Entities/Assembly.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -140,7 +140,7 @@ public static void ExtractCIL(Layout layout, string assemblyPath, ILogger logger
140140
var extractor = new Extractor(false, assemblyPath, logger, pathTransformer);
141141
var transformedAssemblyPath = pathTransformer.Transform(assemblyPath);
142142
var project = layout.LookupProjectOrDefault(transformedAssemblyPath);
143-
using var trapWriter = project.CreateTrapWriter(logger, transformedAssemblyPath.WithSuffix(".cil"), true, trapCompression);
143+
using var trapWriter = project.CreateTrapWriter(logger, transformedAssemblyPath.WithSuffix(".cil"), trapCompression, discardDuplicates: true);
144144
trapFile = trapWriter.TrapFile;
145145
if (nocache || !System.IO.File.Exists(trapFile))
146146
{

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

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -230,7 +230,7 @@ private void DoAnalyseCompilation(string cwd, string[] args)
230230
var transformedAssemblyPath = PathTransformer.Transform(assemblyPath);
231231
var assembly = compilation.Assembly;
232232
var projectLayout = layout.LookupProjectOrDefault(transformedAssemblyPath);
233-
var trapWriter = projectLayout.CreateTrapWriter(Logger, transformedAssemblyPath, true, options.TrapCompression);
233+
var trapWriter = projectLayout.CreateTrapWriter(Logger, transformedAssemblyPath, options.TrapCompression, discardDuplicates: false);
234234
compilationTrapFile = trapWriter; // Dispose later
235235
var cx = extractor.CreateContext(compilation.Clone(), trapWriter, new AssemblyScope(assembly, assemblyPath, true), AddAssemblyTrapPrefix);
236236

@@ -260,7 +260,7 @@ private void DoAnalyseAssembly(PortableExecutableReference r)
260260
var assemblyPath = r.FilePath;
261261
var transformedAssemblyPath = PathTransformer.Transform(assemblyPath);
262262
var projectLayout = layout.LookupProjectOrDefault(transformedAssemblyPath);
263-
using var trapWriter = projectLayout.CreateTrapWriter(Logger, transformedAssemblyPath, true, options.TrapCompression);
263+
using var trapWriter = projectLayout.CreateTrapWriter(Logger, transformedAssemblyPath, options.TrapCompression, discardDuplicates: true);
264264

265265
var skipExtraction = options.Cache && File.Exists(trapWriter.TrapFile);
266266

@@ -365,7 +365,7 @@ private void DoExtractTree(SyntaxTree tree)
365365
if (!excluded)
366366
{
367367
// compilation.Clone() is used to allow symbols to be garbage collected.
368-
using var trapWriter = projectLayout.CreateTrapWriter(Logger, transformedSourcePath, false, options.TrapCompression);
368+
using var trapWriter = projectLayout.CreateTrapWriter(Logger, transformedSourcePath, options.TrapCompression, discardDuplicates: false);
369369

370370
upToDate = options.Fast && FileIsUpToDate(sourcePath, trapWriter.TrapFile);
371371

csharp/extractor/Semmle.Extraction.Tests/Layout.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ public void TestDefaultLayout()
6060

6161
// Test trap file generation
6262
var trapwriterFilename = project.GetTrapPath(logger, new TransformedPathStub("foo.cs"), TrapWriter.CompressionMode.Gzip);
63-
using (var trapwriter = project.CreateTrapWriter(logger, new TransformedPathStub("foo.cs"), false, TrapWriter.CompressionMode.Gzip))
63+
using (var trapwriter = project.CreateTrapWriter(logger, new TransformedPathStub("foo.cs"), TrapWriter.CompressionMode.Gzip, discardDuplicates: false))
6464
{
6565
trapwriter.Emit("1=*");
6666
Assert.False(File.Exists(trapwriterFilename));
@@ -104,7 +104,7 @@ public void TestLayoutFile()
104104
trapwriterFilename);
105105

106106
// Test the source archive
107-
var trapWriter = project.CreateTrapWriter(logger, new TransformedPathStub("bar.cs"), false, TrapWriter.CompressionMode.Gzip);
107+
var trapWriter = project.CreateTrapWriter(logger, new TransformedPathStub("bar.cs"), TrapWriter.CompressionMode.Gzip, discardDuplicates: false);
108108
trapWriter.Archive("layout.txt", new TransformedPathStub("layout.txt"), System.Text.Encoding.ASCII);
109109
var writtenFile = TrapWriter.NestPaths(logger, Path.GetFullPath("snapshot\\archive"), "layout.txt");
110110
Assert.True(File.Exists(writtenFile));

csharp/extractor/Semmle.Extraction/Layout.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -62,8 +62,8 @@ public string GetTrapPath(ILogger logger, PathTransformer.ITransformedPath srcFi
6262
/// </summary>
6363
/// <param name="srcFile">The source file.</param>
6464
/// <returns>A newly created TrapWriter.</returns>
65-
public TrapWriter CreateTrapWriter(ILogger logger, PathTransformer.ITransformedPath srcFile, bool discardDuplicates, TrapWriter.CompressionMode trapCompression) =>
66-
new TrapWriter(logger, srcFile, TRAP_FOLDER, SOURCE_ARCHIVE, discardDuplicates, trapCompression);
65+
public TrapWriter CreateTrapWriter(ILogger logger, PathTransformer.ITransformedPath srcFile, TrapWriter.CompressionMode trapCompression, bool discardDuplicates) =>
66+
new TrapWriter(logger, srcFile, TRAP_FOLDER, SOURCE_ARCHIVE, trapCompression, discardDuplicates);
6767
}
6868

6969
private readonly SubProject defaultProject;

csharp/extractor/Semmle.Extraction/TrapWriter.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ public enum CompressionMode
3939

4040
private readonly CompressionMode trapCompression;
4141

42-
public TrapWriter(ILogger logger, PathTransformer.ITransformedPath outputfile, string? trap, string? archive, bool discardDuplicates, CompressionMode trapCompression)
42+
public TrapWriter(ILogger logger, PathTransformer.ITransformedPath outputfile, string? trap, string? archive, CompressionMode trapCompression, bool discardDuplicates)
4343
{
4444
this.logger = logger;
4545
this.trapCompression = trapCompression;

0 commit comments

Comments
 (0)