Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[bug] ROS distro not sourced for tasks.json on humble #1272

Open
1 of 4 tasks
Ryanf55 opened this issue Jan 15, 2024 · 7 comments
Open
1 of 4 tasks

[bug] ROS distro not sourced for tasks.json on humble #1272

Ryanf55 opened this issue Jan 15, 2024 · 7 comments
Labels
bug Something isn't working Building Features and bugs which affect building ROS help wanted Extra attention is needed

Comments

@Ryanf55
Copy link

Ryanf55 commented Jan 15, 2024

(Please add appropriate labels)

  • Windows: (Version)
  • Linux: (Dist/Version) Ubuntu 22.04 for development server, Windows 10 for host OS, connected using vscode ssh extension
  • ROS 1: Dist
  • ROS 2: ROS 2 humble

Plugin v0.9.6 pre-release

image

what is the bug

When I add a task to run colcon build, it does not source the ROS environment.

Repro steps

  1. Add "ros.distro": "humble", to .vscode/settings.json on the remote computer
  2. Add this to tasks.json
           {
            "label": "colconBuildDebug",
            "detail": "Build ROS 2 workspace with debug symbols",
            "type": "shell",
            "command": "colcon build --symlink-install --mixin debug",
            "group": "build",
            "problemMatcher": "$gcc"
        },
  3. Ensure the ROS extension is started and running in pre-release on the development server
  4. Type F1: Tasks: Run task and select colconBuildDebug
  5. Observe the output showing that it never sourced the ROS environment
 *  Executing task: colcon build --symlink-install --mixin debug 

Starting >>> grid_map_geo
--- stderr: grid_map_geo                         
Traceback (most recent call last):
  File "/opt/ros/humble/share/ament_cmake_core/cmake/package_templates/templates_2_cmake.py", line 21, in <module>
    from ament_package.templates import get_environment_hook_template_path
ModuleNotFoundError: No module named 'ament_package'
CMake Error at /opt/ros/humble/share/ament_cmake_core/cmake/ament_cmake_package_templates-extras.cmake:41 (message):
  execute_process(/usr/bin/python3.10
  /opt/ros/humble/share/ament_cmake_core/cmake/package_templates/templates_2_cmake.py
  /home/ryan/Dev/ros2_ws/src/grid_map_geo/build/grid_map_geo/ament_cmake_package_templates/templates.cmake)
  returned error code 1
Call Stack (most recent call first):
  /opt/ros/humble/share/ament_cmake_core/cmake/ament_cmake_coreConfig.cmake:41 (include)
  /opt/ros/humble/share/ament_cmake/cmake/ament_cmake_export_dependencies-extras.cmake:15 (find_package)
  /opt/ros/humble/share/ament_cmake/cmake/ament_cmakeConfig.cmake:41 (include)
  CMakeLists.txt:18 (find_package)


---
Failed   <<< grid_map_geo [0.13s, exited with code 1]

Summary: 0 packages finished [0.50s]
  1 package failed: grid_map_geo
  1 package had stderr output: grid_map_geo

 *  The terminal process "/bin/bash '-c', 'colcon build --symlink-install --mixin debug'" terminated with exit code: 1. 
 *  Terminal will be reused by tasks, press any key to close it. 

expected behavior

Colcon build will be successful and first source /opt/ros/humble/setup.bash before running.

additional context

Even if I add source /opt/ros/humble/setup.bash to my bashrc, it doesn't source.

As a workaround, I could do modify the task command like so, but that is not documented:
"command": "source /opt/ros/humble/setup.bash && colcon build --symlink-install --mixin debug",

Then, the launch still fails because it's not sourcing the local ROS workspace before launch:

image

@Ryanf55 Ryanf55 added the bug Something isn't working label Jan 15, 2024
@ooeygui
Copy link
Member

ooeygui commented Jan 15, 2024

Thank you for the report.

I don't know if it is possible to support this scenario. VSCode extension model has hooks for various events, which allows code to extension code to execute. Tasks.json is handled by VSCode - but it doesn't (last I looked) provide a general pre-execution hook to allow an extension to modify the execution environment.

Sourcing ROS and the overlay is one of the main reasons that the VSCode ROS extension has its own task execution for build and debug.

For this scenario, you may be able to manually prefix the command with the environment script, or build your own script which sources the environments then runs colcon.

@ooeygui ooeygui added help wanted Extra attention is needed Building Features and bugs which affect building ROS labels Jan 15, 2024
@Ryanf55
Copy link
Author

Ryanf55 commented Jan 15, 2024

How is launch.json supposed to work if it cannot source the local environment?

@ooeygui
Copy link
Member

ooeygui commented Jan 15, 2024

The problem here is using Task.json; I don't believe there is a hook for the ROS extension in that codepath of VSCode to influence the task environment.

We register a VSCode launch.json handler which is ROS aware - and is able to source the environment. The Task..json file is not used when you use the ROS mechanism, so the extension can control the environment.

@Ryanf55
Copy link
Author

Ryanf55 commented Jan 15, 2024

Two environments need sourcing causing two separate issues.

The Humble environment isn't sourced in tasks

The first is /opt/ros/humble/setup.bash which needs to be sourced if you want to add a colcon build task as shown at this timestamp in the video.

A workaround as I already shared is to prepend all commands with source /opt/ros/humble/setup.bash &&

The local workspace is not sourced for ROS launch in debuggerlaunch

Regardless of whether you build through a task, or build using your terminal, the local workspace has the build binaries and environment setup located in the default install folder. Before calling ros2 launch <myRos2Pkg> <myLaunchFile.xml>, you need to type this in Ubuntu:
source install/setup.bash

Without this, ros2 will give an error as I shared earlier:
package <myRos2Pkg> not found

And, you are unable to debug your code in VSCode with the build in GDB GUI with a launch.json.

These two problems are independent issues. Would you like me to create an issue for the 2nd one? The title of this ticket only applies to the 1st one.

I'm happy to set up a debug build of vscode, or whatever else you need to help you solve these issues on Ubuntu.

@ooeygui
Copy link
Member

ooeygui commented Jan 16, 2024

The VSCode ROS extension Provides a "ROS Create Terminal" Command which creates a new terminal with ROS sourced. VSCode does not give extensions a hook for providing environment through the normal UI.

@Ryanf55
Copy link
Author

Ryanf55 commented Jan 20, 2024

Hello,

I'm not sure if you need more info, but it appears this bug is only present when SSH'ing from Windows. If I have direct access to the Linux computer, the launch task works fine, and colcon build tasks works fine with the workaround I posted.

It would be desirable for SSH not to adversely impact this extension's functionality.

@ooeygui
Copy link
Member

ooeygui commented Jan 21, 2024

@Ryanf55 That interesting - thanks for the note. It certainly narrows down where this could be going wrong.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working Building Features and bugs which affect building ROS help wanted Extra attention is needed
Projects
None yet
Development

No branches or pull requests

2 participants