Skip to content

Commit 74a5852

Browse files
committed
C#: Extract source files generated by source generators
1 parent 5de8934 commit 74a5852

File tree

2 files changed

+15
-5
lines changed

2 files changed

+15
-5
lines changed

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

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -381,8 +381,17 @@ private static ExitCode AnalyseTracing(
381381
references => ResolveReferences(compilerArguments, analyser, canonicalPathCache, references),
382382
(analyser, syntaxTrees) =>
383383
{
384+
var paths = compilerArguments.SourceFiles
385+
.Select(src => src.Path)
386+
.ToList();
387+
388+
if (compilerArguments.GeneratedFilesOutputDirectory is not null)
389+
{
390+
paths.AddRange(Directory.GetFiles(compilerArguments.GeneratedFilesOutputDirectory, "*.cs", SearchOption.AllDirectories));
391+
}
392+
384393
return ReadSyntaxTrees(
385-
compilerArguments.SourceFiles.Select(src => canonicalPathCache.GetCanonicalPath(src.Path)),
394+
paths.Select(canonicalPathCache.GetCanonicalPath),
386395
analyser,
387396
compilerArguments.ParseOptions,
388397
compilerArguments.Encoding,

csharp/tools/tracing-config.lua

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ function RegisterExtractorPack(id)
6363
end
6464
end
6565
if match then
66-
local injections = { '-p:UseSharedCompilation=false' }
66+
local injections = { '-p:UseSharedCompilation=false', '-p:EmitCompilerGeneratedFiles=true' }
6767
if dotnetRunNeedsSeparator then
6868
table.insert(injections, '--')
6969
end
@@ -118,7 +118,8 @@ function RegisterExtractorPack(id)
118118
compilerArguments,
119119
nil, {
120120
'/p:UseSharedCompilation=false',
121-
'/p:MvcBuildViews=true'
121+
'/p:MvcBuildViews=true',
122+
'/p:EmitCompilerGeneratedFiles=true',
122123
})
123124

124125
}
@@ -154,7 +155,7 @@ function RegisterExtractorPack(id)
154155

155156
if seenCompilerCall then
156157
return {
157-
order = ORDER_BEFORE,
158+
order = ORDER_AFTER,
158159
invocation = {
159160
path = AbsolutifyExtractorPath(id, extractor),
160161
arguments = {
@@ -194,7 +195,7 @@ function RegisterExtractorPack(id)
194195

195196
if seenCompilerCall then
196197
return {
197-
order = ORDER_BEFORE,
198+
order = ORDER_AFTER,
198199
invocation = {
199200
path = AbsolutifyExtractorPath(id, extractor),
200201
arguments = {

0 commit comments

Comments
 (0)