|
43 | 43 | print("Test directory does not contain .cs files. Please specify a working qltest directory.")
|
44 | 44 | exit(1)
|
45 | 45 |
|
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 |
| - |
52 | 46 | csharpQueries = os.path.abspath(os.path.dirname(sys.argv[0]))
|
53 | 47 | outputFile = os.path.join(testDir, 'stubs.cs')
|
54 | 48 |
|
|
58 | 52 | os.remove(outputFile) # It would interfere with the test.
|
59 | 53 | print("Removed previous", outputFile)
|
60 | 54 |
|
61 |
| -cmd = ['odasa', 'qltest', '--optimize', '--leave-temp-files', testDir] |
| 55 | +cmd = ['codeql', 'test', 'run', '--keep-databases', testDir] |
62 | 56 | print('Running ' + ' '.join(cmd))
|
63 | 57 | 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.") |
65 | 59 | exit(1)
|
66 | 60 |
|
67 |
| -dbDir = os.path.join(testDir, os.path.basename(testDir) + ".testproj", "db-csharp") |
| 61 | +dbDir = os.path.join(testDir, os.path.basename(testDir) + ".testproj") |
68 | 62 |
|
69 | 63 | 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.") |
71 | 65 | exit(1)
|
72 | 66 |
|
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] |
74 | 69 | print('Running ' + ' '.join(cmd))
|
75 | 70 | 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.') |
77 | 72 | exit(1)
|
78 | 73 |
|
79 |
| -# Remove the leading " and trailing " bytes from the file |
80 |
| -len = os.stat(outputFile).st_size |
81 |
| -f = open(outputFile, "rb") |
82 |
| -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) |
90 |
| -finally: |
91 |
| - f.close() |
| 74 | +# Remove the leading and trailing bytes from the file |
| 75 | +length = os.stat(outputFile).st_size |
| 76 | +if length < 20: |
| 77 | + contents = b'' |
| 78 | +else: |
| 79 | + f = open(outputFile, "rb") |
| 80 | + try: |
| 81 | + countTillSlash = 0 |
| 82 | + foundSlash = False |
| 83 | + slash = f.read(1) |
| 84 | + while slash != b'': |
| 85 | + if slash == b'/': |
| 86 | + foundSlash = True |
| 87 | + break |
| 88 | + countTillSlash += 1 |
| 89 | + slash = f.read(1) |
| 90 | + |
| 91 | + if not foundSlash: |
| 92 | + countTillSlash = 0 |
| 93 | + |
| 94 | + f.seek(0) |
| 95 | + quote = f.read(countTillSlash) |
| 96 | + print("Start characters in file skipped.", quote) |
| 97 | + post = b'\x0e\x01\x08#select\x01\x01\x00s\x00' |
| 98 | + contents = f.read(length - len(post) - countTillSlash) |
| 99 | + quote = f.read(len(post)) |
| 100 | + if quote != post: |
| 101 | + print("Unexpected end character in file.", quote) |
| 102 | + finally: |
| 103 | + f.close() |
92 | 104 |
|
93 | 105 | f = open(outputFile, "wb")
|
94 | 106 | f.write(contents)
|
95 | 107 | f.close()
|
96 | 108 |
|
97 |
| -cmd = ['odasa', 'qltest', '--optimize', testDir] |
| 109 | +cmd = ['codeql', 'test', 'run', testDir] |
98 | 110 | print('Running ' + ' '.join(cmd))
|
99 | 111 | 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) |
| 112 | + print('\nTest failed. You may need to fix up', outputFile) |
| 113 | + print('It may help to view', outputFile, ' in Visual Studio') |
| 114 | + print("Next steps:") |
| 115 | + print('1. Look at the compilation errors, and fix up', |
| 116 | + outputFile, 'so that the test compiles') |
| 117 | + print('2. Re-run codeql test run "' + testDir + '"') |
| 118 | + print('3. git add "' + outputFile + '"') |
| 119 | + exit(1) |
107 | 120 |
|
108 | 121 | print("\nStub generation successful! Next steps:")
|
109 | 122 | print('1. Edit "semmle-extractor-options" in the .cs files to remove unused references')
|
110 |
| -print('2. Re-run odasa qltest --optimize "' + testDir + '"') |
| 123 | +print('2. Re-run codeql test run "' + testDir + '"') |
111 | 124 | print('3. git add "' + outputFile + '"')
|
112 | 125 | print('4. Commit your changes.')
|
113 | 126 |
|
|
0 commit comments