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

Skip to content

Commit cda285d

Browse files
committed
Use dotnet format to format the output stub file
1 parent 53655d4 commit cda285d

1 file changed

Lines changed: 32 additions & 15 deletions

File tree

csharp/ql/src/Stubs/make_stubs_nuget.py

Lines changed: 32 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,10 @@
22
import os
33
import helpers
44

5-
6-
print('Script to generate stub.cs file from a nuget package')
7-
print('Usage: python ' + sys.argv[0] +
5+
print('Script to generate stub file from a nuget package')
6+
print(' Usage: python ' + sys.argv[0] +
87
' NUGET_PACKAGE_NAME [VERSION=latest] [WORK_DIR=tempDir] [OUTPUT_NAME=stub]')
8+
print(' The script uses the dotnet cli, codeql cli, and dotnet format global tool')
99

1010
if len(sys.argv) < 2:
1111
print("\nPlease supply a nuget package name.")
@@ -16,35 +16,42 @@
1616
nuget = sys.argv[1]
1717

1818
workDir = os.path.abspath(helpers.get_argv(3, "tempDir"))
19-
projectName = "proj"
20-
projectDir = os.path.join(workDir, projectName)
19+
projectNameIn = "input"
20+
projectDirIn = os.path.join(workDir, projectNameIn)
21+
22+
projectNameOut = "output"
23+
projectDirOut = os.path.join(workDir, projectNameOut)
2124
dbName = 'db'
2225
dbDir = os.path.join(workDir, dbName)
2326
outputName = helpers.get_argv(4, "stub")
24-
outputFile = os.path.join(workDir, outputName + '.cs')
25-
bqrsFile = os.path.join(workDir, outputName + '.bqrs')
27+
outputFile = os.path.join(projectDirOut, outputName + '.cs')
28+
bqrsFile = os.path.join(projectDirOut, outputName + '.bqrs')
2629
version = helpers.get_argv(2, "latest")
2730

28-
print("\nCreating new project")
31+
print("\n* Creating new input project")
2932
helpers.run_cmd(['dotnet', 'new', 'classlib', "--language", "C#", '--name',
30-
projectName, '--output', projectDir])
33+
projectNameIn, '--output', projectDirIn])
3134

32-
print("\nAdding reference")
33-
cmd = ['dotnet', 'add', projectDir, 'package', nuget]
35+
print("\n* Adding reference to package: " + nuget)
36+
cmd = ['dotnet', 'add', projectDirIn, 'package', nuget]
3437
if (version != "latest"):
3538
cmd.append('--version')
3639
cmd.append(version)
3740
helpers.run_cmd(cmd)
3841

39-
print("\nCreating DB")
42+
print("\n* Creating DB")
4043
helpers.run_cmd(['codeql', 'database', 'create', dbDir, '--language=csharp',
41-
'--command', 'dotnet build /t:rebuild ' + projectDir])
44+
'--command', 'dotnet build /t:rebuild ' + projectDirIn])
4245

4346
if not os.path.isdir(dbDir):
4447
print("Expected database directory " + dbDir + " not found.")
4548
exit(1)
4649

47-
print("\nRunning query")
50+
print("\n* Creating new output project")
51+
helpers.run_cmd(['dotnet', 'new', 'classlib', "--language", "C#", '--name',
52+
projectNameOut, '--output', projectDirOut])
53+
54+
print("\n* Running stubbing CodeQL query")
4855
helpers.run_cmd(['codeql', 'query', 'run', os.path.join(
4956
thisDir, 'AllStubsFromReference.ql'), '--database', dbDir, '--output', bqrsFile])
5057

@@ -53,5 +60,15 @@
5360

5461
helpers.trim_output_file(outputFile)
5562

56-
print("\nOutput: " + outputFile)
63+
print("\n --> Generated output file: " + outputFile)
64+
65+
print("\n* Formatting file")
66+
helpers.run_cmd(['dotnet', 'format', projectDirOut,
67+
'--include', outputName + '.cs'])
68+
69+
print("\n* Building output project")
70+
helpers.run_cmd(['dotnet', 'build', '/t:rebuild', projectDirOut],
71+
'ERR: Build failed. Script failed to generate a stub that builds')
72+
73+
print("\n --> Generated output file: " + outputFile)
5774
exit(0)

0 commit comments

Comments
 (0)