local_setup.bash 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121
  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. _contained_value=""
  27. # iterate over existing values in the variable
  28. for _item in $_values; do
  29. # ignore empty strings
  30. if [ -z "$_item" ]; then
  31. continue
  32. fi
  33. # ignore duplicates of _value
  34. if [ "$_item" = "$_value" ]; then
  35. _contained_value=1
  36. continue
  37. fi
  38. # keep non-duplicate values
  39. _all_values="$_all_values:$_item"
  40. done
  41. unset _item
  42. if [ -z "$_contained_value" ]; then
  43. if [ -n "$COLCON_TRACE" ]; then
  44. if [ "$_all_values" = "$_value" ]; then
  45. echo "export $_listname=$_value"
  46. else
  47. echo "export $_listname=$_value:\$$_listname"
  48. fi
  49. fi
  50. fi
  51. unset _contained_value
  52. # restore the field separator
  53. IFS="$_colcon_prefix_bash_prepend_unique_value_IFS"
  54. unset _colcon_prefix_bash_prepend_unique_value_IFS
  55. # export the updated variable
  56. eval export $_listname=\"$_all_values\"
  57. unset _all_values
  58. unset _values
  59. unset _value
  60. unset _listname
  61. }
  62. # add this prefix to the COLCON_PREFIX_PATH
  63. _colcon_prefix_bash_prepend_unique_value COLCON_PREFIX_PATH "$_colcon_prefix_bash_COLCON_CURRENT_PREFIX"
  64. unset _colcon_prefix_bash_prepend_unique_value
  65. # check environment variable for custom Python executable
  66. if [ -n "$COLCON_PYTHON_EXECUTABLE" ]; then
  67. if [ ! -f "$COLCON_PYTHON_EXECUTABLE" ]; then
  68. echo "error: COLCON_PYTHON_EXECUTABLE '$COLCON_PYTHON_EXECUTABLE' doesn't exist"
  69. return 1
  70. fi
  71. _colcon_python_executable="$COLCON_PYTHON_EXECUTABLE"
  72. else
  73. # try the Python executable known at configure time
  74. _colcon_python_executable="/usr/bin/python3"
  75. # if it doesn't exist try a fall back
  76. if [ ! -f "$_colcon_python_executable" ]; then
  77. if ! /usr/bin/env python3 --version > /dev/null 2> /dev/null; then
  78. echo "error: unable to find python3 executable"
  79. return 1
  80. fi
  81. _colcon_python_executable=`/usr/bin/env python3 -c "import sys; print(sys.executable)"`
  82. fi
  83. fi
  84. # function to source another script with conditional trace output
  85. # first argument: the path of the script
  86. _colcon_prefix_sh_source_script() {
  87. if [ -f "$1" ]; then
  88. if [ -n "$COLCON_TRACE" ]; then
  89. echo "# . \"$1\""
  90. fi
  91. . "$1"
  92. else
  93. echo "not found: \"$1\"" 1>&2
  94. fi
  95. }
  96. # get all commands in topological order
  97. _colcon_ordered_commands="$($_colcon_python_executable "$_colcon_prefix_bash_COLCON_CURRENT_PREFIX/_local_setup_util_sh.py" sh bash)"
  98. unset _colcon_python_executable
  99. if [ -n "$COLCON_TRACE" ]; then
  100. echo "$(declare -f _colcon_prefix_sh_source_script)"
  101. echo "# Execute generated script:"
  102. echo "# <<<"
  103. echo "${_colcon_ordered_commands}"
  104. echo "# >>>"
  105. echo "unset _colcon_prefix_sh_source_script"
  106. fi
  107. eval "${_colcon_ordered_commands}"
  108. unset _colcon_ordered_commands
  109. unset _colcon_prefix_sh_source_script
  110. unset _colcon_prefix_bash_COLCON_CURRENT_PREFIX