Giter VIP home page Giter VIP logo

vscode-colcon-helper's Introduction

Colcon

Extension is intended to simplify use of colcon command line tool.

It provides tasks for colcon workspace and automatically run setup scripts in order to correctly adjust environment.

How to use

  1. Enable tasks by running command (Ctrl + Shift + P) Colcon: Enable Tasks for current Workspace or manually set colcon.provideTasks to true.
  2. If default options doesn't suit your workspace, you may configure colcon.globalSetup and colcon.workspaceSetup lists of setup files.
  3. Run Colcon: Refresh Environment command to complete environment set up for your workspace.
  4. Now open yout task list and run any task you want!

How to use on Windows

colcon tasks should be run within VisualStudio dev environment, so you have to add intialization script to your workspace or global setup.

Also, --symlink-install option of colcon build on Windows may be not working without Administator rights. This option is included by default, so you have to either

  • run VS Code as Administator (which is not recommended by VS Code itself)
  • or open VS Code command promt, run > Tasks: Configure Task and then select colcon: build task in picker. Build task configuration should then appear in tasks.json, where you can remove --symlink-install argument.

cmd

Add VisualStudio's vcvars*.bat script to your workspace setup. E.g.:

"colcon.workspaceSetup": [
    "C:\\ros2\\foxy\\local_setup.bat",

    // this one:
    "C:\\Program Files (x86)\\Microsoft Visual Studio\\2019\\Community\\VC\\Auxiliary\\Build\\vcvars64.bat",

    "install/setup.bat"
],

powershell

  1. Create vcvars.ps1 script with content listed below. Please note that you may have to change paths to actual ones.
# https://developercommunity.visualstudio.com/t/powershell-version-of-vcvarsallbat/362377#T-N1029643

Import-Module "C:\Program Files (x86)\Microsoft Visual Studio\2019\Community\Common7\Tools\Microsoft.VisualStudio.DevShell.dll"

Enter-VsDevShell `
    -VsInstallPath "C:\Program Files (x86)\Microsoft Visual Studio\2019\Community\" `
    -StartInPath .
  1. Add path to it to your colcon.workspaceSetup

Available tasks

Tasks provided at the moment:

Workspace level:

  • colcon: build Do exactly the same as command-line colcon build
  • colcon: test
  • colcon: test-result similarily to build
  • colcon: clean that is simple call to rm -f build install

Two tasks specially for current editor:

  • colcon: build <current package> - like
  • colcon: launch <current file.launch.py> that is by default calls ros2 launch ./<current file> command

First three commands use colcon as executable being launched, yet the last two could be configured with colcon.runCommand and colcon.cleanCommand settings.

By default tasks are runned using corresponding workspace folder as working directory but this could be configured via colcon.colconCwd option.

Colcon tool

colcon (COLlective CONstruction) is the command line tool that is known as default build system for ROS2. It may be used as build tool for literally any project (but as far as I know only CMake and Python setuptools are supported directly).

A little bit on workspaces

Main goal of colcon is to build packages in the order based on their dependecies.

colcon build system suppose that you separate your source files in the different workspaces while each of those contain any number of packages. As for ROS2, you may consider each ROS2 repo as different colcon workspace and work with each individually - or put all repos in the large src folder and build them all at once.

When you develop packages in VS Code, you may want to get access to several colcon workspaces within single VS Code workspace - it is possible with VS Code multi-root workspace feature. Each colcon workspace that you want to work with would be a different workspace folder inside VS Code.

This extension allows you to set up settings for each folder individually, whether you want to use it with colcon or not. Any changes to settings in nested folders may override settings for workspace folder, but it is recommended to set up colcon only in upper level folders.

Sourcing workspaces

When you build your workspace (I mean, colcon workspace, not VS Code one), there is two folders are being created: build/ and install/. As their names imply, the first one contains build files and the second contains final packages.

