Robotics StackExchange | Archived questions

Colcon Build from Any Directory and Need to Re-build for changes in Launch file

New to ROS2 and Nav2 here.

  1. Currently, my directory structure is like this: home>nav2_ws>src>navigation2. I need my build and install directory to be in nav2ws. For which currently I call colcon build --symlink-install while in `~/nav2ws`. In ros1- catkin build, I used to call it from anywhere in the workspace (after initialization), and it used to build it at the same location. Is there a quick way to set a single build space and install space in colcon, so that colcon build could be called from anywhere in the workspace?

  2. while using colcon build --symlink-install, it ‘installs’ the workspace, due to which ros2 launch uses all the launch files from the “share” directory (not from the src directory). Now if we change anything in the launch file (src dir), it won’t be reflected in the share directory unless we again do colcon build --symlink-install. Is there way to simplify this? so that user doesn’t have to build it again and again for changes in the launch file?

Ros version - foxy

Asked by puru on 2020-11-16 08:08:58 UTC

Comments

There's been some talk about item 1 and a proposed change too, respectively https://github.com/colcon/colcon-core/issues/139 and https://github.com/colcon/colcon-core/issues/369

Asked by christophebedard on 2020-11-16 09:25:40 UTC

As for item 2, there's a workaround here: https://github.com/colcon/colcon-core/issues/169#issuecomment-531517276. It was mentioned in that issue that newer versions of setuptools should allow for symlinking instead of copying, but I'm not sure if it actually happened/is available through colcon.

Asked by christophebedard on 2020-11-16 09:36:50 UTC

Thought I'd clarify some potential confusion based on the question wording. colcon always installs things into the install/ dir and the ros2 tools never use anything from src/. What happens with --symlink-install is those files underneath install/ are just links back to the originals under src/ so you can change them and see it take effect without rebuilding. @christophebedard is referring to a bug where python packages don't create those links when they ideally should. It's not clear from the question if that's the problem you're running into.

Asked by jdlangs on 2020-11-16 15:16:30 UTC

Answers

For item 1, you can use provided command line arguments --build-base and --install-base specified here

colcon build --build-base <your-build-path> --install-base <your-install-path>

I expected a --log-base argument as well but it does not seem to exist; instead you can set the COLCON_LOG_PATH environment variable. Just add this to your .bashrc:

export COLCON_LOG_PATH=<your-log-path>

Pro tip:

Instead of always specifying the build and install base in your command you can set your configuration in ~/.colcon/defaults.yaml as specified here

Here is my configuration as reference:

{
    "build": {
        "symlink-install": true,
        "build-base": "/code/ros2_ws/build",
        "install-base": "/code/ros2_ws/install",
        "base-paths": ["/code/ros2_ws/src"]
    },
    "test": {
        "build-base": "/code/ros2_ws/build",
        "install-base": "/code/ros2_ws/install",
        "event-handlers": ["console_direct+"],
        "base-paths": ["/code/ros2_ws/src"],
    }
}

Asked by tnajjar on 2021-12-22 05:56:05 UTC

Comments

Hey there!

I had the same problem and kept building in the wrong path, which was super annoying so I created a script with an alias. The alias is defined in project_dir/scripts/aliases.sh and builds a workspace in the directory project_dir/moveit2_ws.

parent_path="$(dirname $(dirname "$(realpath "$0")"))"

alias build-moveit2-ws='colcon \
                            --log-base $parent_path/moveit2_ws/log \
                        build \
                            --base-paths $parent_path/moveit2_ws/src \
                            --install-base $parent_path/moveit2_ws/install \
                            --build-base $parent_path/moveit2_ws/build \
                            --symlink-install \
                            --mixin rel-with-deb-info compile-commands ccache
                        source $parent_path/scripts/source-project.zsh'

Hope I this can help you! Johannes

Asked by bi3ri on 2023-05-05 01:36:24 UTC

Comments