Skip to content

Commit 0037ad4

Browse files
committed
C#: Adjust buildless source generator folders
1 parent 79bd81f commit 0037ad4

File tree

10 files changed

+27
-50
lines changed

10 files changed

+27
-50
lines changed

csharp/extractor/Semmle.Extraction.CSharp.DependencyFetching/SourceGenerators/DotnetSourceGeneratorBase.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,7 @@ protected override IEnumerable<string> Run()
8383
var targetDir = GetTemporaryWorkingDirectory(FileType.ToLowerInvariant());
8484

8585
return groupedFiles
86-
.SelectMany(group => sourceGenerator.RunSourceGenerator(group.Value, group.Key, references, targetDir));
86+
.SelectMany(group => sourceGenerator.RunSourceGenerator(group.Value, group.Key, references, targetDir, fileProvider.SourceDir.FullName));
8787
}
8888
catch (Exception ex)
8989
{

csharp/extractor/Semmle.Extraction.CSharp.DependencyFetching/SourceGenerators/DotnetSourceGeneratorWrapper/DotnetSourceGeneratorWrapper.cs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,11 +33,12 @@ public DotnetSourceGeneratorWrapper(
3333

3434
protected abstract void GenerateAnalyzerConfig(IEnumerable<string> additionalFiles, string csprojFile, string analyzerConfigPath);
3535

36-
public IEnumerable<string> RunSourceGenerator(IEnumerable<string> additionalFiles, string csprojFile, IEnumerable<string> references, string targetDir)
36+
public IEnumerable<string> RunSourceGenerator(IEnumerable<string> additionalFiles, string csprojFile, IEnumerable<string> references, string targetDir, string sourceDir)
3737
{
3838
try
3939
{
40-
var name = FileUtils.ComputeHash($"{csprojFile}{Environment.NewLine}{this.GetType().Name}");
40+
var relativePathToCsProj = Path.GetRelativePath(sourceDir, csprojFile);
41+
var name = FileUtils.ComputeHash($"{relativePathToCsProj}{Environment.NewLine}{this.GetType().Name}");
4142
using var tempDir = new TemporaryDirectory(Path.Join(FileUtils.GetTemporaryWorkingDirectory(out _), "source-generator"), "source generator temporary", logger);
4243
var analyzerConfigPath = Path.Combine(tempDir.DirInfo.FullName, $"{name}.txt");
4344
var dllPath = Path.Combine(tempDir.DirInfo.FullName, $"{name}.dll");
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
11
| Program.cs |
22
| Views/Home/Index.cshtml |
3-
| _ql_csharp_ql_integration_tests_all_platforms_cshtml_standalone_test_test_Views_Home_Index_cshtml.g.cs |
43
| test-db/working/implicitUsings/GlobalUsings.g.cs |
4+
| test-db/working/razor/EC52D77FE9BF67AD10C5C3F248392316/Microsoft.CodeAnalysis.Razor.Compiler/Microsoft.NET.Sdk.Razor.SourceGenerators.RazorSourceGenerator/[...]_ql_csharp_ql_integration_tests_all_platforms_cshtml_standalone_test_test_Views_Home_Index_cshtml.g.cs |

csharp/ql/integration-tests/all-platforms/cshtml_standalone/Files.ql

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,15 @@ private string getPath(File f) {
44
result = f.getRelativePath() and
55
not exists(result.indexOf("_ql_csharp_ql_integration_tests_all_platforms_cshtml_standalone_"))
66
or
7-
exists(int index |
8-
index =
7+
exists(int index1, int index2, string pattern |
8+
pattern = "Microsoft.NET.Sdk.Razor.SourceGenerators.RazorSourceGenerator" and
9+
index1 = f.getRelativePath().indexOf(pattern) and
10+
index2 =
911
f.getRelativePath()
1012
.indexOf("_ql_csharp_ql_integration_tests_all_platforms_cshtml_standalone_") and
11-
result = f.getRelativePath().substring(index, f.getRelativePath().length())
13+
result =
14+
f.getRelativePath().substring(0, index1 + pattern.length()) + "/[...]" +
15+
f.getRelativePath().substring(index2, f.getRelativePath().length())
1216
)
1317
}
1418

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
1-
| Program.cs |
2-
| test-db/working/implicitUsings/GlobalUsings.g.cs |
1+
| Program.cs:0:0:0:0 | Program.cs |
2+
| test-db/working/implicitUsings/GlobalUsings.g.cs:0:0:0:0 | test-db/working/implicitUsings/GlobalUsings.g.cs |
Lines changed: 1 addition & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,5 @@
11
import csharp
22

3-
private string getPath(File f) {
4-
result = f.getRelativePath() and
5-
not exists(
6-
result
7-
.indexOf("_semmle_code_target_codeql_csharp_integration_tests_ql_csharp_ql_integration_tests_all_platforms_cshtml_standalone_")
8-
)
9-
or
10-
exists(int index |
11-
index =
12-
f.getRelativePath()
13-
.indexOf("_semmle_code_target_codeql_csharp_integration_tests_ql_csharp_ql_integration_tests_all_platforms_cshtml_standalone_") and
14-
result = f.getRelativePath().substring(index, f.getRelativePath().length())
15-
)
16-
}
17-
183
from File f
194
where f.fromSource() or f.getExtension() = "cshtml"
20-
select getPath(f)
5+
select f
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
11
| Program.cs |
22
| Views/Home/Index.cshtml |
3-
| _ql_csharp_ql_integration_tests_all_platforms_cshtml_standalone_net6_test_test_Views_Home_Index_cshtml.g.cs |
43
| test-db/working/implicitUsings/GlobalUsings.g.cs |
4+
| test-db/working/razor/EC52D77FE9BF67AD10C5C3F248392316/Microsoft.NET.Sdk.Razor.SourceGenerators/Microsoft.NET.Sdk.Razor.SourceGenerators.RazorSourceGenerator/[...]_ql_csharp_ql_integration_tests_all_platforms_cshtml_standalone_net6_test_test_Views_Home_Index_cshtml.g.cs |

csharp/ql/integration-tests/all-platforms/cshtml_standalone_net6/Files.ql

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,15 @@ private string getPath(File f) {
44
result = f.getRelativePath() and
55
not exists(result.indexOf("_ql_csharp_ql_integration_tests_all_platforms_cshtml_standalone_"))
66
or
7-
exists(int index |
8-
index =
7+
exists(int index1, int index2, string pattern |
8+
pattern = "Microsoft.NET.Sdk.Razor.SourceGenerators.RazorSourceGenerator" and
9+
index1 = f.getRelativePath().indexOf(pattern) and
10+
index2 =
911
f.getRelativePath()
1012
.indexOf("_ql_csharp_ql_integration_tests_all_platforms_cshtml_standalone_") and
11-
result = f.getRelativePath().substring(index, f.getRelativePath().length())
13+
result =
14+
f.getRelativePath().substring(0, index1 + pattern.length()) + "/[...]" +
15+
f.getRelativePath().substring(index2, f.getRelativePath().length())
1216
)
1317
}
1418

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
1-
| Program.cs |
2-
| test-db/working/implicitUsings/GlobalUsings.g.cs |
3-
| test-db/working/resx/[...]/Microsoft.CodeAnalysis.ResxSourceGenerator.CSharp/Microsoft.CodeAnalysis.ResxSourceGenerator.CSharp.CSharpResxGenerator/test.Designer.cs |
1+
| Program.cs:0:0:0:0 | Program.cs |
2+
| test-db/working/implicitUsings/GlobalUsings.g.cs:0:0:0:0 | test-db/working/implicitUsings/GlobalUsings.g.cs |
3+
| test-db/working/resx/F4FAF6D9E0C1522913E76D38E8CF4F3F/Microsoft.CodeAnalysis.ResxSourceGenerator.CSharp/Microsoft.CodeAnalysis.ResxSourceGenerator.CSharp.CSharpResxGenerator/test.Designer.cs:0:0:0:0 | test-db/working/resx/F4FAF6D9E0C1522913E76D38E8CF4F3F/Microsoft.CodeAnalysis.ResxSourceGenerator.CSharp/Microsoft.CodeAnalysis.ResxSourceGenerator.CSharp.CSharpResxGenerator/test.Designer.cs |
Lines changed: 1 addition & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,5 @@
11
import csharp
22

3-
private string getPath(File f) {
4-
result = f.getRelativePath() and
5-
not exists(
6-
result
7-
.indexOf("Microsoft.CodeAnalysis.ResxSourceGenerator.CSharp/Microsoft.CodeAnalysis.ResxSourceGenerator.CSharp.CSharpResxGenerator")
8-
)
9-
or
10-
exists(int index |
11-
index =
12-
f.getRelativePath()
13-
.indexOf("Microsoft.CodeAnalysis.ResxSourceGenerator.CSharp/Microsoft.CodeAnalysis.ResxSourceGenerator.CSharp.CSharpResxGenerator") and
14-
result =
15-
f.getRelativePath().substring(0, index - 32 - 2) + "/[...]/" +
16-
f.getRelativePath().substring(index, f.getRelativePath().length())
17-
)
18-
}
19-
203
from File f
214
where f.fromSource()
22-
select getPath(f)
5+
select f

0 commit comments

Comments
 (0)