Skip to content
Open
Show file tree
Hide file tree
Changes from 28 commits
Commits
Show all changes
46 commits
Select commit Hold shift + click to select a range
9ab36b7
Initial script
guimafelipe Sep 30, 2025
3d8dc83
Downloading ms2cc
guimafelipe Sep 30, 2025
8323d8f
Adding compile commands database to git ignore
guimafelipe Sep 30, 2025
f6908a3
Changing name of temporary log files
guimafelipe Sep 30, 2025
fc32011
Adding ms2cc to git ignore
guimafelipe Sep 30, 2025
0f23f7f
Adding current build file directory to files included in test projects
guimafelipe Oct 1, 2025
f215bdd
Adding 2
guimafelipe Oct 1, 2025
061dbcd
Bumping version of ms2cc
guimafelipe Oct 1, 2025
00f9789
Using specific path for almost all includes in the project
guimafelipe Oct 1, 2025
a3befce
Not cleaning intermediate files if building local
guimafelipe Oct 1, 2025
e2ed1bb
Fixing include path on everything
guimafelipe Oct 1, 2025
1c0141c
Using both bin logs
guimafelipe Oct 1, 2025
213caaf
Testing eol
guimafelipe Oct 1, 2025
eb97073
Testing eol 2
guimafelipe Oct 1, 2025
c3cddcb
Revert "Testing eol 2"
guimafelipe Oct 1, 2025
46c9ca6
Revert "Testing eol"
guimafelipe Oct 1, 2025
93df0d8
Testing eol 3
guimafelipe Oct 1, 2025
5d24606
Fixing EOF on test vcxproj files
guimafelipe Oct 1, 2025
4a0ad1d
Fixing missing test files
guimafelipe Oct 1, 2025
0d6b13f
Revert "Fixing missing test files"
guimafelipe Oct 1, 2025
5ecd1b2
Revert "Fixing EOF on test vcxproj files"
guimafelipe Oct 1, 2025
221f460
Revert "Testing eol 3"
guimafelipe Oct 1, 2025
7aa3f44
Revert "Fixing include path on everything"
guimafelipe Oct 1, 2025
c3b1f8e
Revert "Using specific path for almost all includes in the project"
guimafelipe Oct 1, 2025
b7e9fe9
Revert "Adding 2"
guimafelipe Oct 1, 2025
fcb6344
Revert "Adding current build file directory to files included in test…
guimafelipe Oct 1, 2025
649a900
Regex magic
guimafelipe Oct 1, 2025
28c7dd2
Small changes on build all ps1
guimafelipe Oct 1, 2025
472d62d
adding suggestion
guimafelipe Oct 3, 2025
53ea440
Adding CleanIntermediateFiles argument to BuildAll.ps1 script
guimafelipe Oct 3, 2025
f63dbf3
Improving binlog file discovering
guimafelipe Oct 3, 2025
37f8e52
Removing temporary files
guimafelipe Oct 3, 2025
f2cb8e3
Adding more logging
guimafelipe Oct 3, 2025
b196ba3
Merge branch 'main' into user/felipeda/compiledb2
guimafelipe Oct 4, 2025
6da3435
Fixing delete intermediate files
guimafelipe Oct 4, 2025
119b742
Adding update functionality to script
guimafelipe Oct 4, 2025
331fa32
Adding documentation
guimafelipe Oct 7, 2025
04a0b16
Fixing casing and identation
guimafelipe Oct 7, 2025
1a2ab6a
Fixing open braces
guimafelipe Oct 7, 2025
695a614
Adding .hpp
guimafelipe Oct 7, 2025
728d2dd
Adding opt in to download ms2cc or using existing path
guimafelipe Oct 7, 2025
d465a4e
Removing ms2cc from gitignore
guimafelipe Oct 7, 2025
acfe357
Adding hpp part 2
guimafelipe Oct 7, 2025
028635c
Changing most of the not important logging to verbose
guimafelipe Oct 7, 2025
4cffe83
Adding absolute path fix to precompiled header
guimafelipe Oct 14, 2025
5d136de
Moving context path include to front
guimafelipe Oct 14, 2025
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -395,3 +395,9 @@ build/override/
# WindowsAppSDK specific files
Microsoft.WinUI.AppX.targets
!dev/vsix/**/*.pubxml

# Compile commands database for clang-based tools
compile_commands.json

