-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathRunCodeQL.bat
More file actions
83 lines (80 loc) · 3.57 KB
/
RunCodeQL.bat
File metadata and controls
83 lines (80 loc) · 3.57 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
::
:: Revision: V1.3
::
:: Copyright (c) 2021 OSR Open Systems Resources, Inc.
::
:: Licensed under the Apache License, Version 2.0 (the "License");
:: you may not use this file except in compliance with the License.
:: You may obtain a copy of the License at
::
:: http://www.apache.org/licenses/LICENSE-2.0
::
:: Unless required by applicable law or agreed to in writing, software
:: distributed under the License is distributed on an "AS IS" BASIS,
:: WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
:: See the License for the specific language governing permissions and
:: limitations under the License.
::
:: RunCodeQL.bat -- Runs CodeQL on the current project
:: Can be run as a post-build step for a project from VS
:: or can be run from the command line... if you want to provide
:: all the required parameters.
::
:: RunCodeQL.bat <FQP_base_project_dir> <FQP_to_project_file_to_Build> <name_of_project> <target> <configuration> <query_set>
::
:: - <target> target defaults to "x64"
:: - <configuration> defaults to "Debug"
:: - <query_set> defaults to "windows_driver_recommended"
::
:: Examples:
:: Command Line:
:: RunCodeQL.bat "F:\_Work\OsrFlt\" "F:\_Work\OsrFlt\OsrFlt\OsrFlt.vcxproj" "OsrFlt" "x64" "Debug" "cpp-security-and-quality"
::
:: Post Build:
:: call <your_directory>RunCodeQL.bat "$(solutionDir)" "$(MSBuildProjectFullPath)" "$(ProjectName)" "$(PlatformTarget)" "$(ConfigurationName)" "cpp-security-and-quality"
::
:: After running CodeQL, the SARIF file containing your results will be in the
:: databases sub-directory of your CodeQL "home" directory (for example,
:: C:\codeql-home\databases\). The name of the file will be the name of your
:: project. If you're using the VS add-in to interpret the SARIF file, simply
:: drag the SARIF file and drop it into your VS instance.
::
:: >>>> Set the following to your CodeQL "home" directory:
::
set CodeQLHome=C:\codeql-home
::
set SolutionDir=%~d1%~p1
set SolutionFQPath=%~2
set ProjectName=%~3
set PlatformTarget=%~4
IF "%PlatformTarget%" NEQ "" goto PLATFORM-SPECIFIED
set PlatformTarget=x64
:PLATFORM-SPECIFIED
set Configuration=%~5
IF "%Configuration%" NEQ "" goto CONFIG-SPECIFIED
set Configuration=Debug
:CONFIG-SPECIFIED
set QuerySet=%~6
IF "%QuerySet%" NEQ "" goto QUERY-SPECIFIED
set QuerySet="windows_driver_recommended"
:QUERY-SPECIFIED
set CodeQLBuildDir="%SolutionDir%CodeQL"
echo on
IF EXIST "%SolutionDir%CodeQL.dat" GOTO MUST-BE-RECURSIVE
echo ---- NOT RECURSIVE, creating marker file
echo working >> "%SolutionDir%CodeQL.dat"
echo -------------- PostBuild2: %0 %1 %2 %3 %4 %5
echo -- attempting to delete %CodeQLHome%\databases\%ProjectName%
rmdir /s/q %CodeQLHome%\databases\%ProjectName%
echo -- Proceding with the CodeQL build step --
CALL %CodeQLHome%\codeql\codeql.cmd database create -l=cpp -s=%SolutionDir% -c "msbuild /t:rebuild /p:IntDir=%CodeQLBuildDir%\intermediate\;OutDir=%CodeQLBuildDir%\;Configuration=%Configuration%;Platform=%PlatformTarget% "%SolutionFQPath%" /p:UseSharedCompilation=false" "%CodeQLHome%\databases\%ProjectName%" -j 0
echo -- Proceding with the CodeQL analyze step --
CALL %CodeQLHome%\codeql\codeql.cmd database analyze "%CodeQLHome%\databases\%ProjectName%" %QuerySet%.qls --format=sarifv2.1.0 --output="%CodeQLHome%\databases\%ProjectName%.sarif" -j 0
del "%SolutionDir%CodeQL.dat"
::echo -- Proceding with the viewing results from %CodeQLHome%\databases\%ProjectName%.sarif --
::CALL devenv /edit %CodeQLHome%\databases\%ProjectName%.sarif
GOTO END
:MUST-BE-RECURSIVE
ECHO ---------- Recursive invocation... skipping CodeQL invocation
:END
set ERRORLEVEL=0