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