presets: Inheritance of conditional presets
I propose a different evaluation of conditions in case of inheritance.
The current behavior is, that all preset within inherits
are inherited regardless if it is enabled or disabled by its condition. If inherited presets provide the same nodes, the first node wins.
The suggested behavior is, that only active preset within inherits
are inherited. If inherited presets provide the same nodes, the first node wins.
Elaboration:
I am getting the feeling, that the way conditions are currently evaluated in case of inherited presets is not particularly useful. Conditions appear to be inherited like other properties and are evaluated within the top node of the inheritance chain. In my understanding this means only one node within a chain of inheritance will ever effectively provide a condition. Hence, inheritance of conditions cannot be used to combine conditions, but only to override conditions, so that the highest element in the tree providing a condition will "win".
In case of multiple inheritance, always the first child providing a condition appears to "win" and provide the effective condition.
Instead, I propose to evaluate conditions at the time of inheritance. This would mean inheritance could be used to join multiple paths of conditional presets.
Consider the following example:
...
{
"name": "official-tool-paths-on-linux",
"hidden": true,
"environment": {
"PATH": "$env{MY_TOOLS_PATH}/foo/arm-poky-linux-gnueabi:$penv{PATH}"
},
"condition":{
"type": "notEquals",
"lhs": "${hostSystemName}",
"rhs": "Windows"
}
},
{
"name": "official-tool-paths-on-windows",
"hidden": true,
"environment": {
"PATH": "$env{MY_TOOLS_PATH}/bar/arm-poky-linux-gnueabi;$penv{PATH}"
},
"condition":{
"type": "equals",
"lhs": "${hostSystemName}",
"rhs": "Windows"
}
},
{
"name": "official-tool-paths",
"hidden": true,
"inherits": ["official-tool-paths-on-linux", "official-tool-paths-on-windows"],
"condition": null
},
{
"name": "i686-poky-linux",
"inherits": ["defaults", "official-tool-paths"],
"hidden": false,
"toolchainFile": "${sourceDir}/cmake/toolchains/i686-poky-linux.cmake"
},
...
The idea of this example is to provide different environments depending on the host system name to a common configure preset. From the user perspective i686-poky-linux is the same preset, although underlying paths differ across host systems.
The current behavior is, that always the first preset within inherits
is inherited regardless if it is enabled or disabled by its condition. In the example effectively on Linux and Windows systems, the PATH from official-tool-paths-on-linux is used, because it is given first within
"inherits": ["official-tool-paths-on-linux", "official-tool-paths-on-windows"],
This renders the above logic unusable.
I also don't see any other way to join the conditional presets into a common top preset.
The suggested behavior is, that only the first active preset within inherits
is inherited. This would allow the example to work. I also don't see how such a behavioral change would break any useful existing logic.
The proposed logic would allow to reduce the number of presets defined and presented to users and prevent that the same "logical" presets are presented to users under different names on different platforms.
Please comment. Also I would be happy to see equivalent logic for my example based on the current CMake behavior. I was not able to join conditional paths to a common preset which leads to combinatoric explosion of targets for my application.