forked from space-ros/space-ros
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add additional parameterization options to the ros2.repos generation …
…script (issue ros2#158)
- Loading branch information
Showing
2 changed files
with
130 additions
and
24 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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}" |