-
Notifications
You must be signed in to change notification settings - Fork 396
Adding script to generate compile commands database #5883
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from 28 commits
9ab36b7
3d8dc83
8323d8f
f6908a3
fc32011
0f23f7f
f215bdd
061dbcd
00f9789
a3befce
e2ed1bb
1c0141c
213caaf
eb97073
c3cddcb
46c9ca6
93df0d8
5d24606
4a0ad1d
0d6b13f
5ecd1b2
221f460
7aa3f44
c3b1f8e
b7e9fe9
fcb6344
649a900
28c7dd2
472d62d
53ea440
f63dbf3
37f8e52
f2cb8e3
b196ba3
6da3435
119b742
331fa32
04a0b16
1a2ab6a
695a614
728d2dd
d465a4e
acfe357
028635c
4cffe83
5d136de
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,122 @@ | ||
| Param( | ||
guimafelipe marked this conversation as resolved.
Show resolved
Hide resolved
guimafelipe marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| [string]$Ms2ccVersion = "1.3.0" | ||
| ) | ||
|
|
||
| $binlogFileBase = Split-Path $PSScriptRoot -parent | ||
| $binlogFile0 = Join-Path $binlogFileBase "BuildOutput\Binlogs\MrtCore.x64.Release.binlog" | ||
| $binlogFile1 = Join-Path $binlogFileBase "BuildOutput\Binlogs\WindowsAppRuntime.x64.Release.binlog" | ||
|
|
||
| $binlogFiles = @($binlogFile0, $binlogFile1) | ||
|
|
||
| $VCToolsInstallDir = . "${env:ProgramFiles(x86)}\Microsoft Visual Studio\Installer\vswhere.exe" -Latest -prerelease -requires Microsoft.Component.MSBuild -property InstallationPath | ||
| write-host "VCToolsInstallDir: $VCToolsInstallDir" | ||
guimafelipe marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
guimafelipe marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
guimafelipe marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
|
|
||
| $msBuildPath = "$VCToolsInstallDir\MSBuild\Current\Bin\msbuild.exe" | ||
| write-host "msBuildPath: $msBuildPath" | ||
guimafelipe marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
|
|
||
| Remove-Item "temp-filtered.log" -ErrorAction SilentlyContinue | ||
guimafelipe marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| Remove-Item "temp-filtered2.log" -ErrorAction SilentlyContinue | ||
|
|
||
| # Target "ClCompile" in file "C:\Program Files\Microsoft Visual Studio\2022\Enterprise\MSBuild\Microsoft\VC\v170\Microsoft.CppCommon.targets" from project "C:\WindowsAppSDK\dev\Detours\Detours.vcxproj" (target "_ClCompile" depends on it): | ||
guimafelipe marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| # Context here would be: "C:\WindowsAppSDK\dev\Detours" | ||
|
|
||
| foreach ($binlogFile in $binlogFiles) { | ||
guimafelipe marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| if (-Not (Test-Path $binlogFile)) { | ||
| Write-Error "Binlog file not found: $binlogFile" | ||
| exit 1 | ||
| } | ||
|
|
||
| & $msBuildPath $binlogFile /v:normal /noconlog /flp:logfile=temp.log | ||
guimafelipe marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
|
|
||
| Select-String -Path "temp.log" -Pattern "Target ""ClCompile"" in file","Cl.exe" | | ||
| ForEach-Object { $_.Line } | | ||
| Where-Object { $_ -notmatch "Tracker.exe" } | | ||
| Out-File -FilePath "temp-filtered.log" -Append -Encoding utf8 | ||
|
|
||
| Remove-Item "temp.log" | ||
guimafelipe marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| } | ||
|
|
||
| Write-Host "Filtered log file generated at: $(Get-Location)\temp-filtered.log" | ||
guimafelipe marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
|
|
||
| $contextPath = "" | ||
|
|
||
| # for each line in temp-filtered.log, if it is a "Target " line, extract the project directory and save in the contextPath variable | ||
| # if it is a "Cl.exe" line, prepend the contextPath to every source file in that line only if it is | ||
| # a relative path, then output the modified line to temp-filtered-2.log | ||
| # The source files are the arguments that ends with .cpp, .c, or .h | ||
| # They can have spaces in them. If so, they are enclosed in quotes. | ||
|
|
||
| $lines = Get-Content "temp-filtered.log" | ||
|
|
||
| foreach ($line in $lines) { | ||
| if ($line -match 'Target "ClCompile" in file "([^"]+)" from project "([^"]+)"') { | ||
| $contextPath = Split-Path $matches[2] -parent | ||
| Write-Host "Context path set to: $contextPath" | ||
| } elseif ($line -match 'Cl\.exe (.+)$') { | ||
|
||
| $clLine = $matches[1] | ||
| $args = $clLine -split ' (?=(?:[^"]*"[^"]*")*[^"]*$)' | ||
|
||
|
|
||
| $modifiedArgs = @() | ||
| foreach ($arg in $args) { | ||
| if ($arg -match '^(.*\.(cpp|c|h))$' -or $arg -match '^"(.*\.(cpp|c|h))"$') { | ||
guimafelipe marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| $filePath = $arg.Trim('"') | ||
| if (-Not ([System.IO.Path]::IsPathRooted($filePath))) { | ||
| $filePath = Join-Path $contextPath $filePath | ||
| } | ||
| if ($arg.StartsWith('"') -and $arg.EndsWith('"')) { | ||
| $modifiedArgs += '"' + $filePath + '"' | ||
| } else { | ||
| $modifiedArgs += $filePath | ||
| } | ||
| } else { | ||
| $modifiedArgs += $arg | ||
| } | ||
| } | ||
|
|
||
| $modifiedLine = "Cl.exe " + ($modifiedArgs -join ' ') | ||
| Add-Content -Path "temp-filtered2.log" -Value $modifiedLine | ||
| # Write-Host "Processed Cl.exe line: $modifiedLine" | ||
| } | ||
| } | ||
|
|
||
| $ms2ccPath = Join-Path $PSScriptRoot "ms2cc" | ||
| $ms2ccExe = Join-Path $ms2ccPath "ms2cc.exe" | ||
|
|
||
| if (-Not (Test-Path $ms2ccExe)) { | ||
| Write-Host "Downloading ms2cc..." | ||
| $ms2ccUrl = "https://github.com/freddiehaddad/ms2cc/releases/download/v$Ms2ccVersion/ms2cc-$Ms2ccVersion.zip" | ||
guimafelipe marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| $zipPath = Join-Path $PSScriptRoot "ms2cc-$Ms2ccVersion.zip" | ||
guimafelipe marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
|
|
||
| try { | ||
| Invoke-WebRequest -Uri $ms2ccUrl -OutFile $zipPath -UseBasicParsing | ||
|
||
| Write-Host "Downloaded ms2cc to: $zipPath" | ||
|
|
||
| if (-Not (Test-Path $ms2ccPath)) { | ||
| New-Item -ItemType Directory -Path $ms2ccPath -Force | Out-Null | ||
| } | ||
|
|
||
| Expand-Archive -Path $zipPath -DestinationPath $ms2ccPath -Force | ||
| Write-Host "Extracted ms2cc to: $ms2ccPath" | ||
|
|
||
| Remove-Item $zipPath -Force | ||
| Write-Host "Cleaned up zip file" | ||
guimafelipe marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
|
|
||
| if (Test-Path $ms2ccExe) { | ||
| Write-Host "ms2cc successfully downloaded and extracted" | ||
| } else { | ||
| Write-Error "Failed to extract ms2cc.exe" | ||
| exit 1 | ||
| } | ||
| } | ||
| catch { | ||
| Write-Error "Failed to download or extract ms2cc: $_" | ||
| exit 1 | ||
| } | ||
| } else { | ||
| Write-Host "ms2cc already exists at: $ms2ccExe" | ||
| } | ||
|
|
||
| & $ms2ccExe -i "temp-filtered2.log" -d (Split-Path $PSScriptRoot -parent) -p | ||
guimafelipe marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
|
|
||
| # Remove-Item "temp-filtered.log" | ||
| # Remove-Item "temp-filtered2.log" | ||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
or just this, and have pipelines supply $CleanIntermediateFiles = $true.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I implemented this change in all the calls of
BuildAll.ps1in the pipeline. Let me know what you think about it. Maybe the standard can be for the variable to be true so we don't need to change all these calls.