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

Environment Setup #33

Open
dustingooding opened this issue Jan 19, 2021 · 2 comments
Open

Environment Setup #33

dustingooding opened this issue Jan 19, 2021 · 2 comments
Labels
question Further information is requested

Comments

@dustingooding
Copy link

dustingooding commented Jan 19, 2021

I'm struggling to get a Dockerfile set up with my custom workspace code built and colcon environment automatically configured for a user to "enter" without needing any extra source calls.

In my Dockerfile, I have the following (psuedo) sections:

  1. I have a layer that installs ros-foxy-ros-core=0.9.2-1* in much the same way the official ROS Docker images do.

  2. From (1), I have a layer that sources the ROS workspace and then builds both orocos-toolchain and rtt_ros2_integration from source, in much the same way that the official Orocos Docker images do. The goods of that layer include:

RUN echo "yaml file:///etc/ros/rosdep/orocos-prereqs.yaml" > /etc/ros/rosdep/sources.list.d/10-orocos-prereqs.list && \
    mkdir -p /root/orocos_ws && \
    vcs import --recursive /root/orocos_ws < /root/orocos_ws/orocos_toolchain.repos && \
    # start temporary fix for broken build (https://github.com/orocos-toolchain/orogen/pull/140)
    cd /root/orocos_ws/orocos_toolchain/orogen && \
    git checkout metaruby-rosdep-in-manifest-xml && \
    # end temporary fix for broken build (https://github.com/orocos-toolchain/orogen/pull/140)
    cd /root/orocos_ws/orocos_toolchain && \
    source /opt/ros/${ROS_DISTRO}/local_setup.sh && \
    apt-get update && \
    apt-get install -y \
        ruby \
        && \
    rosdep update && \
    rosdep install -y --from-path . --ignore-src && \
    MAKEFLAGS="${MAKEFLAGS}" \
        colcon build \
            --event-handlers console_direct+ \
            --install-base /opt/orocos/${ROS_DISTRO} \
            --merge-install \
            --cmake-args \
                \ -DBUILD_TESTING=OFF \
                \ -DCMAKE_BUILD_TYPE=Release \
                \ -DENABLE_CORBA=ON \
                \ -DCORBA_IMPLEMENTATION=OMNIORB \
                \ -DOROCOS_INSTALL_INTO_PREFIX_ROOT=ON \
            ${COLCON_ARGS} && \
    mkdir -p /root/orocos_integration_ws/src && \
    vcs import --recursive /root/orocos_integration_ws/src < /root/orocos_integration_ws/orocos_ros2_integration.repos && \
    cd /root/orocos_integration_ws && \
    source /opt/ros/${ROS_DISTRO}/setup.sh && \
    source /opt/orocos/${ROS_DISTRO}/local_setup.sh && \
    # ignore the tests, apparently...
    touch src/rtt_ros2_integration/tests/COLCON_IGNORE && \
    ROS_PACKAGE_PATH=/opt/orocos/${ROS_DISTRO}/share:/opt/ros/${ROS_DISTRO}/share \
        rosdep install -y --from-path . --ignore-src && \
    MAKEFLAGS="${MAKEFLAGS}" \
        colcon build \
            --event-handlers console_direct+ \
            --install-base /opt/orocos/${ROS_DISTRO} \
            --merge-install \
            --cmake-args \
                \ -DBUILD_TESTING=OFF \
                \ -DCMAKE_BUILD_TYPE=Release \
            ${COLCON_ARGS} &&\
    cd /root && \
    rm -rf /root/orocos_ws && \
    rm -rf /root/orocos_integration_ws && \
    rm -rf /var/lib/apt/lists/*
  1. From (2), I have have a layer that sources the Orocos workspace and then builds my custom workspace. The goods of that layer include:
RUN cd /root/custom_ws && \
    source /opt/orocos/${ROS_DISTRO}/setup.sh && \
    colcon build --parallel-workers ${BUILD_JOBS}
  1. And finally, I have a .bashrc file that does get automatically sourced (because I see echos from it in testing), that includes:
if [ -f ~/custom_ws/install/setup.bash ]; then
    source ~/custom_ws/install/setup.bash
    echo "SOURCED"
else
    echo "WARNING: ~/custom_ws/install/setup.bash does not exist"
fi

(and I get SOURCED printed to the screen when I docker run and docker exec).

The trouble is... when I do docker run or docker exec into my image/container, I notice that the RTT_COMPONENT_PATH is incomplete (and my components don't execute correctly).

$ docker run -it my_image
SOURCED
# env | grep RTT_COMPONENT_PATH
RTT_COMPONENT_PATH=/opt/orocos/foxy/lib/orocos:/opt/orocos/foxy/lib/orocos

When I try to run something, I get an error like this:

# ros2 run orocos_examples simple_rtt-gnulinux
0.434 [ ERROR  ][ComponentLoader::importInstalledPackage(package, path_list)] No such package or directory found in search path: orocos_examples. Search path is: /opt/orocos/foxy/lib/orocos:.
0.434 [ ERROR  ][ComponentLoader::importInstalledPackage(package, path_list)] Directories searched include the following:
0.434 [ ERROR  ][ComponentLoader::importInstalledPackage(package, path_list)]  - /opt/orocos/foxy/lib/orocos/orocos_examples
0.434 [ ERROR  ][ComponentLoader::importInstalledPackage(package, path_list)]  - /opt/orocos/foxy/lib/orocos/gnulinux/orocos_examples
0.434 [ ERROR  ][ComponentLoader::importInstalledPackage(package, path_list)]  - ./orocos_examples
0.434 [ ERROR  ][ComponentLoader::importInstalledPackage(package, path_list)]  - ./gnulinux/orocos_examples
Orocos package orocos_examples could not be imported.

If I then source my environment again, my env changes and executable runs.

# source ~/.bashrc
SOURCED
# env | grep RTT_COMPONENT_PATH
RTT_COMPONENT_PATH=/opt/orocos/foxy/lib/orocos:/opt/orocos/foxy/lib/orocos:/root/custom_ws/install/lib/orocos
# ros2 run orocos_examples simple_rtt-gnulinux
Simple [foo]: constructed

I've also noticed that if I source the /opt/orocos/foxy/setup.bash environment, my custom workspace is added... that can't be right...

# env | grep RTT
RTT_COMPONENT_PATH=/opt/orocos/foxy/lib/orocos:/opt/orocos/foxy/lib/orocos
# source /opt/orocos/foxy/setup.bash
# env | grep RTT
RTT_COMPONENT_PATH=/opt/orocos/foxy/lib/orocos:/opt/orocos/foxy/lib/orocos:/root/custom_ws/install/lib/orocos

What am I doing wrong here? Am I not "chaining" my colcon workspaces correctly? Do I need to source my workspace twice? Something else look obviously wrong?

@dustingooding dustingooding added the question Further information is requested label Jan 19, 2021
@dustingooding
Copy link
Author

dustingooding commented Jan 20, 2021

I enabled COLCON_TRACE=1 on the sourcing of my custom_ws environment. On run and exec, I get a long list of export commands and the following things sourced:

. "/opt/ros/foxy/local_setup.bash"
. "/opt/orocos/foxy/local_setup.bash"
. "/opt/orocos/foxy/etc/orocos/setup.sh"
. "/root/custom_ws/install/local_setup.bash"

Between the two /opt/orocos sourcings, I get this:

if [ "$(echo -n $CMAKE_PREFIX_PATH | tail -c 1)" = ":" ]; then export CMAKE_PREFIX_PATH=${CMAKE_PREFIX_PATH%?} ; fi
if [ "$(echo -n $PKG_CONFIG_PATH | tail -c 1)" = ":" ]; then export PKG_CONFIG_PATH=${PKG_CONFIG_PATH%?} ; fi
if [ "$(echo -n $RTT_COMPONENT_PATH | tail -c 1)" = ":" ]; then export RTT_COMPONENT_PATH=${RTT_COMPONENT_PATH%?} ; fi

Now, when I re-source .bashrc after I'm in the container, I get the same list of export commands, except they're all #-ed out (expected)... but the stanza above isn't included between the /opt/orocos sourcings. I don't know if this is just a quirk with how colcon tracing works... but this is again strange to me.

So why isn't the RTT_COMPONENT_PATH variable getting set correctly the first time things are sourced, but is getting set the second time?

@dustingooding
Copy link
Author

dustingooding commented Jan 21, 2021

I think this might be a 🐔 🥚 problem. I'm still seeing that I need to "double source" things. Here's what I think is happening.

I source my built workspace and that then 1) adds the ROS stuff, 2) adds the Orocos stuff (which doesn't see my workspace), and 3) adds my workspace stuff.

Then I source my built workspace a second time and then it 1) adds the ROS stuff, 2) adds the Orocos stuff (which now does see my workspace and adds it to the RTT var), and 3) adds my workspace stuff.

So maybe the solution is to make my custom workspace update the RTT var itself?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
question Further information is requested
Projects
None yet
Development

No branches or pull requests

1 participant