colcon / colcon-cmake

Extension for colcon to support CMake packages
http://colcon.readthedocs.io
Apache License 2.0
16 stars 26 forks source link

Option to concatenate multiple compile_commands.json files into a single file #61

Closed youtalk closed 4 years ago

youtalk commented 4 years ago

When we run colcon build with the following cmake-args option, we can got compile_commands.json for each package.

colcon build --cmake-args -DCMAKE_EXPORT_COMPILE_COMMANDS=ON

It's very useful to use auto complete of programming ROS / ROS 2 by the language server protocol of clangd. It'll be even more useful to develop multiple packages at a time if the multiple compile_commands.json to unify one compile_commands.json.

I'm thinking about adding a --cmake-concat-compile-commands option. How do you think about it? I try to implement it soon.

Thanks to the colcon extensibility, my development experience is better than before!

Maverobot commented 4 years ago

Why is this issue closed? I would be really happy to see this being implemented and merged into the master :)

dirk-thomas commented 4 years ago

I don't know why the author of the ticket closed it right after creating it. But the feature has recently been implemented, see #69.

Maverobot commented 4 years ago

@dirk-thomas Thanks for pointing me to that newly implemented feature.

However, I failed to understand how to use it. It seems to be related to event handler. Is there a documentation about how to use this feature?

dirk-thomas commented 4 years ago

Is there a documentation about how to use this feature?

The referenced PR also references a pull request for the documentation. And that is rendered here: https://colcon.readthedocs.io/en/released/user/how-to.html#cmake-packages-generating-compile-commands-json

Maverobot commented 4 years ago

@dirk-thomas Thanks. I forgot to mention that I have tried

colcon build --cmake-args -DCMAKE_EXPORT_COMPILE_COMMANDS=ON

but it did not create any workspace-level compile_commands.json. Is there anything else that I am missing?

Output of colcon version-check:

colcon-argcomplete 0.3.3: up-to-date
colcon-bash 0.4.2: up-to-date
colcon-cd 0.1.1: up-to-date
colcon-cmake 0.2.19: newer version available (0.2.20)
colcon-core 0.5.5: newer version available (0.5.6)
colcon-defaults 0.2.4: newer version available (0.2.5)
colcon-devtools 0.2.2: up-to-date
colcon-library-path 0.2.1: up-to-date
colcon-metadata 0.2.4: up-to-date
colcon-notification 0.2.12: up-to-date
colcon-output 0.2.8: newer version available (0.2.9)
colcon-package-information 0.3.2: newer version available (0.3.3)
colcon-package-selection 0.2.5: newer version available (0.2.6)
colcon-parallel-executor 0.2.4: up-to-date
colcon-pkg-config 0.1.0: up-to-date
colcon-powershell 0.3.6: up-to-date
colcon-python-setup-py 0.2.5: up-to-date
colcon-recursive-crawl 0.2.1: up-to-date
colcon-ros 0.3.17: up-to-date
colcon-test-result 0.3.8: up-to-date
colcon-zsh 0.4.0: up-to-date

Maybe I need to update colcon? I am just starting to use ros2 today. Please forgive my stupid questions.

dirk-thomas commented 4 years ago

69 mentions that it is available as of colcon-cmake version 0.2.20 so yes, you need the get the latest version(s).

Maverobot commented 4 years ago

@dirk-thomas It turned out that sudo apt install python3-colcon-common-extensions does not contain the latest versions yet.

Using

pip install -U colcon-common-extensions

gives the latest version and the combination of compile_commands.json works out of the box! Thanks!

dirk-thomas commented 4 years ago

You should not install Python packages via pip if there are Debian packages available. Simply because they will "hide" any future updated coming from Debian packages.

So I highly recommend to uninstall the pip packages and wait for Debian to become available in the mirrored apt repos.

Scoeerg commented 1 year ago

Hi,

on Ubuntu 20.04 LTS using ROS2 Foxy, colcon version-check:

colcon-argcomplete 0.3.3: up-to-date
colcon-bash 0.4.2: up-to-date
colcon-cd 0.1.1: up-to-date
colcon-cmake 0.2.27: up-to-date
colcon-core 0.12.1: up-to-date
colcon-defaults 0.2.8: up-to-date
colcon-devtools 0.2.3: up-to-date
colcon-installed-package-information 0.1.0: up-to-date
colcon-library-path 0.2.1: up-to-date
colcon-metadata 0.2.5: up-to-date
colcon-notification 0.2.15: up-to-date
colcon-output 0.2.13: up-to-date
colcon-override-check 0.0.1: up-to-date
colcon-package-information 0.3.3: up-to-date
colcon-package-selection 0.2.10: up-to-date
colcon-parallel-executor 0.2.4: up-to-date
colcon-pkg-config 0.1.0: up-to-date
colcon-powershell 0.3.7: up-to-date
colcon-python-setup-py 0.2.8: up-to-date
colcon-recursive-crawl 0.2.1: up-to-date
colcon-ros 0.3.23: up-to-date
colcon-test-result 0.3.8: up-to-date
colcon-zsh 0.4.0: up-to-date

