Skip to content

Commit

Permalink
Add additional parameterization options to the ros2.repos generation …
Browse files Browse the repository at this point in the history
…script (issue ros2#158)
  • Loading branch information
eholum committed Jun 27, 2024
1 parent 41e8e0f commit 3e1e200
Show file tree
Hide file tree
Showing 2 changed files with 130 additions and 24 deletions.
5 changes: 4 additions & 1 deletion Earthfile
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,10 @@ repos-file:
COPY excluded-pkgs.txt ./
COPY spaceros-pkgs.txt ./
COPY spaceros.repos ./
RUN --no-cache sh scripts/generate-repos.sh
RUN --no-cache sh scripts/generate-repos.sh \
--outfile ros2.repos \
--packages spaceros-pkgs.txt \
--excluded-packages excluded-pkgs.txt
RUN --no-cache ruby scripts/merge-repos.rb

# Save the generated .repos file
Expand Down
149 changes: 126 additions & 23 deletions scripts/generate-repos.sh
Original file line number Diff line number Diff line change
@@ -1,37 +1,140 @@
#!/bin/sh
#!/bin/bash

usage() {
echo "$0 [OUTPUT_FILENAME]"
set -e

echo " Generate a spaceros repos file containing packages listed in spaceros-pkgs.txt"
echo " and their dependencies, excluding packages in excluded-pkgs.txt"
echo " Set the ROSDISTRO environment variable to change the target ROS distribution."
echo " By default it is 'humble'."
exit 0
# Function to display usage information
usage() {
echo "Generate .repos file with list of SpaceROS repositories to clone"
echo "Usage: $0 --packages PACKAGES --outfile OUTFILE [--excluded-packages EXCLUDED_PACKAGES] [--repos REPOS] [--rosdistro ROSDISTRO] [--upstream UPSTREAM] [--exclude-installed EXCLUDE_INSTALLED]"
echo " --outfile The output file"
echo " --packages File containing a list of ROS packages to include"
echo " --repos File containing a list of ROS repos to use."
echo " Use as alternative to 'packages', rosinstall can generate .repos file from list of repos instead of list of packages"
echo " --excluded-packages File containing a list of packages to exclude [optional] "
echo " --rosdistro ROS2 distribution (default: humble)"
echo " --upstream Specify whether to use version tags of upstream repositories (default: true)"
echo " --exclude-installed Whether to exclude already installed packages from .repos file. Installed workspaces must be sourced to make it work (default: true)"
echo " -h, --help Display this help and exit"
exit 1
}

OUTFILE=${1:-ros2.repos}
ROSDISTRO=${ROSDISTRO:-humble}
# Initialize variables with default values
rosdistro="humble"
packages=""
outfile=""
excluded_packages=""
repos=""
upstream="true"
exclude_installed="true"
ARGS=$(getopt -o h -l help,packages:,outfile:,excluded-packages:,repos:,rosdistro:,upstream:,exclude-installed: -n "$0" -- "$@")
if [ $? -ne 0 ]; then
usage
fi
eval set -- "$ARGS"

# Parse command-line arguments
while true; do
case "$1" in
-h|--help )
usage
;;
--packages )
# change newlines to whitespaces
packages=$(echo $2 | tr "\n" " ")
shift 2
;;
--outfile )
outfile=$2
shift 2
;;
--excluded-packages )
# change newlines to whitespaces
excluded_packages=$(echo $2 | tr "\n" " ")
shift 2
;;
--repos )
# change newlines to whitespaces
repos=$(echo $2 | tr "\n" " ")
shift 2
;;
--rosdistro )
rosdistro=$2
shift 2
;;
--upstream )
upstream=$2
shift 2
;;
--exclude-installed )
exclude_installed=$2
shift 2
;;
-- )
shift
break
;;
* )
echo "Invalid argument!"
usage
exit 1
;;
esac
done

# Check if all required arguments are provided
if [ -z "${packages}" ] && [ -z "${repos}" ]; then
echo "Error: Either packages or repos (or both) have to be specified"
usage
fi

if [ -z "${outfile}" ]; then
echo "Error: Required argument outfile missing"
usage
fi

# Define the command for generating rosinstall
GENERATE_CMD=rosinstall_generator

# Use the repos file format rather than rosinstall format.
GENERATE_CMD="$GENERATE_CMD --format repos"
# Set rosdistro. Overrideable with ROSDISTRO environment variable.
GENERATE_CMD="$GENERATE_CMD --rosdistro $ROSDISTRO"
GENERATE_CMD="${GENERATE_CMD} --format repos"

# Set rosdistro.
GENERATE_CMD="${GENERATE_CMD} --rosdistro ${rosdistro}"

# Include all dependencies
GENERATE_CMD="$GENERATE_CMD --deps"
GENERATE_CMD="${GENERATE_CMD} --deps"

# Use version tags of upstream repositories
GENERATE_CMD="$GENERATE_CMD --upstream"
if [ "$upstream" = "true" ]; then
GENERATE_CMD="${GENERATE_CMD} --upstream"
fi

# Exclude packages which we do not want to incorporate into Space ROS
excluded_pkgs=$(cat ${excluded_packages})
if [ "$exclude_installed" = "true" ]; then
# paths to packages are stored in AMENT_PREFIX_PATH,
# however rosinstall_generator expects ROS_PACKAGE_PATH variable to be set
export ROS_PACKAGE_PATH=${AMENT_PREFIX_PATH}
GENERATE_CMD="${GENERATE_CMD} --exclude ${excluded_pkgs} --"
else
GENERATE_CMD="${GENERATE_CMD} --exclude ${excluded_pkgs} --"
fi

# include additional repos along specified packages'
if [ ! -z "${repos}" ]; then
space_ros_repos=$(cat ${repos})
GENERATE_CMD="${GENERATE_CMD} --repos ${repos} --"
fi

if [ ! -z "${packages}" ]; then
spaceros_pkgs=$(cat ${packages})
GENERATE_CMD="${GENERATE_CMD} -- ${spaceros_pkgs}"
fi

# Exclude packages which we don't incorporate into Space ROS
excluded_pkgs=$(cat excluded-pkgs.txt)
GENERATE_CMD="$GENERATE_CMD --exclude $excluded_pkgs --"
echo "Generating .repos file with command:"
echo ${GENERATE_CMD}

# Use Space ROS packages as base package list
# This list should stay small, rosinstall_generator will resolve dependencies.
spaceros_pkgs=$(cat spaceros-pkgs.txt)
GENERATE_CMD="$GENERATE_CMD $spaceros_pkgs"
# Generate rosinstall file
${GENERATE_CMD} > ${outfile}

$GENERATE_CMD > $OUTFILE
echo "rosinstall file generated: ${outfile}"

0 comments on commit 3e1e200

Please sign in to comment.