Skip to content

Commit 35d5fc8

Browse files
author
Timothy Mothra Lee (from Dev Box)
committed
refactor
1 parent 1ecdd70 commit 35d5fc8

File tree

1 file changed

+9
-52
lines changed

1 file changed

+9
-52
lines changed

.github/workflows/codeql-daily.yml

Lines changed: 9 additions & 52 deletions
Original file line numberDiff line numberDiff line change
@@ -80,69 +80,34 @@ jobs:
8080
debug: true
8181

8282
- name: Build C++ code
83-
shell: pwsh
84-
id: build-cpp
83+
shell: cmd
8584
run: |
86-
# Use vswhere to find the path to the latest installed Visual Studio Build Tools
87-
$vsPath = & "${env:ProgramFiles(x86)}\Microsoft Visual Studio\Installer\vswhere.exe" -latest -products * -requires Microsoft.VisualStudio.Component.VC.Tools.x86.x64 -property installationPath
88-
if (-not $vsPath) {
89-
Write-Host "Could not find Visual Studio Build Tools installation."
90-
exit 1
91-
}
92-
$vcvarsPath = Join-Path $vsPath 'VC\Auxiliary\Build\vcvars64.bat'
93-
if (-not (Test-Path $vcvarsPath)) {
94-
Write-Host "Could not find vcvars64.bat at $vcvarsPath"
95-
exit 1
96-
}
97-
98-
REM Prepare the build script as a string
99-
$buildScript = @'
100-
REM Set required environment variables
101-
set APPINSIGHTS_WIN10_SDK_PATH="C:\Program Files (x86)\Windows Kits\10"
102-
set APPINSIGHTS_VS_PATH=%VsInstallRoot%
85+
"%ProgramFiles(x86)%\Microsoft Visual Studio\Installer\vswhere.exe" -latest -products * -requires Microsoft.VisualStudio.Component.VC.Tools.x86.x64 -property installationPath > vs.txt
86+
set /p VSPATH=<vs.txt
87+
set VCVARS=%VSPATH%\VC\Auxiliary\Build\vcvars64.bat
88+
call "%VCVARS%"
89+
set APPINSIGHTS_WIN10_SDK_PATH=C:\Program Files (x86)\Windows Kits\10
90+
set APPINSIGHTS_VS_PATH=%VSPATH%
10391
set JAVA_HOME=%JAVA_HOME_17_X64%
104-
10592
set sourceDir=etw/native/src/main/cpp
10693
set headerDir=etw/native/src/main/headers
10794
set cppFile=%sourceDir%/etw_provider.cpp
108-
10995
echo Analyzing C++ file: %cppFile%
110-
111-
REM Create compile_commands.json for CodeQL to use
11296
echo [ > compile_commands.json
11397
echo { >> compile_commands.json
11498
echo "directory": "%CD%/%sourceDir%", >> compile_commands.json
11599
echo "command": "cl.exe /W4 /EHsc /sdl /std:c++14 /I\"%APPINSIGHTS_WIN10_SDK_PATH%/include/10.0.22621.0/um\" /I\"%JAVA_HOME%/include\" /I\"%JAVA_HOME%/include/win32\" /I\"%CD%/%headerDir%\" /c %cppFile%", >> compile_commands.json
116100
echo "file": "%cppFile%" >> compile_commands.json
117101
echo } >> compile_commands.json
118102
echo ] >> compile_commands.json
119-
120-
REM Create a simple C++ file in the same directory to ensure the compiler is called
121103
echo // Simple file to ensure compiler is run > codeql_trigger.cpp
122-
echo #include <windows.h> >> codeql_trigger.cpp
123-
echo #include <jni.h> >> codeql_trigger.cpp
104+
echo #include ^<windows.h^> >> codeql_trigger.cpp
105+
echo #include ^<jni.h^> >> codeql_trigger.cpp
124106
echo #include "etw_provider.h" >> codeql_trigger.cpp
125107
echo int main() { return 0; } >> codeql_trigger.cpp
126-
127-
REM Use a try/catch block to handle errors without failing the job
128-
REM (not available in batch, so use errorlevel)
129-
REM List files for debugging
130-
echo C++ files that will be analyzed:
131108
dir %sourceDir% /s /b *.cpp
132109
dir %headerDir% /s /b *.h
133-
134-
REM Try a minimal compile to help CodeQL recognize the files
135-
echo Running minimal compile...
136-
echo Using JAVA_HOME: %JAVA_HOME%
137-
if exist %JAVA_HOME%/include (
138-
echo JNI include path exists: %JAVA_HOME%/include
139-
) else (
140-
echo WARNING: JNI include path doesn't exist: %JAVA_HOME%/include
141-
)
142-
143-
REM Compile with explicit include paths
144110
cl.exe /c codeql_trigger.cpp /I"%headerDir%" /I"%sourceDir%" /I"%JAVA_HOME%/include" /I"%JAVA_HOME%/include/win32" /EHsc
145-
146111
if %errorlevel%==0 (
147112
echo C++ preparation completed successfully
148113
echo CPP_BUILD_SUCCEEDED=true>>%GITHUB_ENV%
@@ -151,14 +116,6 @@ jobs:
151116
echo Proceeding with CodeQL analysis anyway
152117
echo CPP_BUILD_SUCCEEDED=false>>%GITHUB_ENV%
153118
)
154-
'@
155-
156-
REM Write the batch script to a file
157-
$batchFile = 'run-cpp-build.bat'
158-
Set-Content -Path $batchFile -Value $buildScript -NoNewline
159-
160-
REM Call vcvars64.bat and then the batch file (fix quoting for spaces)
161-
& cmd /c "`"$vcvarsPath`" && $batchFile"
162119
163120
- name: Perform CodeQL analysis
164121
uses: github/codeql-action/analyze@v3

0 commit comments

Comments
 (0)