In order to make your package discoverable you must source special file depending on your platform and shell. There are several files created during colcon build command and for Linux with Bash the correct file would be install/setup.sh. (See available setup files in install/ if you use another platform/shell.)

This extension helps you to source workspace with just one command named Refresh colcon environment. You may list any necessary workspaces with two settings: colcon.globalSetup and colcon.workspaceSetup. You can add any setup file paths to either of lists. It is considered that globalSetup lists all workspaces that would be used with any colcon workspace - like /opt/ros/dashing/setup.sh - while workspaceSetup contains only local install/setup.sh and other workspaces that are needed to build this exact workspace.

As a special bonus, with this you can specify literally any file, not just colcon setups. For example, you may want to source /home/user/.bashrc in every your colcon workspace and therefore you should add it to your colcon.globalSetup list.

By default there is only /opt/ros/dashing/setup.sh in the globalSetup and install/setup.sh in the workspaceSetup. If you use e.g. ZSH as your terminal.integrated.shell, you must explicitely set corresponding setup file extension as .zsh.


More info about extension

Enabling extension

By default extension do nothing until you explicitly set "colcon.provideTasks": true in workspace or folder VS Code settings. If you use multi-root workspace, it is highly recommended to set colcon settings in each workspace folder individually.

After you set provideTask option, you will get colcon tasks in the task list based on the default settings. Tasks are collected only for workspace folder that is parent to document in current editor.

There may be no tasks if you open task list for document outside your workspace, yet there may be tasks for all of your workspace folders if there is no current editor.

Refresh colcon environment command

After you build your project, in order to get your newest packages being discovered you must refresh your environment. This could be done by launching such command in VS Code command panel.

Command sources all of your workspaces that you listed in colcon.globalSetup and colcon.workspaceSetup then put correct environment variable values in file specified by colcon.env configuration setting. This file would be transferred to each task before execution.

If you find out there is some variable missing, you can add it through colcon.defaultEnvironment or you may change environment file manually. In the last case your changes would be overwritten in the next Refresh command execution.

NOTE that this command may run automatically if either of colcon.refreshOnStart, colcon.refreshOnTasksOpened or colcon.refreshOnConfigurationChanged is set to true.

Tasks configuration via settings.json

Each command has corresponding args setting like colcon.buildArgs. These args are inserted right after the command. In the case of build the default value is ['--symlink-install'] (more on argument meaning see colcon documentation or --help page).

If you open *.launch.py file, you'll get colcon: launch command which actually have no relation to colcon, but is very useful for ROS2 workspaces. It launches

  • ros2 launch *.launch.py
    • ros2 = could be configured with colcon.runCommand option
    • launch = could be configured with colcon.runArgs

Chaining tasks

By default each task is run independently. But in some cases you may want to run command in chains. You may use VS Code tasks.json to customize your colcon tasks and integrate with your other tasks. Example on how to automatically run colcon test before test-result when you run the latter:

{
    "type": "colcon",
    "task": "test-result",
    "problemMatcher": [],
    "dependsOn": [
        {
            "type": "colcon",
            "task": "test"
        }
    ]
}

Disclaimer

Extension is in slow development and there may be divergencies between this file, help tooltips and actual code. Feel free to ask anything and open issues.

Contact me at:

Buy Me A Coffee

vscode-colcon-helper's People

Contributors

deitry avatar dependabot[bot] avatar felix-el avatar flynneva avatar fred-labs avatar richard-guan-dev avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

vscode-colcon-helper's Issues

Make workspaceSetup a list

Right now there is three possible options how to source a file: workspaceSetup, globalSetup and userSetup.

Instead of using userSetup, there may be a list of paths that is passed as workspaceSetup and globalSetup - one is specific for current wokspace and one that is for all workspace

removing --symlink-install on windows not working as expected

I am getting this error from vs code tasks after trying to edit the tasks.json file like in the README on windows:

