Skip to content

build: Skip configure when no variable has changed #82195

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

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
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
56 changes: 51 additions & 5 deletions utils/build.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -1498,6 +1498,8 @@ function Build-CMakeProject {
if ($CacheScript) {
$cmakeGenerateArgs += @("-C", $CacheScript)
}

$ParsedDefines = @{}
foreach ($Define in ($Defines.GetEnumerator() | Sort-Object Name)) {
# The quoting gets tricky to support defines containing compiler flags args,
# some of which can contain spaces, for example `-D` `Flags=-flag "C:/Program Files"`
Expand All @@ -1524,21 +1526,65 @@ function Build-CMakeProject {
}
}

# Remove the backslashes from the value, as they are not in CMakeCache.txt
$ParsedDefines["$($Define.Key)"] = $Value.Replace("\", "")
$cmakeGenerateArgs += @("-D", "$($Define.Key)=$Value")
}

# Read CMakeCache.txt to see if we need to re-run configure.
$CMakeCacheFile = [IO.Path]::Combine($Bin, "CMakeCache.txt")
$NeedsConfigure = $false
if (Test-Path $CMakeCacheFile) {
$CMakeCacheRaw = Get-Content $CMakeCacheFile -Raw
$CMakeCache = @{}
foreach ($Entry in $CMakeCacheRaw -split "`r?`n") {
if ($Entry -match "^(?<Key>[^:]+):(?<Type>[^=]+)=(?<Value>.*)$") {
$CMakeCache[$matches["Key"]] = $matches["Value"]
}
}

foreach ($Define in $ParsedDefines.GetEnumerator()) {
if ($CMakeCache[$Define.Key] -ne $Define.Value) {
Write-Host "CMake define '$($Define.Key)' changed from '$($CMakeCache[$Define.Key])' to '$($Define.Value)'. Reconfiguring project."
$NeedsConfigure = $true
break
}
}

if (-not $NeedsConfigure) {
# Check if the CMake generator has changed
if ($CMakeCache["CMAKE_GENERATOR"] -ne $Generator) {
Copy link
Contributor

Choose a reason for hiding this comment

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

I do not think this changes, but might want to check it before enumarating/checking the cache entries.

Write-Host "CMake generator changed from '$($CMakeCache["CMAKE_GENERATOR"])' to '$Generator'. Reconfiguring project."
$NeedsConfigure = $true
}
}
} else {
Write-Host "CMake cache file '$CMakeCacheFile' does not exist. Reconfiguring project."
$NeedsConfigure = $true
}

if ($UseBuiltCompilers.Contains("Swift")) {
$env:Path = "$([IO.Path]::Combine((Get-InstallDir $BuildPlatform), "Runtimes", $ProductVersion, "usr", "bin"));$(Get-CMarkBinaryCache $BuildPlatform)\src;$($BuildPlatform.ToolchainInstallRoot)\usr\bin;$(Get-PinnedToolchainRuntime);${env:Path}"
} elseif ($UsePinnedCompilers.Contains("Swift")) {
$env:Path = "$(Get-PinnedToolchainRuntime);${env:Path}"
}
if ($ToBatch) {
Write-Output ""
Write-Output "echo $cmake $cmakeGenerateArgs"

if ($NeedsConfigure) {
if ($ToBatch) {
Write-Output ""
Write-Output "echo $cmake $cmakeGenerateArgs"
} else {
Write-Host "$cmake $cmakeGenerateArgs"
}
Invoke-Program $cmake @cmakeGenerateArgs
} else {
Write-Host "$cmake $cmakeGenerateArgs"
if ($ToBatch) {
Write-Output ""
Write-Output "echo Skipping reconfiguration of '$Src' to '$Bin' as no input changed."
} else {
Write-Host -ForegroundColor Yellow "Skipping reconfiguration of '$Src' to '$Bin' as no input changed."
}
}
Invoke-Program $cmake @cmakeGenerateArgs

# Build all requested targets
foreach ($Target in $BuildTargets) {
Expand Down