local_setup.zsh 4.1 KB

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