Error: The colcon task detection didn't contribute a task for the following configuration:
{
    "type": "colcon",
    "args": [
        "build"
    ],
    "group": "build",
    "problemMatcher": [],
    "label": "colcon: build"
}
The task will be ignored.

any tips on how to edit the tasks.json file correctly?

Support for vscode 1.44.1

Just upgraded vscode to version 1.44.1 and my custom tasks break the colcon helper. Without any tasks set in tasks.json everything works as expected. The change in 1.44.1 now only loads the tasks from colcon when colcon is selected in the run tasks dialog.

If I configure a task it adds it to the tasks.json without args key and the previous args values. Secondly it overwrites all the labels of the predefined tasks from colcon tasks.

When reusing previously configured tasks (which were working with the previous vscode version) with the correct args values it is not working anymore.

Can't run colcon

Ubuntu 20.04 ROS2 Foxy

After enabling, refreshing and running colcon build task, i get the following:

> Executing task in folder ros2_ws: /home/roxy/ros2_ws/colcon build <

The terminal process failed to launch: Path to shell executable "/home/roxy/ros2_ws/colcon" does not exist.

Terminal will be reused by tasks, press any key to close it.

I don't get why the extension is searching for colcon executable in the workspace itself...

Command to activate Colcon tasks

This would put "colcon.provideTasks": true into settings.json

Also, remove warning/error if Code is started without any workspace folder

Smooth disable of extension

Right now if you want to disable this extension, you should restart VS Code. Check Python extension which doesn't require restart. I guess one should implement disable method or something like that.

Issue with building ROS2 package, unable to properly source /opt/ros/foxy/setup.bash

Hi,

I would like to apologize first as I am new to VScode and a little unsure on how to use your extension. That said, I am getting a build error in vscode, using your extension (ctrl+shift+p and 'Colcon: Build Current Package'):

`> Executing task: colcon build --symlink-install --packages-select cpp_pubsub <

Starting >>> cpp_pubsub
--- stderr: cpp_pubsub
CMake Error at CMakeLists.txt:19 (find_package):
By not providing "Findament_cmake.cmake" in CMAKE_MODULE_PATH this project
has asked CMake to find a package configuration file provided by
"ament_cmake", but CMake did not find one.

Could not find a package configuration file provided by "ament_cmake" with
any of the following names:

ament_cmakeConfig.cmake
ament_cmake-config.cmake

Add the installation prefix of "ament_cmake" to CMAKE_PREFIX_PATH or set
"ament_cmake_DIR" to a directory containing one of the above files. If
"ament_cmake" provides a separate development package or SDK, be sure it
has been installed.


Failed <<< cpp_pubsub [0.05s, exited with code 1]

Summary: 0 packages finished [0.14s]
1 package failed: cpp_pubsub
1 package had stderr output: cpp_pubsub
The terminal process "colcon 'build', '--symlink-install', '--packages-select', 'cpp_pubsub'" terminated with exit code: 1.`

This seems to be due to /opt/ros/foxy/setup.bash not being sourced. However, following your instructions, I added the following in my package workspace/.vscode/settings.json:

{ "colcon.provideTasks": true, "colcon.globalSetup": ["/opt/ros/foxy/setup.sh"], "colcon.workspaceSetup":[ "install/setup.sh" ], }

On my terminal, I am able to colcon build the package as per normal, after I source the ros bash script.
May I ask what have I been doing wrong? Or did I skip a step somewhere.

colcon build Support for ROS2 in Windows

when performing colcon build task in Windows, error is thrown and the reason being that the command is not executed from 'x64 Native tools Command Prompt for Visual Studio'. I am interested in seeing a way to address this in VSCode

error on colcon build task
VisualStudioVersion is not set, please run within a Visual Studio Command Prompt.

Better support for non-Linux machines

This extension targets Linux as its main platform. But since colcon could be used anywhere, this extension should support non-Linux platform too.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.