Skip to content
Merged
Show file tree
Hide file tree
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
10 changes: 4 additions & 6 deletions PSCMake/Common/CMake.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand Down Expand Up @@ -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
Expand Down
4 changes: 2 additions & 2 deletions PSCMake/PSCMake.psm1
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
5 changes: 3 additions & 2 deletions Tests/Configure-CMakeBuild.Tests.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -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')
}
}

Expand Down
17 changes: 15 additions & 2 deletions Tests/Invoke-CMakeOutput.Tests.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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"
Expand Down
6 changes: 3 additions & 3 deletions Tests/ReferenceBuild.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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

Expand All @@ -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"
Expand Down
39 changes: 27 additions & 12 deletions Tests/ReferenceBuild/CMakePresets.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,8 @@
"minor": 21,
"patch": 0
},
"configurePresets": [{
"configurePresets": [
{
"name": "ninja",
"hidden": true,
"generator": "Ninja Multi-Config"
Expand All @@ -30,6 +31,13 @@
},
"environment": {}
},
{
"name": "windows-x64[asan]",
"inherits": "windows-x64",
"cacheVariables": {
"ENABLE_ASAN": "ON"
}
},
{
"name": "windows-arm",
"inherits": "windows",
Expand All @@ -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
}
}
}]
]
}