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

Configure raises an error if CTest scripts print to stdout #3750

Closed
benschreiber opened this issue May 8, 2024 · 7 comments · Fixed by #3868
Closed

Configure raises an error if CTest scripts print to stdout #3750

benschreiber opened this issue May 8, 2024 · 7 comments · Fixed by #3868
Assignees
Labels
bug a bug in the product
Milestone

Comments

@benschreiber
Copy link

Brief Issue Summary

My project uses TEST_INCLUDE_FILES to generate labels for CTest tests at runtime.

Our script prints a line Generating test labels... to stdout. This causes CMake Tools to report an error when configuring.

[rollbar] Unhandled exception: Unhandled Promise rejection: cleanConfigure SyntaxError: Unexpected token G in JSON at position 0 {}

[error] SyntaxError: Unexpected token G in JSON at position 0
	at JSON.parse (<anonymous>)
	at CTestDriver.refreshTests (/root/.vscode-server/extensions/ms-vscode.cmake-tools-1.17.17/dist/main.js:50861:37)
	at async /root/.vscode-server/extensions/ms-vscode.cmake-tools-1.17.17/dist/main.js:44894:29
	at async CMakeProject.doConfigure (/root/.vscode-server/extensions/ms-vscode.cmake-tools-1.17.17/dist/main.js:45001:24) cmake.cleanConfigure {"value":"ms-vscode.cmake-tools","_lower":"ms-vscode.cmake-tools"}

This can easily be reproduced.

cmake_minimum_required(VERSION 3.27)
project(foo)

enable_testing()

file(CONFIGURE
    OUTPUT ${PROJECT_BINARY_DIR}/createTestLabels.cmake
    CONTENT "execute_process(COMMAND @CMAKE_COMMAND@ -E echo \"Generating test labels...\")\n"
    @ONLY
)

set_property(DIRECTORY APPEND PROPERTY
    TEST_INCLUDE_FILES ${PROJECT_BINARY_DIR}/createTestLabels.cmake
)
{
    "version": 6,
    "configurePresets": [
        {
            "name": "gcc-debug",
            "binaryDir": "${sourceDir}/out/build/${presetName}",
            "cacheVariables": {
                "CMAKE_CXX_COMPILER": "g++",
                "CMAKE_BUILD_TYPE": "Debug"
            },
            "generator": "Unix Makefiles"
        }
    ],
    "buildPresets": [
        {
            "name": "gcc-debug",
            "configurePreset": "gcc-debug"
        }
    ],
    "testPresets": [
        {
            "name": "gcc-debug",
            "configurePreset": "gcc-debug"
        }
    ]
}

CMake Tools Diagnostics

No response

Debug Log

No response

Additional Information

No response

@github-actions github-actions bot added the triage label May 8, 2024
@github-project-automation github-project-automation bot moved this to Triage Needed in CMake Tools May 8, 2024
@Yingzi1234 Yingzi1234 added more info needed More info is needed from the community for us to properly triage and investigate. and removed triage labels May 9, 2024
@Yingzi1234
Copy link
Collaborator

Yingzi1234 commented May 9, 2024

@benschreiber Thank you for your github issue! We followed the command you provided to reproduce the issue, but we encountered error below, in order to better reproduce and solve your issue, could you provide us with your reproduction steps video and reproduction file?
image

@benschreiber
Copy link
Author

It looks like you are on windows? Then you can modify the preset to use MSVC and the VS Generator. But it would be easier to just try to reproduce on Linux or in WSL.

@benschreiber
Copy link
Author

@Yingzi1234 If you're still stuck, try using this devcontainer.json

{
    "image": "mcr.microsoft.com/devcontainers/cpp:debian-12",
    "customizations": {
        "vscode": {
            "extensions": [
                "ms-vscode.cpptools",
                "ms-vscode.cmake-tools"
            ]
        }
    }
}

@benschreiber benschreiber changed the title [rollbar] Unhandled exception: Unhandled Promise rejection: cleanConfigure SyntaxError: Unexpected token in JSON at position 0 {} Configure raises an error if CTest scripts print to stdout May 15, 2024
@Yingzi1234
Copy link
Collaborator

Yingzi1234 commented May 17, 2024

@benschreiber Thanks for your reply, based on the latest information you provided, we tried to reproduce your issue on a Linux machine, but are not sure if we got the same results as your issue. When I run the "CMake: configure" command, an error box pops up, but when I go to the output window, the contents show that my configuration was successful. Here's a recording of my reproduction for you to check out.
GitHub issue.webm

@benschreiber
Copy link
Author

@Yingzi1234 Yes, that is the same behavior I see. I know that the configure step was successful, but the error box should not pop up.

@Yingzi1234 Yingzi1234 added bug a bug in the product and removed more info needed More info is needed from the community for us to properly triage and investigate. labels May 21, 2024
@Yingzi1234
Copy link
Collaborator

Yingzi1234 commented May 21, 2024

Hi @gcampbell-msft, based on customer repro steps we can reproduced this issue on Linux platform(Configuration was successful but an error box appears), you can get the details below and we have been changed the issue's status to "Bug" if it is incorrect, could you help change it to the correct label? Thank you in advance!

ENV:

  1. Platform: Linux
  2. CMake tools: v1.17.17
  3. VScode: 1.89.1

Repro steps:

  1. Create a folder on desktop and open it by VScode
  2. Create a CMakeLists.txt file and paste the following into it
cmake_minimum_required(VERSION 3.27)
project(foo)

enable_testing()

file(CONFIGURE
    OUTPUT ${PROJECT_BINARY_DIR}/createTestLabels.cmake
    CONTENT "execute_process(COMMAND @CMAKE_COMMAND@ -E echo \"Generating test labels...\")\n"
    @ONLY
)

set_property(DIRECTORY APPEND PROPERTY
    TEST_INCLUDE_FILES ${PROJECT_BINARY_DIR}/createTestLabels.cmake
)
  1. Create a CMakePresets.json file and paste the following into it
{
    "version": 6,
    "configurePresets": [
        {
            "name": "gcc-debug",
            "binaryDir": "${sourceDir}/out/build/${presetName}",
            "cacheVariables": {
                "CMAKE_CXX_COMPILER": "g++",
                "CMAKE_BUILD_TYPE": "Debug"
            },
            "generator": "Unix Makefiles"
        }
    ],
    "buildPresets": [
        {
            "name": "gcc-debug",
            "configurePreset": "gcc-debug"
        }
    ],
    "testPresets": [
        {
            "name": "gcc-debug",
            "configurePreset": "gcc-debug"
        }
    ]
}
  1. Create a devcontainer.json file and paste the following into it
{
    "image": "mcr.microsoft.com/devcontainers/cpp:debian-12",
    "customizations": {
        "vscode": {
            "extensions": [
                "ms-vscode.cpptools",
                "ms-vscode.cmake-tools"
            ]
        }
    }
}
  1. After saving all, click F1 to run "CMake: configure" command

Actual result:
It shows that "Configuring done" and "Generating done" but pops up with an error message: "Unexpected token 'G', "Generating"... is not valid JSON"
GitHub issue.webm

@gcampbell-msft gcampbell-msft moved this from Triage Needed to Pending Prioritization in CMake Tools Jun 24, 2024
@gcampbell-msft gcampbell-msft added this to the 1.19 milestone 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 10, 2024
@v-frankwang
Copy link
Collaborator

We verified the issue on CMake tools: v1.19.45 and it has been fixed.

ENV:
CMake Tools:v1.19.45
vscode: 1.92.2

Actual result:
image

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
Projects
Status: Completed
Development

Successfully merging a pull request may close this issue.

4 participants