skip to Main Content

I use VSC to compile and debug a CPP generated test executable. The name of the executable and makefile changes depending on which build I’m debugging, and importantly there is only ever a single executable/makefile in my workspace directory.

I’m wondering if there’s a way to simply build/debug the makefile/exe that is found within the directory, as my current solution is to create a new build task/launch configuration (or update my existing configuration) for each build with the updated exe/makefile name, but this is of course not an ideal solution.

"tasks":[
   {
      "label": "Build A",
      "type": "shell",
      "command": "vcvars32.bat && nmake /nologo /S /F .\TestA.mak",
      "group": "build",
      "options": {"cwd": "${workspaceFolder}"
   },
   {
      "label": "Build B",
      "type": "shell",
      "command": "vcvars32.bat && nmake /nologo /S /F .\TestB.mak",
      "group": "build",
      "options": {"cwd": "${workspaceFolder}"
   },

]
"configurations":
[
   {
      "name": "Test A",
      "program": "${workspaceRoot}\TestA.exe"
      "cwd": "${fileDirname}",
      ...
    },
    {
      "name": "Test B",
      "program": "${workspaceRoot}\TestB.exe"
      "cwd": "${fileDirname}",
      ...
    }
]

Changing the name of the makefile/exe is not a solution here, I’m limited by the tools my org uses.

For reference, I open create a new workspace for each build. Our codebase is auto-generated code, so for each build, each required .cpp/.hpp is generated. Having a new workspace for each build means I don’t have duplicates of files. I don’t know if this is the optimal workflow for me.. but it works. As such, having some easily transferable/global build tasks/run configurations would make my life a little bit easier.

EDIT:
I was able to set up my task.json for this, just need to figure out for launch configurations 🙂

"tasks":[
   {
      "label": "Build",
      "type": "shell",
      "command": "vcvars32.bat && for /r ${workspaceFolder} %i in (*.mak) do nmake /nologo /S /F %i",
      "group": "build",
      "options": {"cwd": "${workspaceFolder}"
   },
]

2

Answers


  1. Using the extension Command Variable you can add a pickFile selection:

    Global tasks.json

    {
      "version": "2.0.0",
      "tasks": [
        {
          "label": "Build A",
          "type": "shell",
          "command": "vcvars32.bat && nmake /nologo /S /F ${input:pickMakefile}",
          "group": "build",
          "options": {"cwd": "${workspaceFolder}",
          "problemMatcher": []
        }
      ],
      "inputs": [
        {
          "id": "pickMakefile",
          "type": "command",
          "command": "extension.commandvariable.file.pickFile",
          "args": {
            "include": "**/*.mak",
            "description": "Select a Makefile",
            "acceptIfOneFile": true
          }
        }
      ]
    }
    

    The property "acceptIfOneFile": true is implemented in v1.45.

    You can do the same for your Global Launch configs in settings.json

    "launch": {
      "version": "0.2.0",
      "configurations": [
        {
          "name": "Test Exe",
          "program": "${input:pickExefile}"
          "cwd": "${fileDirname}",
          ...
        }
      ],
      "inputs": [
        {
          "id": "pickExefile",
          "type": "command",
          "command": "extension.commandvariable.file.pickFile",
          "args": {
            "include": "**/*.exe",
            "description": "Select an Exe file",
            "acceptIfOneFile": true
          }
        }
      ]
    }
    
    Login or Signup to reply.
  2. You can use a compound task to build using your for trick in the OP:

    Global tasks.json

    {
      "version": "2.0.0",
      "tasks": [
        {
          "label": "Make Build",
          "type": "shell",
          "command": "vcvars32.bat && for /r ${workspaceFolder} %i in (*.mak) do nmake /nologo /S /F %i",
          "options": {"cwd": "${workspaceFolder}",
          "problemMatcher": []
        },
        {
          "label": "Rename EXE Build",
          "type": "shell",
          "command": "for /r ${workspaceFolder} %i in (*.exe) do rename %i TestRENAME.exe",
          "options": {"cwd": "${workspaceFolder}",
          "problemMatcher": []
        },
        {
          "label": "Build",
          "group": "build",
          "dependsOn": ["Make Build", "Rename EXE Build"],
          "dependsOrder": "sequence"
        }
      ]
    }
    

    In your Global Launch config use the exe TestRENAME.exe

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search