ros-industrial / ros_qtc_plugin

ROS Qt Creator Plug-in (https://ros-qtc-plugin.readthedocs.io)

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Support ROS-independent builds

marip8 opened this issue · comments

Problem

There are now quite a few tools in the ROS-I ecosystem that are independent of ROS such that they can support both ROS1 and ROS2 layers simultaneously. As of version 12.0.0, it appears that part of the plugin build process (at least for colcon) forces the sourcing of the selected distribution's setup.bash file. This is a problem for me because I want to build a ROS-independent project in Qt Creator and then build both the ROS1 and ROS2 layers as separate projects in Qt, using the ROS-independent project as an underlay.

Currently, my ROS-independent build (using colcon) is being forced to source ROS2 (I had to choose a distro, so I chose a ROS2 one), and my chained ROS1 workspace build (using colcon) fails because sourcing the upstream workspace only lets it know about ROS2 things.

What I tried to get around this issue

  • I tried manually unsetting build environment variables like ROS_DISTRO, etc. before building.
    • These environment variables reappear instantly when I build or click the Source workspace button, so it appears that the build process sources /opt/ros/<distro>/setup.bash during the build
  • I tried removing the <Distribution /> key from the .workspace file, manually building the workspace first, then clicking the Source workspace button in the build dialog before rebuilding
    • This appears to source each available ROS distro, because I see build environment variables in the build dialog that relate to both ROS1 and ROS2 distros that I have installed on my machine

Desired solution

I think the ideal solution would be to add an empty string or "None" option in the Distribution drop down box in the ROS project configuration menu and make the sourcing of /opt/ros/<distro>/setup.bash optional based on the value of this field.

When I create a new "ROS Project", the Distribution: drop-down menu does not list a ROS distribution initially:
qt_creator_ros_workspace
and the .workspace file also contains no distribution:

<?xml version="1.0"?>
<Workspace>
    <Distribution path=""/>
    <DefaultBuildSystem value="2"/>
</Workspace>

Does this not work in your case?

I should have clarified that I did not have this issue when I was using the snap distributed version of Qt Creator and this plugin. What you described above is also what I would see when I used the snap version.

I recently switched from the snap version to the nominal Qt installer version (i.e., from their website); the problems I described above occur in the Qt installer version of Qt Creator. It does find both distributions of ROS by default (maybe the snap version can't find them because it can't access /opt from its sandbox directory?), so I'm forced to choose one or the other.

When I set <Distribution path="">, I get the following message: [ROS Error] Project file distribution [] is not installed. Setting to [/opt/ros/foxy], if incorrect modify project file [calibration_ws.workspace]. Then I think the plugin sources the setup.bash file of the "default" version of ROS every time it builds because I see ROS environment variables in the build dialog and in a terminal after I source the workspace

I think this might be the code to change to get around this issue:

content.distribution = Utils::FilePath::fromString(attributes.value(QLatin1String("path")).toString());
if (!distributions.empty() && !distributions.contains(content.distribution))
{
Core::MessageManager::writeFlashing(QObject::tr("[ROS Error] Project file distribution [%1] is not installed. Setting to [%2], if incorrect modify project file [%3].").arg(content.distribution.toString(), distributions.first().toString(), filePath.fileName()));
content.distribution = distributions.first();
}

Can you send a PR that implements the feature you need?

I also noticed that when I change the entry in the Distribution: drop-down list to something with a path, then I cannot change back to an empty entry. To make this explicit and more robust, the list should contain an explicit empty entry.

Can you send a PR that implements the feature you need?

Sure. I opened the issue without a PR mostly because I wasn't sure what all files needed to be changed and thought you or @Levi-Armstrong might know of a better solution.

I added that feature to the upcoming Qt Creator 13 plugin: #495. Please test and let me know if this works or you.