mirror of
https://github.com/github/codeql.git
synced 2025-12-21 03:06:31 +01:00
Merge pull request #5453 from tamasvajk/feature/use_codeql_stubs
C#: Adjust make_stubs.py to use codeql instead of odasa
This commit is contained in:
@@ -43,12 +43,6 @@ if not foundCS:
|
|||||||
print("Test directory does not contain .cs files. Please specify a working qltest directory.")
|
print("Test directory does not contain .cs files. Please specify a working qltest directory.")
|
||||||
exit(1)
|
exit(1)
|
||||||
|
|
||||||
cmd = ['odasa', 'selfTest']
|
|
||||||
print('Running ' + ' '.join(cmd))
|
|
||||||
if subprocess.check_call(cmd):
|
|
||||||
print("odasa selfTest failed. Ensure odasa is on your current path.")
|
|
||||||
exit(1)
|
|
||||||
|
|
||||||
csharpQueries = os.path.abspath(os.path.dirname(sys.argv[0]))
|
csharpQueries = os.path.abspath(os.path.dirname(sys.argv[0]))
|
||||||
outputFile = os.path.join(testDir, 'stubs.cs')
|
outputFile = os.path.join(testDir, 'stubs.cs')
|
||||||
|
|
||||||
@@ -58,35 +52,53 @@ if os.path.isfile(outputFile):
|
|||||||
os.remove(outputFile) # It would interfere with the test.
|
os.remove(outputFile) # It would interfere with the test.
|
||||||
print("Removed previous", outputFile)
|
print("Removed previous", outputFile)
|
||||||
|
|
||||||
cmd = ['odasa', 'qltest', '--optimize', '--leave-temp-files', testDir]
|
cmd = ['codeql', 'test', 'run', '--keep-databases', testDir]
|
||||||
print('Running ' + ' '.join(cmd))
|
print('Running ' + ' '.join(cmd))
|
||||||
if subprocess.check_call(cmd):
|
if subprocess.check_call(cmd):
|
||||||
print("qltest failed. Please fix up the test before proceeding.")
|
print("codeql test failed. Please fix up the test before proceeding.")
|
||||||
exit(1)
|
exit(1)
|
||||||
|
|
||||||
dbDir = os.path.join(testDir, os.path.basename(testDir) + ".testproj", "db-csharp")
|
dbDir = os.path.join(testDir, os.path.basename(testDir) + ".testproj")
|
||||||
|
|
||||||
if not os.path.isdir(dbDir):
|
if not os.path.isdir(dbDir):
|
||||||
print("Expected database directory " + dbDir + " not found. Please contact Semmle.")
|
print("Expected database directory " + dbDir + " not found.")
|
||||||
exit(1)
|
exit(1)
|
||||||
|
|
||||||
cmd = ['odasa', 'runQuery', '--query', os.path.join(csharpQueries, 'MinimalStubsFromSource.ql'), '--db', dbDir, '--output-file', outputFile]
|
cmd = ['codeql', 'query', 'run', os.path.join(
|
||||||
|
csharpQueries, 'MinimalStubsFromSource.ql'), '--database', dbDir, '--output', outputFile]
|
||||||
print('Running ' + ' '.join(cmd))
|
print('Running ' + ' '.join(cmd))
|
||||||
if subprocess.check_call(cmd):
|
if subprocess.check_call(cmd):
|
||||||
print('Failed to run the query to generate output file. Please contact Semmle.')
|
print('Failed to run the query to generate output file.')
|
||||||
exit(1)
|
exit(1)
|
||||||
|
|
||||||
# Remove the leading " and trailing " bytes from the file
|
# Remove the leading and trailing bytes from the file
|
||||||
len = os.stat(outputFile).st_size
|
length = os.stat(outputFile).st_size
|
||||||
|
if length < 20:
|
||||||
|
contents = b''
|
||||||
|
else:
|
||||||
f = open(outputFile, "rb")
|
f = open(outputFile, "rb")
|
||||||
try:
|
try:
|
||||||
quote = f.read(1)
|
countTillSlash = 0
|
||||||
if quote != b'"':
|
foundSlash = False
|
||||||
print("Unexpected character in file. Please contact Semmle.")
|
slash = f.read(1)
|
||||||
contents = f.read(len-3)
|
while slash != b'':
|
||||||
quote = f.read(1)
|
if slash == b'/':
|
||||||
if quote != b'"':
|
foundSlash = True
|
||||||
print("Unexpected end character. Please contact Semmle.", quote)
|
break
|
||||||
|
countTillSlash += 1
|
||||||
|
slash = f.read(1)
|
||||||
|
|
||||||
|
if not foundSlash:
|
||||||
|
countTillSlash = 0
|
||||||
|
|
||||||
|
f.seek(0)
|
||||||
|
quote = f.read(countTillSlash)
|
||||||
|
print("Start characters in file skipped.", quote)
|
||||||
|
post = b'\x0e\x01\x08#select\x01\x01\x00s\x00'
|
||||||
|
contents = f.read(length - len(post) - countTillSlash)
|
||||||
|
quote = f.read(len(post))
|
||||||
|
if quote != post:
|
||||||
|
print("Unexpected end character in file.", quote)
|
||||||
finally:
|
finally:
|
||||||
f.close()
|
f.close()
|
||||||
|
|
||||||
@@ -94,20 +106,21 @@ f = open(outputFile, "wb")
|
|||||||
f.write(contents)
|
f.write(contents)
|
||||||
f.close()
|
f.close()
|
||||||
|
|
||||||
cmd = ['odasa', 'qltest', '--optimize', testDir]
|
cmd = ['codeql', 'test', 'run', testDir]
|
||||||
print('Running ' + ' '.join(cmd))
|
print('Running ' + ' '.join(cmd))
|
||||||
if subprocess.check_call(cmd):
|
if subprocess.check_call(cmd):
|
||||||
print('\nTest failed. You may need to fix up', outputFile)
|
print('\nTest failed. You may need to fix up', outputFile)
|
||||||
print('It may help to view', outputFile, ' in Visual Studio')
|
print('It may help to view', outputFile, ' in Visual Studio')
|
||||||
print("Next steps:")
|
print("Next steps:")
|
||||||
print('1. Look at the compilation errors, and fix up', outputFile, 'so that the test compiles')
|
print('1. Look at the compilation errors, and fix up',
|
||||||
print('2. Re-run odasa qltest --optimize "' + testDir + '"')
|
outputFile, 'so that the test compiles')
|
||||||
|
print('2. Re-run codeql test run "' + testDir + '"')
|
||||||
print('3. git add "' + outputFile + '"')
|
print('3. git add "' + outputFile + '"')
|
||||||
exit(1)
|
exit(1)
|
||||||
|
|
||||||
print("\nStub generation successful! Next steps:")
|
print("\nStub generation successful! Next steps:")
|
||||||
print('1. Edit "semmle-extractor-options" in the .cs files to remove unused references')
|
print('1. Edit "semmle-extractor-options" in the .cs files to remove unused references')
|
||||||
print('2. Re-run odasa qltest --optimize "' + testDir + '"')
|
print('2. Re-run codeql test run "' + testDir + '"')
|
||||||
print('3. git add "' + outputFile + '"')
|
print('3. git add "' + outputFile + '"')
|
||||||
print('4. Commit your changes.')
|
print('4. Commit your changes.')
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user