Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Expansion of ${generator} macro not working in preset conditions #2934

Closed
petwu opened this issue Jan 10, 2023 · 1 comment · Fixed by #3905
Closed

Expansion of ${generator} macro not working in preset conditions #2934

petwu opened this issue Jan 10, 2023 · 1 comment · Fixed by #3905
Assignees
Labels
bug a bug in the product Feature: presets suggested Temporary label for internal tracking for suggested bugs to pick up in spare time.
Milestone

Comments

@petwu
Copy link

petwu commented Jan 10, 2023

Brief Issue Summary

In order to reuse our company-internal CMake presets I wanted to create a repository with common base presets and leverage the include and inherits capabilities. Since the build presets differ for single-config and multi-config generators (mainly the configuration property), I tried to leverage the condition properties to check what the value of ${generator} is. Unfortunately, the evaluation seems to fail and does not match CMake's command line behavior.

CMake Tools Diagnostics

{
  "os": "win32",
  "vscodeVersion": "1.74.2",
  "cmtVersion": "1.12.27",
  "configurations": [
    {
      "folder": "c:\\Users\\WDAGUtilityAccount\\Desktop\\presets-test",
      "cmakeVersion": "3.25.1",
      "configured": true,
      "generator": "Ninja",
      "usesPresets": true,
      "compilers": {}
    }
  ],
  "cpptoolsIntegration": {
    "isReady": false,
    "hasCodeModel": false,
    "activeBuildType": "",
    "buildTypesSeen": [],
    "requests": [],
    "responses": [],
    "partialMatches": [],
    "targetCount": 0,
    "executablesCount": 0,
    "librariesCount": 0,
    "targets": []
  },
  "settings": [
    {
      "communicationMode": "automatic",
      "useCMakePresets": "auto",
      "configureOnOpen": null
    }
  ]
}

Debug Log

No response

Additional Information

Example Presets

CMakePresets.json
{
    "version": 4,
    "configurePresets": [
        {
            "name": "base-single",
            "hidden": true,
            "generator": "Ninja"
        },
        {
            "name": "base-multi",
            "hidden": true,
            "generator": "Ninja Multi-Config"
        },
        {
            "name": "dev1",
            "inherits": ["base-single"]
        },
        {
            "name": "dev2",
            "inherits": ["base-multi"]
        },
        {
            "name": "dev3",
            "generator": "Ninja"
        },
        {
            "name": "dev4",
            "generator": "Ninja Multi-Config"
        },
        {
            "name": "dev5",
            "inherits": ["base-single"],
            "condition": {
                "type": "equals",
                "lhs": "${generator}",
                "rhs": "Ninja"
            }
        },
        {
            "name": "dev6",
            "inherits": ["base-single"],
            "condition": {
                "type": "equals",
                "lhs": "${generator}",
                "rhs": "Ninja Multi-Config"
            }
        },
        {
            "name": "dev7",
            "generator": "Ninja",
            "condition": {
                "type": "equals",
                "lhs": "${generator}",
                "rhs": "Ninja"
            }
        },
        {
            "name": "dev8",
            "generator": "Ninja",
            "condition": {
                "type": "equals",
                "lhs": "${generator}",
                "rhs": "Ninja Multi-Config"
            }
        }
    ],
    "buildPresets": [
        {
            "name": "dev1-working",
            "configurePreset": "dev1",
            "environment": {
                "GENERATOR_MACRO": "${generator}"
            },
            "condition": {
                "type": "equals",
                "lhs": "${hostSystemName}",
                "rhs": "Windows"
            }
        },
        {
            "name": "dev1-single",
            "configurePreset": "dev1",
            "condition": {
                "type": "equals",
                "lhs": "${generator}",
                "rhs": "Ninja"
            }
        },
        {
            "name": "dev1-multi-debug",
            "configurePreset": "dev1",
            "configuration": "Debug",
            "condition": {
                "type": "equals",
                "lhs": "${generator}",
                "rhs": "Ninja Multi-Config"
            }
        },
        {
            "name": "dev1-multi-release",
            "configurePreset": "dev1",
            "configuration": "Release",
            "condition": {
                "type": "equals",
                "lhs": "${generator}",
                "rhs": "Ninja Multi-Config"
            }
        },
        {
            "name": "dev2-single",
            "configurePreset": "dev2",
            "condition": {
                "type": "equals",
                "lhs": "${generator}",
                "rhs": "Ninja"
            }
        },
        {
            "name": "dev2-multi-debug",
            "configurePreset": "dev2",
            "configuration": "Debug",
            "condition": {
                "type": "equals",
                "lhs": "${generator}",
                "rhs": "Ninja Multi-Config"
            }
        },
        {
            "name": "dev2-multi-release",
            "configurePreset": "dev2",
            "configuration": "Release",
            "condition": {
                "type": "equals",
                "lhs": "${generator}",
                "rhs": "Ninja Multi-Config"
            }
        },
        {
            "name": "dev3-single",
            "configurePreset": "dev3",
            "condition": {
                "type": "equals",
                "lhs": "${generator}",
                "rhs": "Ninja"
            }
        },
        {
            "name": "dev3-multi-debug",
            "configurePreset": "dev3",
            "configuration": "Debug",
            "condition": {
                "type": "equals",
                "lhs": "${generator}",
                "rhs": "Ninja Multi-Config"
            }
        },
        {
            "name": "dev3-multi-release",
            "configurePreset": "dev3",
            "configuration": "Release",
            "condition": {
                "type": "equals",
                "lhs": "${generator}",
                "rhs": "Ninja Multi-Config"
            }
        },
        {
            "name": "dev4-single",
            "configurePreset": "dev4",
            "condition": {
                "type": "equals",
                "lhs": "${generator}",
                "rhs": "Ninja"
            }
        },
        {
            "name": "dev4-multi-debug",
            "configurePreset": "dev4",
            "configuration": "Debug",
            "condition": {
                "type": "equals",
                "lhs": "${generator}",
                "rhs": "Ninja Multi-Config"
            }
        },
        {
            "name": "dev4-multi-release",
            "configurePreset": "dev4",
            "configuration": "Release",
            "condition": {
                "type": "equals",
                "lhs": "${generator}",
                "rhs": "Ninja Multi-Config"
            }
        }
    ]
}

