From 0f3d0851019f3e48765f629525e8bdcfd9b58c24 Mon Sep 17 00:00:00 2001 From: Elias Toivola Date: Thu, 4 Sep 2025 13:22:21 +0300 Subject: [PATCH] Windows: Add a helper to cleanly invoke NMake with zlib Invoke-NMake helper temporarily clears MAKE flags, such as MAKEFLAGS='-j8', to prevent errors from GNU-style flags and to reduce flakiness with NMAKE. The helper is used to build zlib and to prevent: error U1065: invalid option '-' Pick-to: 6.10 6.9 6.8 6.5 Task-number: QTQAINFRA-7363 Change-Id: Ia80216677eba6fd8f8364741b6999e6155d678ab Reviewed-by: Tero Heikkinen --- coin/provisioning/common/windows/helpers.ps1 | 19 +++++++++++++++++++ coin/provisioning/common/windows/zlib.ps1 | 3 +-- 2 files changed, 20 insertions(+), 2 deletions(-) diff --git a/coin/provisioning/common/windows/helpers.ps1 b/coin/provisioning/common/windows/helpers.ps1 index 982c5ee9..35583b3b 100644 --- a/coin/provisioning/common/windows/helpers.ps1 +++ b/coin/provisioning/common/windows/helpers.ps1 @@ -382,3 +382,22 @@ function Invoke-MtCommand { & $Env:SystemRoot\system32\cmd.exe /c $cmdLine | Write-Output Remove-Item $tempFile } + +function Invoke-NMake { + param([string[]]$NmakeArgs) + # Temporarily remove MAKE flags for NMAKE process + $old = @{ + MAKEFLAGS = (Get-Item Env:MAKEFLAGS -ErrorAction Ignore).Value + MFLAGS = (Get-Item Env:MFLAGS -ErrorAction Ignore).Value + MAKE = (Get-Item Env:MAKE -ErrorAction Ignore).Value + NMAKEFLAGS = (Get-Item Env:NMAKEFLAGS -ErrorAction Ignore).Value + } + foreach ($n in $old.Keys) {Remove-Item "Env:$n" -ErrorAction SilentlyContinue} + try {& nmake @NmakeArgs} + finally { + foreach ($n in $old.Keys) { + if ($old[$n]) {Set-EnvironmentVariable -Key "$n" -Value $old[$n]} + else {Remove-Item "Env:$n" -ErrorAction SilentlyContinue} + } + } +} diff --git a/coin/provisioning/common/windows/zlib.ps1 b/coin/provisioning/common/windows/zlib.ps1 index f725f8f6..87c59690 100644 --- a/coin/provisioning/common/windows/zlib.ps1 +++ b/coin/provisioning/common/windows/zlib.ps1 @@ -42,8 +42,7 @@ function BuildZlib { ) PrepareBuildEnvironment -HostArchitecture $HostArchitecture -TargetArchitecture $TargetArchitecture - - nmake /f $MAKEFILE + Invoke-NMake -NmakeArgs @('/f', "$MAKEFILE") } function CopySource {