From 55cdad634b421e953075ec4d786a7a7db3083e43 Mon Sep 17 00:00:00 2001 From: Mark Schofield Date: Mon, 3 Nov 2025 22:28:25 -0800 Subject: [PATCH 1/4] Use Get-ChildItem's -LiteralPath when passing user data --- PSCMake/Common/CMake.ps1 | 10 ++++------ 1 file changed, 4 insertions(+), 6 deletions(-) diff --git a/PSCMake/Common/CMake.ps1 b/PSCMake/Common/CMake.ps1 index f45faa4..1729558 100644 --- a/PSCMake/Common/CMake.ps1 +++ b/PSCMake/Common/CMake.ps1 @@ -418,8 +418,8 @@ function FilterExecutableTargets { ) $TargetJsons = $TargetTuplesCodeModel | ForEach-Object { - Join-Path -Path $CodeModelDirectory -ChildPath $_.jsonFile | - Get-Item | + $JsonPath = Join-Path -Path $CodeModelDirectory -ChildPath $_.jsonFile + Get-Item -LiteralPath $JsonPath | Get-Content | ConvertFrom-Json } @@ -450,10 +450,8 @@ function Get-CMakeBuildCodeModel { ) # Since BinaryDirectory may contain characters that are valid for the file-system, but are used by PowerShell's - # wildcard syntax (i.e. '[' and ']'), escape the characters before passing to Get-ChildItem. - $EscapedBinaryDirectory = $BinaryDirectory.Replace('[', '`[').Replace(']', '`]') - - Get-ChildItem -Path (Get-CMakeBuildCodeModelDirectory $EscapedBinaryDirectory) -File -Filter 'codemodel-v2-*' -ErrorAction SilentlyContinue | + # wildcard syntax (i.e. '[' and ']'), specify it as the LiteralPath to Get-ChildItem + Get-ChildItem -LiteralPath (Get-CMakeBuildCodeModelDirectory $BinaryDirectory) -File -Filter 'codemodel-v2-*' -ErrorAction SilentlyContinue | Select-Object -First 1 | Get-Content | ConvertFrom-Json From b874776f91067ea95272409cd4fbb4d1052deaf8 Mon Sep 17 00:00:00 2001 From: Mark Schofield Date: Sat, 8 Nov 2025 21:23:20 -0800 Subject: [PATCH 2/4] Add a preset to ReferenceBuild that uses '[' and ']' --- Tests/Configure-CMakeBuild.Tests.ps1 | 5 ++-- Tests/ReferenceBuild/CMakePresets.json | 39 ++++++++++++++++++-------- 2 files changed, 30 insertions(+), 14 deletions(-) diff --git a/Tests/Configure-CMakeBuild.Tests.ps1 b/Tests/Configure-CMakeBuild.Tests.ps1 index a74ad90..def8693 100644 --- a/Tests/Configure-CMakeBuild.Tests.ps1 +++ b/Tests/Configure-CMakeBuild.Tests.ps1 @@ -80,9 +80,10 @@ Describe 'Configure-CMakeBuild' { Using-Location "$PSScriptRoot/ReferenceBuild" { Configure-CMakeBuild -Preset windows-* - $script:CMakeCalls | Should -HaveCount 2 + $script:CMakeCalls | Should -HaveCount 3 $script:CMakeCalls[0] | Should -Be @('--preset', 'windows-x64') - $script:CMakeCalls[1] | Should -Be @('--preset', 'windows-arm') + $script:CMakeCalls[1] | Should -Be @('--preset', 'windows-x64[asan]') + $script:CMakeCalls[2] | Should -Be @('--preset', 'windows-arm') } } diff --git a/Tests/ReferenceBuild/CMakePresets.json b/Tests/ReferenceBuild/CMakePresets.json index 871a4d7..707a437 100644 --- a/Tests/ReferenceBuild/CMakePresets.json +++ b/Tests/ReferenceBuild/CMakePresets.json @@ -5,7 +5,8 @@ "minor": 21, "patch": 0 }, - "configurePresets": [{ + "configurePresets": [ + { "name": "ninja", "hidden": true, "generator": "Ninja Multi-Config" @@ -30,6 +31,13 @@ }, "environment": {} }, + { + "name": "windows-x64[asan]", + "inherits": "windows-x64", + "cacheVariables": { + "ENABLE_ASAN": "ON" + } + }, { "name": "windows-arm", "inherits": "windows", @@ -43,24 +51,31 @@ "environment": {} } ], - "buildPresets": [{ + "buildPresets": [ + { "name": "windows-x64", "configurePreset": "windows-x64" }, + { + "name": "windows-x64[asan]", + "configurePreset": "windows-x64[asan]" + }, { "name": "windows-arm", "configurePreset": "windows-arm" } ], - "testPresets": [{ - "name": "windows-x64", - "configurePreset": "windows-x64", - "output": { - "outputOnFailure": true - }, - "execution": { - "noTestsAction": "error", - "stopOnFailure": true + "testPresets": [ + { + "name": "windows-x64", + "configurePreset": "windows-x64", + "output": { + "outputOnFailure": true + }, + "execution": { + "noTestsAction": "error", + "stopOnFailure": true + } } - }] + ] } From 3c6184a3f773709713a28e4f83076780acf09c6d Mon Sep 17 00:00:00 2001 From: Mark Schofield Date: Sat, 8 Nov 2025 21:50:59 -0800 Subject: [PATCH 3/4] Use Test-Path's -LiteralPath when passing user data --- PSCMake/PSCMake.psm1 | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/PSCMake/PSCMake.psm1 b/PSCMake/PSCMake.psm1 index 331861b..166cc25 100644 --- a/PSCMake/PSCMake.psm1 +++ b/PSCMake/PSCMake.psm1 @@ -385,8 +385,8 @@ function Build-CMakeBuild { # 5) "Get-CMakeBuildCodeModel" returns $null if ($Configure -or $Fresh -or - (-not (Test-Path -Path $CMakeCacheFile -PathType Leaf)) -or - (-not (Test-Path -Path (Get-CMakeBuildCodeModelDirectory $BinaryDirectory) -PathType Container)) -or + (-not (Test-Path -LiteralPath $CMakeCacheFile -PathType Leaf)) -or + (-not (Test-Path -LiteralPath (Get-CMakeBuildCodeModelDirectory $BinaryDirectory) -PathType Container)) -or (-not ($CodeModel = Get-CMakeBuildCodeModel $BinaryDirectory)) ) { ConfigureCMake -CMake $CMake $CMakePresetsJson $ConfigurePreset -Fresh:$Fresh From 559efa48196cd22c43835605751741a0ea30fc20 Mon Sep 17 00:00:00 2001 From: Mark Schofield Date: Sat, 8 Nov 2025 21:52:34 -0800 Subject: [PATCH 4/4] Add a test for Invoke-CMakeOutput using a preset with [ and ] in --- Tests/Invoke-CMakeOutput.Tests.ps1 | 17 +++++++++++++++-- Tests/ReferenceBuild.ps1 | 6 +++--- 2 files changed, 18 insertions(+), 5 deletions(-) diff --git a/Tests/Invoke-CMakeOutput.Tests.ps1 b/Tests/Invoke-CMakeOutput.Tests.ps1 index c4c3b22..dcd3ed4 100644 --- a/Tests/Invoke-CMakeOutput.Tests.ps1 +++ b/Tests/Invoke-CMakeOutput.Tests.ps1 @@ -7,9 +7,11 @@ BeforeAll { . $PSScriptRoot/TestUtilities.ps1 . $PSScriptRoot/ReferenceBuild.ps1 - $Properties = PrepareReferenceBuild - $CMake = "$env:ProgramFiles/CMake/bin/cmake.exe" + $Properties = PrepareReferenceBuild 'windows-x64' + & $CMake @Properties + + $Properties = PrepareReferenceBuild 'windows-x64[asan]' & $CMake @Properties Import-Module -Force $PSScriptRoot/../PSCMake/PSCMake.psd1 -DisableNameChecking @@ -73,6 +75,17 @@ Describe 'Invoke-CMakeOutput' { } } + It 'Runs an executable in a preset with [ and ]' { + Using-Location "$PSScriptRoot/ReferenceBuild/SubDirectory" { + Invoke-CMakeOutput -preset 'windows-x64[asan]' + + $script:ExecutableCalls | Should -HaveCount 2 + $script:ExecutableCalls[0].Arguments | Should -Be @('--build', '--preset', 'windows-x64[asan]', '--target', 'SubDirectory_Executable') + $script:ExecutableCalls[1].Arguments | Should -BeNullOrEmpty + $script:ExecutableCalls[1].Path | Should -Be @("$PSScriptRoot\ReferenceBuild\__output\windows-x64[asan]\SubDirectory\Debug\SubDirectory_Executable.exe") + } + } + It 'Fails with multiple executable targets in scope' { Using-Location "$PSScriptRoot/ReferenceBuild" { { Invoke-CMakeOutput } | Should -Throw "Multiple executable scoped targets match. Specify a target explicitly: SubDirectoryOther_Executable SubDirectory_Executable" diff --git a/Tests/ReferenceBuild.ps1 b/Tests/ReferenceBuild.ps1 index cb32a20..f565f59 100644 --- a/Tests/ReferenceBuild.ps1 +++ b/Tests/ReferenceBuild.ps1 @@ -7,7 +7,7 @@ $ErrorActionPreference = 'Stop' . $PSScriptRoot/../PSCMake/Common/Ninja.ps1 # Get ninja.exe -function PrepareReferenceBuild() { +function PrepareReferenceBuild($Preset = 'windows-x64') { $NinjaCommand = Get-Command 'ninja.exe' -ErrorAction SilentlyContinue $NinjaPath = if ($NinjaCommand) { $NinjaCommand.Source @@ -25,7 +25,7 @@ function PrepareReferenceBuild() { Select-Object -First 1 # Write the CMake query files - $BinaryDirectory = New-Item -Path "$PSScriptRoot/ReferenceBuild/__output/windows-x64" -ItemType Directory -Force + $BinaryDirectory = New-Item -Path "$PSScriptRoot/ReferenceBuild/__output/$Preset" -ItemType Directory -Force Enable-CMakeBuildQuery $BinaryDirectory @@ -35,7 +35,7 @@ function PrepareReferenceBuild() { $CMAKE_MAKE_PROGRAM = $NinjaPath.Replace('\', '/') @( - "--preset", "windows-x64", + "--preset", $Preset, "-S", $BuildPath "-DCMAKE_CXX_COMPILER=$CMAKE_CXX_COMPILER" "-DCMAKE_MAKE_PROGRAM=$CMAKE_MAKE_PROGRAM"