From d99bc6e7b532a3b02b20c59062d7545c4e8cd98a Mon Sep 17 00:00:00 2001 From: Michael Ripperger Date: Thu, 2 Mar 2023 14:27:51 -0600 Subject: [PATCH 1/2] Updated scripts to support ROS-independent builds --- industrial_ci/src/isolation/docker.env | 3 +++ industrial_ci/src/isolation/docker.sh | 11 +++++++++-- industrial_ci/src/ros.sh | 5 ++++- industrial_ci/src/tests/source_tests.sh | 2 +- industrial_ci/src/workspace.sh | 6 +++--- 5 files changed, 20 insertions(+), 7 deletions(-) diff --git a/industrial_ci/src/isolation/docker.env b/industrial_ci/src/isolation/docker.env index 0aed10fe4..d5f11d6e3 100644 --- a/industrial_ci/src/isolation/docker.env +++ b/industrial_ci/src/isolation/docker.env @@ -37,6 +37,7 @@ PYLINT_ARGS PYLINT_CHECK PYLINT_EXCLUDE PYTHONUNBUFFERED +PYTHON_VERSION_NAME ROSDEP_SKIP_KEYS ROSINSTALL_FILENAME ROS_DISTRO @@ -44,6 +45,8 @@ ROS_PYTHON_VERSION ROS_REPO ROS_REPOSITORY_KEY ROS_REPOSITORY_PATH +ROS_VERSION +ROS_VERSION_EOL TARGET_CMAKE_ARGS TARGET_REPO_NAME TARGET_REPO_PATH diff --git a/industrial_ci/src/isolation/docker.sh b/industrial_ci/src/isolation/docker.sh index e354316d1..2f831fae9 100644 --- a/industrial_ci/src/isolation/docker.sh +++ b/industrial_ci/src/isolation/docker.sh @@ -79,8 +79,15 @@ function ici_isolate() { fi if [ -z "${ROS_DISTRO:-}" ]; then - ROS_DISTRO=$(docker image inspect --format "{{.Config.Env}}" "${DOCKER_IMAGE}" | grep -o -P "(?<=ROS_DISTRO=)[a-z]*") || ici_error "ROS_DISTRO is not set" - elif [ "${ROS_DISTRO}" = "false" ]; then + # Attempt to extract ROS_DISTRO from the docker image + ROS_DISTRO=$(docker image inspect --format "{{.Config.Env}}" "${DOCKER_IMAGE}" | grep -o -P "(?<=ROS_DISTRO=)[a-z]*") + if [ -z "${ROS_DISTRO:-}" ]; then + ici_log "Could not extract environment variable 'ROS_DISTRO' from the docker image '${DOCKER_IMAGE}'; proceeding without 'ROS_DISTRO'" + unset ROS_DISTRO + else + ici_log "Extracted 'ROS_DISTRO=${ROS_DISTRO}' from docker image '${DOCKER_IMAGE}'" + fi + elif [ "${ROS_DISTRO:-}" = "false" ]; then unset ROS_DISTRO fi diff --git a/industrial_ci/src/ros.sh b/industrial_ci/src/ros.sh index 473085e96..986997c5d 100644 --- a/industrial_ci/src/ros.sh +++ b/industrial_ci/src/ros.sh @@ -88,6 +88,10 @@ function _set_ros_defaults { _ros2_defaults "jammy" ;; "false") + export BUILDER=${BUILDER:-colcon} + export ROS_VERSION=0 + export ROS_VERSION_EOL=false + export ROS_PYTHON_VERSION=${ROS_PYTHON_VERSION:-3} unset ROS_DISTRO ;; *) @@ -100,7 +104,6 @@ function _set_ros_defaults { elif [ "$ROS_PYTHON_VERSION" = 3 ]; then export PYTHON_VERSION_NAME=python3 fi - } function _use_snapshot() { diff --git a/industrial_ci/src/tests/source_tests.sh b/industrial_ci/src/tests/source_tests.sh index a00b278dc..9ffbafcca 100644 --- a/industrial_ci/src/tests/source_tests.sh +++ b/industrial_ci/src/tests/source_tests.sh @@ -172,7 +172,7 @@ function run_source_tests { ici_step "setup_rosdep" ici_setup_rosdep - extend=${UNDERLAY:?} + extend=${UNDERLAY:-} if [ -n "$UPSTREAM_WORKSPACE" ]; then ici_with_ws "$upstream_ws" ici_build_workspace "upstream" "$extend" "$upstream_ws" diff --git a/industrial_ci/src/workspace.sh b/industrial_ci/src/workspace.sh index 8d2d1fa28..1bb100c29 100644 --- a/industrial_ci/src/workspace.sh +++ b/industrial_ci/src/workspace.sh @@ -322,7 +322,7 @@ function ici_setup_rosdep { if [ "$ROS_DISTRO" = "indigo" ] || [ "$ROS_DISTRO" = "jade" ]; then ici_apt_install "ros-$ROS_DISTRO-roslib" - else + elif [ -n "${ROS_DISTRO:-}" ]; then ici_apt_install "ros-$ROS_DISTRO-ros-environment" fi @@ -331,7 +331,7 @@ function ici_setup_rosdep { fi update_opts=() - if [ -z "${ROSDISTRO_INDEX_URL:-}" ]; then + if [ -z "${ROSDISTRO_INDEX_URL:-}" ] && [ -n "$ROS_DISTRO" ]; then update_opts+=(--rosdistro "$ROS_DISTRO") fi if [ "$ROS_VERSION_EOL" = true ]; then @@ -406,7 +406,7 @@ function ici_source_setup { local extend=$1; shift if [ ! -f "$extend/setup.bash" ]; then if [ "$extend" != "/opt/ros/$ROS_DISTRO" ]; then - ici_error "'$extend' is not a devel/install space" + ici_log "'$extend' is not a devel/install space; skipping source" fi else ici_with_unset_variables source "$extend/setup.bash" From 2f4c8ab919f0aafddd514e586325defabd2911ea Mon Sep 17 00:00:00 2001 From: Michael Ripperger Date: Thu, 2 Mar 2023 14:59:33 -0600 Subject: [PATCH 2/2] Updated documentation --- doc/index.rst | 2 ++ 1 file changed, 2 insertions(+) diff --git a/doc/index.rst b/doc/index.rst index c6cf53d97..88d6ff36c 100644 --- a/doc/index.rst +++ b/doc/index.rst @@ -158,6 +158,8 @@ Required environment variables: * ``ROS_DISTRO``: Version of ROS in all lower case. E.g.: ``indigo``. If it is set in the custom Docker (base) image, it might be omitted in the script call. + * Note: a ROS-independent CI build can be executed if ``ROS_DISTRO=false``. In this case ``/opt/ros/`` will not be sourced or used as the underlay during the build. This can be useful for projects that are used in the ROS ecosystem but do not have an explicit dependency on ROS. + Optional environment variables ++++++++++++++++++++++++++++++++