especially colcon-cmake 0.2.27: up-to-date with

ros2_ws
  └── src
      └── cpp_pubsub
          ├── CMakeLists.txt
          ├── include
          │   └── cpp_pubsub
          ├── package.xml
          └── src

Neither colcon build --cmake-args -DCMAKE_EXPORT_COMPILE_COMMANDS=ON -G Ninja nor colcon build --cmake-args -DCMAKE_EXPORT_COMPILE_COMMANDS=ON produce any ros2_ws/build/compile_commands.json. Output of colcon build --event-handlers console_direct+ --cmake-args -DCMAKE_EXPORT_COMPILE_COMMANDS=ON -G Ninja

Starting >>> cpp_pubsub
-- The C compiler identification is GNU 9.4.0
-- The CXX compiler identification is GNU 9.4.0
-- Check for working C compiler: /usr/bin/cc
-- Check for working C compiler: /usr/bin/cc -- works
-- Detecting C compiler ABI info
-- Detecting C compiler ABI info - done
-- Detecting C compile features
-- Detecting C compile features - done
-- Check for working CXX compiler: /usr/bin/c++
-- Check for working CXX compiler: /usr/bin/c++ -- works
-- Detecting CXX compiler ABI info
-- Detecting CXX compiler ABI info - done      
-- Detecting CXX compile features
-- Detecting CXX compile features - done
-- Found ament_cmake: 0.9.11 (/opt/ros/foxy/share/ament_cmake/cmake)
-- Found PythonInterp: /usr/bin/python3 (found suitable version "3.8.10", minimum required is "3") 
-- Using PYTHON_EXECUTABLE: /usr/bin/python3
-- Found ament_lint_auto: 0.9.8 (/opt/ros/foxy/share/ament_lint_auto/cmake)
-- Added test 'copyright' to check source files copyright and LICENSE
-- Added test 'lint_cmake' to check CMake code style
-- Added test 'xmllint' to check XML markup files
-- Configuring done
-- Generating done
-- Build files have been written to: $mypath/ros_ws/build/cpp_pubsub
ninja: no work to do.
-- Install configuration: ""
-- Installing: $mypath/ros_ws/install/cpp_pubsub/share/ament_index/resource_index/package_run_dependencies/cpp_pubsub
-- Installing: /home/eric/Software/ros_ws/install/cpp_pubsub/share/ament_index/resource_index/parent_prefix_path/cpp_pubsub
-- Installing: $mypath/ros_ws/install/cpp_pubsub/share/cpp_pubsub/environment/ament_prefix_path.sh
-- Installing: $mypath/ros_ws/install/cpp_pubsub/share/cpp_pubsub/environment/ament_prefix_path.dsv
-- Installing: $mypath/ros_ws/install/cpp_pubsub/share/cpp_pubsub/environment/path.sh
-- Installing: $mypath/ros_ws/install/cpp_pubsub/share/cpp_pubsub/environment/path.dsv
-- Installing: $mypath/ros_ws/install/cpp_pubsub/share/cpp_pubsub/local_setup.bash
-- Installing: $mypath/ros_ws/install/cpp_pubsub/share/cpp_pubsub/local_setup.sh
-- Installing: $mypath/ros_ws/install/cpp_pubsub/share/cpp_pubsub/local_setup.zsh
-- Installing: $mypath/ros_ws/install/cpp_pubsub/share/cpp_pubsub/local_setup.dsv
-- Installing: $mypath/ros_ws/install/cpp_pubsub/share/cpp_pubsub/package.dsv
-- Installing: $mypath/ros_ws/install/cpp_pubsub/share/ament_index/resource_index/packages/cpp_pubsub
-- Installing: $mypath/ros_ws/install/cpp_pubsub/share/cpp_pubsub/cmake/cpp_pubsubConfig.cmake
-- Installing: $mypath/ros_ws/install/cpp_pubsub/share/cpp_pubsub/cmake/cpp_pubsubConfig-version.cmake
-- Installing: $mypath/ros_ws/install/cpp_pubsub/share/cpp_pubsub/package.xml
Finished <<< cpp_pubsub [0.50s]                  

Summary: 1 package finished [0.60s]

Edit: https://github.com/colcon/colcon-cmake/issues/76#issuecomment-609472603 i.e. colcon build --event-handlers console_direct+ --cmake-args -DCMAKE_EXPORT_COMPILE_COMMANDS=ON -G Ninja --no-warn-unused-cli produces the same result.

Any suggestions?

samehmohamed88 commented 11 months ago

I have the exact same issue as @Scoeerg . I've tried on both Ubuntu 20.04 with Foxy and Ubuntu 22.04 with Humble. In both instances, I've installed Ninja with apt-get -y install ninja-build and then ran colcon build --cmake-args -DCMAKE_EXPORT_COMPILE_COMMANDS=ON -G Ninja.

It does not produce a compile_commands.json ... what is going on here?

yvesb04 commented 10 months ago

I am having the exact same issue, no compile_commands.json is getting generated and I have up to date versions

bertulli commented 6 months ago

If you're folloqing the cpp_pubsub tutorial, it may be the intended behaviour, IIUC, have a look here