Skip to content

Commit 79d6731

Browse files
committed
C#: Adjust make_stubs.py to use codeql instead of odasa
1 parent fbbec5d commit 79d6731

File tree

1 file changed

+23
-27
lines changed

1 file changed

+23
-27
lines changed

csharp/ql/src/Stubs/make_stubs.py

Lines changed: 23 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -43,12 +43,6 @@
4343
print("Test directory does not contain .cs files. Please specify a working qltest directory.")
4444
exit(1)
4545

46-
cmd = ['odasa', 'selfTest']
47-
print('Running ' + ' '.join(cmd))
48-
if subprocess.check_call(cmd):
49-
print("odasa selfTest failed. Ensure odasa is on your current path.")
50-
exit(1)
51-
5246
csharpQueries = os.path.abspath(os.path.dirname(sys.argv[0]))
5347
outputFile = os.path.join(testDir, 'stubs.cs')
5448

@@ -58,52 +52,54 @@
5852
os.remove(outputFile) # It would interfere with the test.
5953
print("Removed previous", outputFile)
6054

61-
cmd = ['odasa', 'qltest', '--optimize', '--leave-temp-files', testDir]
55+
cmd = ['codeql', 'test', 'run', '--keep-databases', testDir]
6256
print('Running ' + ' '.join(cmd))
6357
if subprocess.check_call(cmd):
64-
print("qltest failed. Please fix up the test before proceeding.")
58+
print("codeql test failed. Please fix up the test before proceeding.")
6559
exit(1)
6660

67-
dbDir = os.path.join(testDir, os.path.basename(testDir) + ".testproj", "db-csharp")
61+
dbDir = os.path.join(testDir, os.path.basename(testDir) + ".testproj")
6862

6963
if not os.path.isdir(dbDir):
70-
print("Expected database directory " + dbDir + " not found. Please contact Semmle.")
64+
print("Expected database directory " + dbDir + " not found.")
7165
exit(1)
7266

73-
cmd = ['odasa', 'runQuery', '--query', os.path.join(csharpQueries, 'MinimalStubsFromSource.ql'), '--db', dbDir, '--output-file', outputFile]
67+
cmd = ['codeql', 'query', 'run', os.path.join(
68+
csharpQueries, 'MinimalStubsFromSource.ql'), '--database', dbDir, '--output', outputFile]
7469
print('Running ' + ' '.join(cmd))
7570
if subprocess.check_call(cmd):
76-
print('Failed to run the query to generate output file. Please contact Semmle.')
71+
print('Failed to run the query to generate output file.')
7772
exit(1)
7873

7974
# Remove the leading " and trailing " bytes from the file
8075
len = os.stat(outputFile).st_size
8176
f = open(outputFile, "rb")
8277
try:
83-
quote = f.read(1)
84-
if quote != b'"':
85-
print("Unexpected character in file. Please contact Semmle.")
86-
contents = f.read(len-3)
87-
quote = f.read(1)
88-
if quote != b'"':
89-
print("Unexpected end character. Please contact Semmle.", quote)
78+
quote = f.read(6)
79+
if quote != b"\x02\x01\x86'\x85'":
80+
print("Unexpected start characters in file.", quote)
81+
contents = f.read(len-21)
82+
quote = f.read(15)
83+
if quote != b'\x0e\x01\x08#select\x01\x01\x00s\x00':
84+
print("Unexpected end character in file.", quote)
9085
finally:
9186
f.close()
9287

9388
f = open(outputFile, "wb")
9489
f.write(contents)
9590
f.close()
9691

97-
cmd = ['odasa', 'qltest', '--optimize', testDir]
92+
cmd = ['codeql', 'test', 'run', testDir]
9893
print('Running ' + ' '.join(cmd))
9994
if subprocess.check_call(cmd):
100-
print('\nTest failed. You may need to fix up', outputFile)
101-
print('It may help to view', outputFile, ' in Visual Studio')
102-
print("Next steps:")
103-
print('1. Look at the compilation errors, and fix up', outputFile, 'so that the test compiles')
104-
print('2. Re-run odasa qltest --optimize "' + testDir + '"')
105-
print('3. git add "' + outputFile + '"')
106-
exit(1)
95+
print('\nTest failed. You may need to fix up', outputFile)
96+
print('It may help to view', outputFile, ' in Visual Studio')
97+
print("Next steps:")
98+
print('1. Look at the compilation errors, and fix up',
99+
outputFile, 'so that the test compiles')
100+
print('2. Re-run codeql test run "' + testDir + '"')
101+
print('3. git add "' + outputFile + '"')
102+
exit(1)
107103

108104
print("\nStub generation successful! Next steps:")
109105
print('1. Edit "semmle-extractor-options" in the .cs files to remove unused references')

0 commit comments

Comments
 (0)