top of page
Search
  • Writer's pictureJoseph

Automate Workflow Using VSCode

VSCode is a very popular tool to manage large projects in C/C++. One of the main advantages of VSCode is we can automate workflows that we use often. There are many articles available on how you can do this, but most of them do not consider an HPC environment. For instance, if we are using VSCode on a system that loads the required versions of software using module load or snap load, we will see that VSCode cannot discover the required toolkit we need. Which means

  1. Cmd + Shift + P

  2. Scan of kit

will not give the correct toolkit we need. This means most of the automation available for CMake or make is out of the window. I have faced this problem in my projects, so I use User Task within VSCode to automate my workflows.


For example, I have a project parsec and I need to build the project in the build directory (parsec/build ) and install it in the install directory (parsec/build/install). My workflow for this project (assuming my VSCode workspace is the parsec directory) is as follows

  1. Load all modules I need. I usually have all the module load commands in a module.sh file and I source this file to load all the modules (source module.sh). Make sure you set the executable permission for this file (chmod 777 module.sh)

  2. Then run the command ../configure --prefix=/home/parsec/build/install --enable-debug=noisier --enable-prof-trace. Which is the command to run CMake for this project.

  3. I use ninja as my build tool. So to build and install the project I run ninja install.

Most projects I deal with have a similar workflow and to automate this workflow in VSCode I do the following

  1. Cmd + Shift + P

  2. Task: Open User Task

This will open the file task.json with the following:

{
    "version": "2.0.0",
    "tasks": [
        {
            "label": " ",
            "type": " ",
            "command": " "
        }
    ]
}

Populate the following with the commands you need (${workspaceRoot} will have the path ~/home/parsec in this case):

{
    "version": "2.0.0",
    "tasks": [
        {
            "label": "parsec configure and build",
            "type": "shell",
            "command": " cd ${workspaceRoot}/build; source ../../module_profiling.sh; ../configure --prefix=${workspaceRoot}/build/install --enable-debug=noisier --enable-prof-trace; ninja install"
        }
    ]
}

Once you save the file you can just run workflow using

  1. Cmd + Shift + B

  2. Tasks: Run Task

  3. Select 'parsec configure and build'

While this may not be very clean as most VSCode solutions, I find this more robust as I control all aspects of the workflow.

16 views0 comments

Recent Posts

See All

Using Vim and Ctags to Manage Large Projects

The usual workflow in developing an HPC application is to develop the code in local machines and then run the completed application in an HPC machine. There is no scenario where the entire application

bottom of page