local_setup.bash 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107
  1. # generated from colcon_bash/shell/template/prefix.bash.em
  2. # This script extends the environment with all packages contained in this
  3. # prefix path.
  4. # a bash script is able to determine its own path if necessary
  5. if [ -z "$COLCON_CURRENT_PREFIX" ]; then
  6. _colcon_prefix_bash_COLCON_CURRENT_PREFIX="$(builtin cd "`dirname "${BASH_SOURCE[0]}"`" > /dev/null && pwd)"
  7. else
  8. _colcon_prefix_bash_COLCON_CURRENT_PREFIX="$COLCON_CURRENT_PREFIX"
  9. fi
  10. # function to prepend a value to a variable
  11. # which uses colons as separators
  12. # duplicates as well as trailing separators are avoided
  13. # first argument: the name of the result variable
  14. # second argument: the value to be prepended
  15. _colcon_prefix_bash_prepend_unique_value() {
  16. # arguments
  17. _listname="$1"
  18. _value="$2"
  19. # get values from variable
  20. eval _values=\"\$$_listname\"
  21. # backup the field separator
  22. _colcon_prefix_bash_prepend_unique_value_IFS="$IFS"
  23. IFS=":"
  24. # start with the new value
  25. _all_values="$_value"
  26. # iterate over existing values in the variable
  27. for _item in $_values; do
  28. # ignore empty strings
  29. if [ -z "$_item" ]; then
  30. continue
  31. fi
  32. # ignore duplicates of _value
  33. if [ "$_item" = "$_value" ]; then
  34. continue
  35. fi
  36. # keep non-duplicate values
  37. _all_values="$_all_values:$_item"
  38. done
  39. unset _item
  40. # restore the field separator
  41. IFS="$_colcon_prefix_bash_prepend_unique_value_IFS"
  42. unset _colcon_prefix_bash_prepend_unique_value_IFS
  43. # export the updated variable
  44. eval export $_listname=\"$_all_values\"
  45. unset _all_values
  46. unset _values
  47. unset _value
  48. unset _listname
  49. }
  50. # add this prefix to the COLCON_PREFIX_PATH
  51. _colcon_prefix_bash_prepend_unique_value COLCON_PREFIX_PATH "$_colcon_prefix_bash_COLCON_CURRENT_PREFIX"
  52. unset _colcon_prefix_bash_prepend_unique_value
  53. # check environment variable for custom Python executable
  54. if [ -n "$COLCON_PYTHON_EXECUTABLE" ]; then
  55. if [ ! -f "$COLCON_PYTHON_EXECUTABLE" ]; then
  56. echo "error: COLCON_PYTHON_EXECUTABLE '$COLCON_PYTHON_EXECUTABLE' doesn't exist"
  57. return 1
  58. fi
  59. _colcon_python_executable="$COLCON_PYTHON_EXECUTABLE"
  60. else
  61. # try the Python executable known at configure time
  62. _colcon_python_executable="/usr/bin/python3"
  63. # if it doesn't exist try a fall back
  64. if [ ! -f "$_colcon_python_executable" ]; then
  65. if ! /usr/bin/env python3 --version > /dev/null 2> /dev/null; then
  66. echo "error: unable to find python3 executable"
  67. return 1
  68. fi
  69. _colcon_python_executable=`/usr/bin/env python3 -c "import sys; print(sys.executable)"`
  70. fi
  71. fi
  72. # function to source another script with conditional trace output
  73. # first argument: the path of the script
  74. _colcon_prefix_sh_source_script() {
  75. if [ -f "$1" ]; then
  76. if [ -n "$COLCON_TRACE" ]; then
  77. echo ". \"$1\""
  78. fi
  79. . "$1"
  80. else
  81. echo "not found: \"$1\"" 1>&2
  82. fi
  83. }
  84. # get all commands in topological order
  85. _colcon_ordered_commands="$($_colcon_python_executable "$_colcon_prefix_bash_COLCON_CURRENT_PREFIX/_local_setup_util_sh.py" sh bash)"
  86. unset _colcon_python_executable
  87. if [ -n "$COLCON_TRACE" ]; then
  88. echo "Execute generated script:"
  89. echo "<<<"
  90. echo "${_colcon_ordered_commands}"
  91. echo ">>>"
  92. fi
  93. eval "${_colcon_ordered_commands}"
  94. unset _colcon_ordered_commands
  95. unset _colcon_prefix_sh_source_script
  96. unset _colcon_prefix_bash_COLCON_CURRENT_PREFIX