Expected Behavior

All presets whose conditions are evaluated to true are displayed.

Actual Behavior

CMake > Select Configure Preset is missing the dev5 configure preset:

image

CMake > Select Build Preset does not show any of the associated build presets, whether the condition is met or not:

image

Also when a configure preset is selected for the first time, the first associated build preset is selected automatically even if its condition is not fulfilled and it is not visible in the dropdown:

image

For reference, these are the presets recognized by CMake:

$ cmake --list-presets=configure
Available configure presets:

  "dev1"
  "dev2"
  "dev3"
  "dev4"
  "dev5"
  "dev7"

$ cmake --list-presets=build
Available build presets:

  "dev1-single"       
  "dev2-multi-debug"  
  "dev2-multi-release"
  "dev3-single"       
  "dev4-multi-debug"  
  "dev4-multi-release"

Other Observations

With other properties such as environment the ${generator} macro gets correctly expanded. Also, conditions with other macros such as ${hostSystemName} work as expected. See dev1-working.

@elahehrashedi
Copy link
Contributor

Thank you for reporting this issue. It looks like we are not evaluating the inherits when expanding the condition and it's causing it to fail.

@elahehrashedi elahehrashedi added the bug a bug in the product label Jan 10, 2023
@elahehrashedi elahehrashedi added this to the 1.14 milestone Jan 10, 2023
@elahehrashedi elahehrashedi modified the milestones: 1.14, On Deck Jan 10, 2023
@github-project-automation github-project-automation bot moved this to Triage Needed in CMake Tools Nov 29, 2023
@gcampbell-msft gcampbell-msft moved this from Triage Needed to Pending Prioritization in CMake Tools Nov 29, 2023
@gcampbell-msft gcampbell-msft added the suggested Temporary label for internal tracking for suggested bugs to pick up in spare time. label Apr 24, 2024
@gcampbell-msft gcampbell-msft modified the milestones: On Deck, 1.19 Jun 24, 2024
@gcampbell-msft gcampbell-msft moved this from Pending Prioritization to Ready to be Assigned in CMake Tools Jun 26, 2024
@gcampbell-msft gcampbell-msft self-assigned this Jun 26, 2024
@gcampbell-msft gcampbell-msft moved this from Ready to be Assigned to In Progress in CMake Tools Jul 3, 2024
@github-project-automation github-project-automation bot moved this from In Progress to Completed in CMake Tools Jul 24, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug a bug in the product Feature: presets suggested Temporary label for internal tracking for suggested bugs to pick up in spare time.
Projects
Status: Completed
Development

Successfully merging a pull request may close this issue.

5 participants