@@ -17,7 +17,7 @@ def write_csproj_prefix(ioWrapper):
17
17
18
18
19
19
print ('Script to generate stub file from a nuget package' )
20
- print (' Usage: python ' + sys .argv [0 ] +
20
+ print (' Usage: python3 ' + sys .argv [0 ] +
21
21
' NUGET_PACKAGE_NAME [VERSION=latest] [WORK_DIR=tempDir]' )
22
22
print (' The script uses the dotnet cli, codeql cli, and dotnet format global tool' )
23
23
@@ -34,6 +34,9 @@ def write_csproj_prefix(ioWrapper):
34
34
projectNameIn = "input"
35
35
projectDirIn = os .path .join (workDir , projectNameIn )
36
36
37
+ def run_cmd (cmd , msg = "Failed to run command" ):
38
+ helpers .run_cmd_cwd (cmd , workDir , msg )
39
+
37
40
# /output contains the output of the stub generation
38
41
outputDirName = "output"
39
42
outputDir = os .path .join (workDir , outputDirName )
@@ -57,7 +60,7 @@ def write_csproj_prefix(ioWrapper):
57
60
version = helpers .get_argv (2 , "latest" )
58
61
59
62
print ("\n * Creating new input project" )
60
- helpers . run_cmd (['dotnet' , 'new' , 'classlib' , "--language" , "C#" , '--name' ,
63
+ run_cmd (['dotnet' , 'new' , 'classlib' , "-f" , "net5.0" , "--language" , "C#" , '--name' ,
61
64
projectNameIn , '--output' , projectDirIn ])
62
65
helpers .remove_files (projectDirIn , '.cs' )
63
66
@@ -66,27 +69,31 @@ def write_csproj_prefix(ioWrapper):
66
69
if (version != "latest" ):
67
70
cmd .append ('--version' )
68
71
cmd .append (version )
69
- helpers .run_cmd (cmd )
72
+ run_cmd (cmd )
73
+
74
+ sdk_version = '5.0.402'
75
+ print ("\n * Creating new global.json file and setting SDK to " + sdk_version )
76
+ run_cmd (['dotnet' , 'new' , 'globaljson' , '--force' , '--sdk-version' , sdk_version , '--output' , workDir ])
70
77
71
78
print ("\n * Creating DB" )
72
- helpers . run_cmd (['codeql' , 'database' , 'create' , dbDir , '--language=csharp' ,
73
- '--command' , 'dotnet build /t:rebuild ' + projectDirIn ])
79
+ run_cmd (['codeql' , 'database' , 'create' , dbDir , '--language=csharp' ,
80
+ '--command' , 'dotnet build /t:rebuild /p:UseSharedCompilation=false ' + projectDirIn ])
74
81
75
82
if not os .path .isdir (dbDir ):
76
83
print ("Expected database directory " + dbDir + " not found." )
77
84
exit (1 )
78
85
79
86
print ("\n * Running stubbing CodeQL query" )
80
- helpers . run_cmd (['codeql' , 'query' , 'run' , os .path .join (
87
+ run_cmd (['codeql' , 'query' , 'run' , os .path .join (
81
88
thisDir , 'AllStubsFromReference.ql' ), '--database' , dbDir , '--output' , bqrsFile ])
82
89
83
- helpers . run_cmd (['codeql' , 'bqrs' , 'decode' , bqrsFile , '--output' ,
90
+ run_cmd (['codeql' , 'bqrs' , 'decode' , bqrsFile , '--output' ,
84
91
jsonFile , '--format=json' ])
85
92
86
93
print ("\n * Creating new raw output project" )
87
94
rawSrcOutputDirName = 'src'
88
95
rawSrcOutputDir = os .path .join (rawOutputDir , rawSrcOutputDirName )
89
- helpers . run_cmd (['dotnet' , 'new' , 'classlib' , "--language" , "C#" ,
96
+ run_cmd (['dotnet' , 'new' , 'classlib' , "--language" , "C#" ,
90
97
'--name' , rawSrcOutputDirName , '--output' , rawSrcOutputDir ])
91
98
helpers .remove_files (rawSrcOutputDir , '.cs' )
92
99
@@ -102,7 +109,7 @@ def write_csproj_prefix(ioWrapper):
102
109
print ("\n --> Generated stub files: " + rawSrcOutputDir )
103
110
104
111
print ("\n * Formatting files" )
105
- helpers . run_cmd (['dotnet' , 'format' , rawSrcOutputDir ])
112
+ run_cmd (['dotnet' , 'format' , rawSrcOutputDir ])
106
113
107
114
print ("\n --> Generated (formatted) stub files: " + rawSrcOutputDir )
108
115
0 commit comments