question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Using preLaunchTask with Cmake Tools

See original GitHub issue

After some fiddling I finally found out how to invoke cmake.build properly from within launch.json.

Steps:

  • create a ba(t)ch file someFolder/prelaunch.bash:
#!/bin/bash
if [ $1 == 0 ] 
then
    printf "Build is OK :-)\n"
    exit 0
fi
if [ $1 == 1 ] 
then
    printf "**** Please build project first. ****\n\n"
    exit 1
else
    printf "**** Please fix build errors. ****\n\n"
fi
exit 2
  • create the following task:
        {
            "label": "Check build",
            "type": "shell",
            "options": { "statusbar": { "hide" : true } },
            "presentation": {
                "echo": false,
                "focus": false,
                "reveal": "never",
                "revealProblems": "always"                                  // Use "always" to default to the "problems" window or "never" to default to the "output" window after build.
            },
            "command" : "someFolder/prelaunch.bash ${command:cmake.build}"
        }
  • add the preLaunchTask to launch.json: "preLaunchTask": "Check build"

  • change the source code of the extension (main.js in the VS code extensions folder):

    /**
     * Implementation of `cmake.build`
     */
    async build(target_) {
        this.m_promise_build = await this.runBuild(target_);          // add await to the build function
        //return this.m_promise_build;                                // comment this and add the following line 
        return JSON.stringify(this.m_promise_build);
    }

Is there any chance this modification gets into the releases? Or add an implementation (eg. cmake.prebuild)?

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Reactions:3
  • Comments:13 (8 by maintainers)

github_iconTop GitHub Comments

1reaction
bobbrowcommented, Nov 10, 2020

Oops! Yes you did. 😅 Try this instead:

  vscode.commands.executeCommand('cmake.selectLaunchTarget', undefined, "targetName");

The first parameter is a vscode.WorkspaceFolder (can be undefined if you want to use the currently “active” folder as context) The second parameter is the target name

1reaction
RolfNootcommented, Nov 10, 2020

This is exactly what I did. I noticed it was possible to Ctrl+click the links in the terminal window indeed, however creating a dedicated .js (using the Powertools extension) provided the most flexible solution.

I created a .js file with the following command implementation:

exports.execute = async (args) => {
    const vscode = args.require('vscode');
    var ret = await     vscode.commands.executeCommand('cmake.build');
    if (ret == 0) return '';
    vscode.commands.executeCommand('workbench.action.problems.focus', 'CMake/Build');
    vscode.window.showErrorMessage("Your code didn't built well...\n\nTry some more :-)", { modal: true });
    return null;
};

Next, I called this command directly from the preBuildTask.

Read more comments on GitHub >

github_iconTop Results From Across the Web

preLaunchTask to build using cmaketools in settings.json #540
I've tried using a build task but I couldnt get it to work. Is there any way to do this currently? { //...
Read more >
Target Debugging and Launching — CMake Tools 1.4.0 ...
CMake Tools removes some of the friction required in setting up debugging. ... Debugging is only supported when using CMake Server mode.
Read more >
VSCode make launch configuration fail if preLaunchTask fails
I had the same problem with a cmake task. I've solved it by changing task's type to shell and passing everything else in...
Read more >
vscode-cmake-tools/support - Gitter
Just wanting to know if anyone recommends using cmake-tools-helper , or not? ... "preLaunchTask": "clang++ build active file", "logging": { "trace": true, ...
Read more >
Debug an app running in a Docker container
The Docker extension provides a docker debug configuration provider that manages how VS Code will launch an application and/or attach a debugger to...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found