Skip to content

Commit 82784b4

Browse files
committed
C#: Add a script for generating stubs for all packages needed for testing.
1 parent 3d012cd commit 82784b4

File tree

2 files changed

+51
-2
lines changed

2 files changed

+51
-2
lines changed

csharp/scripts/stubs/README.md

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# Generate stubs
1+
# Generate stubs for a single NuGet package
22

33
Stubs can be generated from Nuget packages with the `make_stubs_nuget.py` script.
44

@@ -16,4 +16,17 @@ The output stubs are found in the `[DIR]/output/stubs` folder and can be copied
1616
In some more involved cases the output files need to be edited. For example `ServiceStack` has Nuget dependencies, which
1717
are included in the `Microsoft.NETCore.App` framework stub. These dependencies generate empty packages, which can be
1818
removed. The `ProjectReference` entries referencing these removed empty packages also need to be deleted from the
19-
`.csproj` files.
19+
`.csproj` files.
20+
21+
# Generate stubs for all packages needed for tests.
22+
23+
Stubs needed for all C# Code QL tests can be generated by
24+
```
25+
python3 make_stubs_all.py
26+
python3 make_stubs_all.py /Users/tmp/working-dir
27+
```
28+
The script contains a hardcoded list of `packages`. If a new package is needed for test purposes, it should be added to the `packages` list in the script.
29+
30+
The generated stubs require some manual changes before they are compilable.
31+
32+
The output stubs are found in the `[DIR]/output/stubs` folder and can be copied over to `csharp/ql/test/resources/stubs`.
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
import sys
2+
import os
3+
import helpers
4+
import json
5+
import shutil
6+
7+
print('Script to generate stub files for all C# packages relevant for tests.')
8+
print('Please extend the `packages` list in this script to add more packages when relevant.')
9+
print(' Usage: python3 ' + sys.argv[0] + ' ' + '[WORK_DIR=tempDir]')
10+
11+
# List of packages to create stubs for.
12+
packages = [
13+
"Amazon.Lambda.Core",
14+
"Amazon.Lambda.APIGatewayEvents",
15+
"Dapper",
16+
"Newtonsoft.Json",
17+
"NHibernate",
18+
"ServiceStack",
19+
"ServiceStack.OrmLite.SqlServer",
20+
"System.Data.SqlClient",
21+
"System.Data.SQLite",
22+
]
23+
24+
thisScript = sys.argv[0]
25+
template = "webapp"
26+
relativeWorkDir = helpers.get_argv(1, "tempDir")
27+
28+
29+
generator = helpers.Generator(thisScript, relativeWorkDir, template)
30+
31+
for package in packages:
32+
generator.add_nuget(package)
33+
34+
generator.make_stubs()
35+
36+
exit(0)

0 commit comments

Comments
 (0)