# MS2CC files used to generate compile commands database
tools/ms2cc/**
16 changes: 12 additions & 4 deletions BuildAll.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,8 @@ Param(
[string]$OutputDirectory = (Split-Path $MyInvocation.MyCommand.Path) + "\BuildOutput",
[string]$PGOBuildMode = "Optimize",
[string]$UpdateVersionDetailsPath = $null,
[switch]$Clean = $false
[switch]$Clean = $false,
[switch]$CleanIntermmediateFiles = $false
)

Set-StrictMode -Version 3.0
Expand Down Expand Up @@ -146,7 +147,7 @@ Try {
{
$destinationPaths = Get-Childitem -Path 'packages' -File 'Traceloggingconfig.h' -Recurse

if (($destinationPaths -ne $null))
if (($destinationPaths -ne $null))
{
foreach ($destPath in $destinationPaths) {
Write-Host 'SourcePath:' $srcPath.FullName
Expand All @@ -165,6 +166,13 @@ Try {
# PreFastSetup intentionally skips the call to MSBuild.exe below.
if (($AzureBuildStep -eq "all") -Or ($AzureBuildStep -eq "BuildFoundation"))
{
if ($WindowsAppSDKBuildPipeline -eq 1)
{
$CleanIntermediateFiles = $true
}

$cleanIntermediateFilesArg = if ($CleanIntermediateFiles) { "/p:WindowsAppSDKCleanIntermediateFiles=true" } else { "" }

Copy link
Member

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.

Suggested change
if ($WindowsAppSDKBuildPipeline -eq 1)
{
$CleanIntermediateFiles = $true
}
$cleanIntermediateFilesArg = if ($CleanIntermediateFiles) { "/p:WindowsAppSDKCleanIntermediateFiles=true" } else { "" }
if ($CleanIntermediateFiles -eq $true)
{
$cleanIntermediateFilesArg = "/p:WindowsAppSDKCleanIntermediateFiles=true"
}

Copy link
Contributor Author

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.

foreach($configurationToRun in $configuration.Split(","))
{
foreach($platformToRun in $platform.Split(","))
Expand All @@ -178,7 +186,7 @@ Try {
/binaryLogger:"BuildOutput/binlogs/WindowsAppRuntime.$platformToRun.$configurationToRun.binlog" `
$WindowsAppSDKVersionProperty `
/p:PGOBuildMode=$PGOBuildMode `
/p:WindowsAppSDKCleanIntermediateFiles=true `
$cleanIntermediateFilesArg `
/p:AppxSymbolPackageEnabled=false `
/p:WindowsAppSDKBuildPipeline=$WindowsAppSDKBuildPipeline
if ($lastexitcode -ne 0)
Expand Down Expand Up @@ -279,7 +287,7 @@ Try {
{
foreach($platformToRun in $platform.Split(","))
{
# TODO: $windowsAppSdkBinariesPath may not be defined. Remove the temp downgrade to 1.0 once this issue has been fixed (b#52130179).
# TODO: $windowsAppSdkBinariesPath may not be defined. Remove the temp downgrade to 1.0 once this issue has been fixed (b#52130179).
Set-StrictMode -Version 1.0
.\build\CopyFilesToStagingDir.ps1 -BuildOutputDir 'BuildOutput' -OverrideDir "$buildOverridePath" -PublishDir "$windowsAppSdkBinariesPath" -NugetDir "$BasePath" -Platform $PlatformToRun -Configuration $ConfigurationToRun
Set-StrictMode -Version 3.0
Expand Down
122 changes: 122 additions & 0 deletions tools/GenerateCompilationDatabase.ps1
Original file line number Diff line number Diff line change
@@ -0,0 +1,122 @@
Param(
[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"

$msBuildPath = "$VCToolsInstallDir\MSBuild\Current\Bin\msbuild.exe"
write-host "msBuildPath: $msBuildPath"

Remove-Item "temp-filtered.log" -ErrorAction SilentlyContinue
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):
# Context here would be: "C:\WindowsAppSDK\dev\Detours"

foreach ($binlogFile in $binlogFiles) {
if (-Not (Test-Path $binlogFile)) {
Write-Error "Binlog file not found: $binlogFile"
exit 1
}

& $msBuildPath $binlogFile /v:normal /noconlog /flp:logfile=temp.log

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"
}

Write-Host "Filtered log file generated at: $(Get-Location)\temp-filtered.log"

$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 (.+)$') {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Are you looking for a line containing cl.exe ...anything...<end-of-line>?
Odd to see looking for that rather than '^.*cl.exe (.+)$' to explicitly match the whole line and not simply ends-with

Also, looking for 'cl.exe .+$' is somewhat risky as it match "c:\foo\cl.exe blahblah" as well as "c:\foo\oracl.exe blahblah" and other false positives. Unlikely, but paranoia's not a bad thing :P Better if you can specify something more explicit e.g. "^.+\\cl\.exe (.+)$"

Copy link
Contributor Author

@guimafelipe guimafelipe Oct 7, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, anything containing cl.exe works. This is just to reduce drastically the amount of lines ms2cc needs to process. If there is an oracl.exe there remaining, it is ok because ms2cc will do a better job parsing it. I could pass the entire log file to it with no problem, but I needed to merge all the log files into one so I took chance to also filter to only the important lines while doing it.

$clLine = $matches[1]
$args = $clLine -split ' (?=(?:[^"]*"[^"]*")*[^"]*$)'
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why not bake this into the regex above?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This was just for organization/reading purposes. I can move it up if it is better.


$modifiedArgs = @()
foreach ($arg in $args) {
if ($arg -match '^(.*\.(cpp|c|h))$' -or $arg -match '^"(.*\.(cpp|c|h))"$') {
$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"
$zipPath = Join-Path $PSScriptRoot "ms2cc-$Ms2ccVersion.zip"

try {
Invoke-WebRequest -Uri $ms2ccUrl -OutFile $zipPath -UseBasicParsing
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

DevCheck uses curl.exe with -L (follow redirects) and -# (show progress)

How's Invoke-WebRequest compare?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Invoke-WebRequest was the default I found for downloading something with powershell. Looking at the documentation, it does not seems to have the same capabilities as the ones you listed for curl.exe. Do you think it is worth changing it to use curl?

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"

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

# Remove-Item "temp-filtered.log"
# Remove-Item "temp-filtered2.log"