Skip to content

Add support for multiple inheritance of presets#68

Merged
MarkSchofield merged 2 commits intodevelopfrom
mschofie/traverse
Sep 29, 2025
Merged

Add support for multiple inheritance of presets#68
MarkSchofield merged 2 commits intodevelopfrom
mschofie/traverse

Conversation

@MarkSchofield
Copy link
Owner

CMakePreset.json's presets can inherit from other presets. At the minute PSCMake only supports single inheritance - it expects inherit to be a single string - but a given preset can specify an array of preset names.

PSCMake walks the preset inheritance hierarchy for two reasons:

  1. To filter presets that have a 'condition' to limit their applicability
  2. To find the 'binaryDir' or a preset to be able to configure/use cmake-file-api.

Attempting to use PSCMake with a CMakePreset.json that uses multiple inheritance where the binaryDir is specified in a base preset will fail with:

Invoke-Command: C:\PSCMake\PSCMake\Common\Common.ps1:83
Line |
  83 |          Invoke-Command $Scriptlet
     |          ~~~~~~~~~~~~~~~~~~~~~~~~~
     | Exception calling "GetFullPath" with "1" argument(s): "The path is empty. (Parameter 'path')"

Since the 'binaryDir' can't be found. This PR adds multiple inheritance support in two transforms - implemented as two commits:

  1. Consolidate 'ancestor search' from 'ResolvePresetProperty' and 'EvaluatePresetCondition' - This commit moves the common implementation of 'ResolvePresetProperty' and 'EvaluatePresetCondition' into 'SearchAncestors'. 'SearchAncestors' takes a 'preset' object, and array of 'preset' objects to find inherited presets in. The common implementation doesn't yet support multiple inheritance, but can be tested in isolation.
  2. Accommodate multiple 'inherit' values in a given preset - Expands 'SearchAncestors' from performing a linear search of presets, to performing a 'depth-first', 'left-to-right' search of presets, following the behavior of CMake.

This change helps move to support 'included' presets, since the logic operates over a set of 'presets' (which could be 'build' or 'configuration'), not operating on the ConvertFrom-Json object directly, providing an opportunity to merge in 'included' presets.

@MarkSchofield MarkSchofield merged commit bd984bf into develop Sep 29, 2025
1 check passed
@MarkSchofield MarkSchofield deleted the mschofie/traverse branch September 29, 2025 03:35
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant