From 6605f3b705227bb178171982a87dfe01b7596fa7 Mon Sep 17 00:00:00 2001 From: Bhagirath Mehta Date: Sat, 2 May 2026 00:56:00 -0500 Subject: [PATCH 1/2] Validate custom build props inputs early Reject missing or non-MSBuild custom props inputs before the build starts so callers get an explicit failure instead of a successful build that silently ignores the intended custom SKU settings. Files changed: - build-all.bat - build-tests.cmd - build-win.ps1 - docs/building-custom-SKU.md Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> --- build-all.bat | 38 +++++++++++++++++++++++++++++-------- build-tests.cmd | 38 +++++++++++++++++++++++++++++-------- build-win.ps1 | 12 +++++++++++- docs/building-custom-SKU.md | 2 ++ 4 files changed, 73 insertions(+), 17 deletions(-) diff --git a/build-all.bat b/build-all.bat index 6ab0d4ab0..5b535bc08 100644 --- a/build-all.bat +++ b/build-all.bat @@ -1,9 +1,38 @@ @echo off cd %~dp0 -call tools\gen-version.cmd @setlocal ENABLEEXTENSIONS +set CUSTOM_PROPS= +if not "%~1"=="" ( + if not exist "%~f1" ( + goto custom_props_missing + ) + if /I not "%~x1"==".props" ( + if /I not "%~x1"==".targets" ( + goto custom_props_invalid_type + ) + ) + set CUSTOM_PROPS="/p:ForceImportBeforeCppTargets=%~f1" + echo Using custom properties file for the build: + echo %CUSTOM_PROPS% +) + +goto after_custom_props_validation + +:custom_props_missing +echo ERROR: Custom build input not found: %~1 +echo Pass an existing MSBuild .props or .targets file to ForceImportBeforeCppTargets. +exit /b 1 + +:custom_props_invalid_type +echo ERROR: Custom build input must be an MSBuild .props or .targets file: %~1 +echo Pass the MSBuild import file, not the CONFIG_CUSTOM_H header. +exit /b 1 + +:after_custom_props_validation +call tools\gen-version.cmd + echo Update all public submodules... git -c submodule."lib/modules".update=none submodule update --init --recursive @@ -17,13 +46,6 @@ if NOT EXIST %GTEST_PATH%\CMakeLists.txt ( git clone --depth 1 --branch release-1.12.1 https://github.com/google/googletest %GTEST_PATH% ) -set CUSTOM_PROPS= -if ("%~1"=="") goto skip -set CUSTOM_PROPS="/p:ForceImportBeforeCppTargets=%1" -echo Using custom properties file for the build: -echo %CUSTOM_PROPS% -:skip - if NOT DEFINED SKIP_MD_BUILD ( REM DLL and static /MD build REM Release diff --git a/build-tests.cmd b/build-tests.cmd index b73f18689..e6dc4bf6a 100644 --- a/build-tests.cmd +++ b/build-tests.cmd @@ -1,8 +1,37 @@ @echo off cd %~dp0 -call tools\gen-version.cmd @setlocal ENABLEEXTENSIONS +set CUSTOM_PROPS= +if not "%~3"=="" ( + if not exist "%~f3" ( + goto custom_props_missing + ) + if /I not "%~x3"==".props" ( + if /I not "%~x3"==".targets" ( + goto custom_props_invalid_type + ) + ) + set CUSTOM_PROPS="/p:ForceImportBeforeCppTargets=%~f3" + echo Using custom properties file for the build: + echo %CUSTOM_PROPS% +) + +goto after_custom_props_validation + +:custom_props_missing +echo ERROR: Custom build input not found: %~3 +echo Pass an existing MSBuild .props or .targets file to ForceImportBeforeCppTargets. +exit /b 1 + +:custom_props_invalid_type +echo ERROR: Custom build input must be an MSBuild .props or .targets file: %~3 +echo Pass the MSBuild import file, not the CONFIG_CUSTOM_H header. +exit /b 1 + +:after_custom_props_validation +call tools\gen-version.cmd + if DEFINED GIT_PULL_TOKEN ( rd /s /q lib\modules git clone https://%GIT_PULL_TOKEN%:x-oauth-basic@github.com/microsoft/cpp_client_telemetry_modules.git lib\modules @@ -20,13 +49,6 @@ set PLAT=%1 REM Possible configurations: Release|Debug set CONFIGURATION=%2 -set CUSTOM_PROPS= -if ("%3"=="") goto skip -set CUSTOM_PROPS="/p:ForceImportBeforeCppTargets=%3" -echo Using custom properties file for the build: -echo %CUSTOM_PROPS% -:skip - set MAXCPUCOUNT=%NUMBER_OF_PROCESSORS% set SOLUTION=Solutions\MSTelemetrySDK.sln diff --git a/build-win.ps1 b/build-win.ps1 index 8f4ef80da..3f915f867 100644 --- a/build-win.ps1 +++ b/build-win.ps1 @@ -15,7 +15,17 @@ $cpuCount = $env:NUMBER_OF_PROCESSORS $actualCustomProps = "" if ($customProps -ne "") { - $actualCustomProps = "/p:ForceImportBeforeCppTargets=$customProps" + if (-not (Test-Path -LiteralPath $customProps -PathType Leaf)) { + throw "Custom build input not found: $customProps`nPass an existing MSBuild .props or .targets file to ForceImportBeforeCppTargets." + } + + $customPropsExtension = [System.IO.Path]::GetExtension($customProps) + if ($customPropsExtension -ine ".props" -and $customPropsExtension -ine ".targets") { + throw "Custom build input must be an MSBuild .props or .targets file: $customProps`nPass the MSBuild import file, not the CONFIG_CUSTOM_H header." + } + + $resolvedCustomProps = (Resolve-Path -LiteralPath $customProps).Path + $actualCustomProps = "/p:ForceImportBeforeCppTargets=$resolvedCustomProps" } $coreTargets = @("zlib") diff --git a/docs/building-custom-SKU.md b/docs/building-custom-SKU.md index 5252e5e14..0668fbe3f 100644 --- a/docs/building-custom-SKU.md +++ b/docs/building-custom-SKU.md @@ -44,6 +44,8 @@ build-all.bat %CD%\Solutions\build.compact.props produces a custom compact SDK build. +The argument passed to `build-all.bat` must be an MSBuild `.props` or `.targets` file that sets the required preprocessor definitions. Do not pass the `config-*.h` header directly to `ForceImportBeforeCppTargets`. + How it works: **build.compact.props** - contains the preprocessor definition that is functionally equivalent to From f478d701c73a6d57e36fd217424647152cb257ed Mon Sep 17 00:00:00 2001 From: Bhagirath Mehta Date: Sat, 2 May 2026 16:34:04 -0500 Subject: [PATCH 2/2] Call msbuild directly in build-win.ps1 build-win.ps1 validated custom props paths but still routed msbuild through a single cmd /c string, so paths containing spaces could still break. Invoke msbuild with an argument array instead so ForceImportBeforeCppTargets survives normal Windows path quoting. Files changed: - build-win.ps1 Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> --- build-win.ps1 | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/build-win.ps1 b/build-win.ps1 index 3f915f867..af4004aba 100644 --- a/build-win.ps1 +++ b/build-win.ps1 @@ -143,7 +143,18 @@ foreach ($arch in $archs) { } # Build! - & cmd /c "msbuild $solution /target:$targetStr /p:BuildProjectReferences=true /maxcpucount:$cpuCount /p:Configuration=$actualConfig /p:Platform=$actualArch $actualCustomProps" + $msbuildArgs = @( + $solution + "/target:$targetStr" + "/p:BuildProjectReferences=true" + "/maxcpucount:$cpuCount" + "/p:Configuration=$actualConfig" + "/p:Platform=$actualArch" + ) + if ($actualCustomProps -ne "") { + $msbuildArgs += $actualCustomProps + } + & msbuild @msbuildArgs echo "...Done!" echo ""