# generated from colcon_bash/shell/template/prefix_chain.bash.em# This script extends the environment with the environment of other prefix# paths which were sourced when this file was generated as well as all packages# contained in this prefix path.# function to source another script with conditional trace output# first argument: the path of the script_colcon_prefix_chain_bash_source_script(){if[-f"$1"];thenif[-n"$COLCON_TRACE"];thenecho"# . \"$1\""fi."$1"elseecho"not found: \"$1\""1>&2fi}# source chained prefixes# setting COLCON_CURRENT_PREFIX avoids determining the prefix in the sourced scriptCOLCON_CURRENT_PREFIX="/opt/tros"
_colcon_prefix_chain_bash_source_script "$COLCON_CURRENT_PREFIX/local_setup.bash"# source this prefix# setting COLCON_CURRENT_PREFIX avoids determining the prefix in the sourced scriptCOLCON_CURRENT_PREFIX="$(builtincd"`dirname"${BASH_SOURCE[0]}"`"> /dev/null &&pwd)"
_colcon_prefix_chain_bash_source_script "$COLCON_CURRENT_PREFIX/local_setup.bash"unset COLCON_CURRENT_PREFIX
unset _colcon_prefix_chain_bash_source_script
# generated from colcon_bash/shell/template/prefix_chain.bash.em:解释了这个脚本是由colcon工具自动生成的(每次执行colcon build会在install下自动生成该脚本)
# source this prefix# setting COLCON_CURRENT_PREFIX avoids determining the prefix in the sourced scriptCOLCON_CURRENT_PREFIX="$(builtincd"`dirname"${BASH_SOURCE[0]}"`"> /dev/null &&pwd)"
_colcon_prefix_chain_bash_source_script "$COLCON_CURRENT_PREFIX/local_setup.bash"
"$(builtin cd "dirname “${[0]}”" > /dev/null && pwd)"详细看看这一行贼长的东东
# Determine whether the login account is root, if not, switch to the root accountif["$(id-u)"-ne0];thenecho"Please use the 'root' account to log in (default password is 'root'), and re-run 'source /opt/tros/setup.bash'!">&2sufi# generated from colcon_bash/shell/template/prefix.bash.em# This script extends the environment with all packages contained in this# prefix path.# a bash script is able to determine its own path if necessaryif[-z"$COLCON_CURRENT_PREFIX"];then_colcon_prefix_bash_COLCON_CURRENT_PREFIX="$(builtincd"`dirname"${BASH_SOURCE[0]}"`"> /dev/null &&pwd)"else_colcon_prefix_bash_COLCON_CURRENT_PREFIX="$COLCON_CURRENT_PREFIX"fi# 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_bash_prepend_unique_value(){# arguments_listname="$1"_value="$2"# get values from variableeval_values=\"\$$_listname\"
# backup the field separator_colcon_prefix_bash_prepend_unique_value_IFS="$IFS"IFS=":"# start with the new value_all_values="$_value"_contained_value=""# iterate over existing values in the variablefor_itemin$_values;do# ignore empty stringsif[-z"$_item"];thencontinuefi# ignore duplicates of _valueif["$_item"="$_value"];then_contained_value=1continuefi# keep non-duplicate values_all_values="$_all_values:$_item"doneunset _item
if[-z"$_contained_value"];thenif[-n"$COLCON_TRACE"];thenif["$_all_values"="$_value"];thenecho"export $_listname=$_value"elseecho"export $_listname=$_value:\$$_listname"fififiunset _contained_value
# restore the field separatorIFS="$_colcon_prefix_bash_prepend_unique_value_IFS"unset _colcon_prefix_bash_prepend_unique_value_IFS
# export the updated variableevalexport$_listname=\"$_all_values\"
unset _all_values
unset _values
unset _value
unset _listname
}# add this prefix to the COLCON_PREFIX_PATH
_colcon_prefix_bash_prepend_unique_value COLCON_PREFIX_PATH "$_colcon_prefix_bash_COLCON_CURRENT_PREFIX"unset _colcon_prefix_bash_prepend_unique_value
# check environment variable for custom Python executableif[-n"$COLCON_PYTHON_EXECUTABLE"];thenif[!-f"$COLCON_PYTHON_EXECUTABLE"];thenecho"error: COLCON_PYTHON_EXECUTABLE '$COLCON_PYTHON_EXECUTABLE' doesn't exist"return1fi_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 backif[!-f"$_colcon_python_executable"];thenif! /usr/bin/env python3 --version> /dev/null 2> /dev/null;thenecho"error: unable to find python3 executable"return1fi_colcon_python_executable=`/usr/bin/env python3 -c"import sys; print(sys.executable)"`fifi# function to source another script with conditional trace output# first argument: the path of the script_colcon_prefix_sh_source_script(){if[-f"$1"];thenif[-n"$COLCON_TRACE"];thenecho"# . \"$1\""fi."$1"elseecho"not found: \"$1\""1>&2fi}# get all commands in topological order_colcon_ordered_commands="$($_colcon_python_executable "$_colcon_prefix_bash_COLCON_CURRENT_PREFIX/_local_setup_util_sh.py"shbash --merged-install)"unset _colcon_python_executable
if[-n"$COLCON_TRACE"];thenecho"$(declare-f _colcon_prefix_sh_source_script)"echo"# Execute generated script:"echo"# <<<"echo"${_colcon_ordered_commands}"echo"# >>>"echo"unset _colcon_prefix_sh_source_script"fieval"${_colcon_ordered_commands}"unset _colcon_ordered_commands
unset _colcon_prefix_sh_source_script
unset _colcon_prefix_bash_COLCON_CURRENT_PREFIX
exportTROS_DISTRO=
# Determine whether the login account is root, if not, switch to the root accountif["$(id-u)"-ne0];thenecho"Please use the 'root' account to log in (default password is 'root'), and re-run 'source /opt/tros/setup.bash'!">&2sufi
# generated from colcon_bash/shell/template/prefix.bash.em# This script extends the environment with all packages contained in this# prefix path.# a bash script is able to determine its own path if necessaryif[-z"$COLCON_CURRENT_PREFIX"];then_colcon_prefix_bash_COLCON_CURRENT_PREFIX="$(builtincd"`dirname"${BASH_SOURCE[0]}"`"> /dev/null &&pwd)"else_colcon_prefix_bash_COLCON_CURRENT_PREFIX="$COLCON_CURRENT_PREFIX"fi
_colcon_prefix_bash_prepend_unique_value函数
紧接着来看看这个长函数
# 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_bash_prepend_unique_value(){# arguments_listname="$1"_value="$2"# get values from variableeval_values=\"\$$_listname\"
# backup the field separator_colcon_prefix_bash_prepend_unique_value_IFS="$IFS"IFS=":"# start with the new value_all_values="$_value"_contained_value=""# iterate over existing values in the variablefor_itemin$_values;do# ignore empty stringsif[-z"$_item"];thencontinuefi# ignore duplicates of _valueif["$_item"="$_value"];then_contained_value=1continuefi# keep non-duplicate values_all_values="$_all_values:$_item"doneunset _item
if[-z"$_contained_value"];thenif[-n"$COLCON_TRACE"];thenif["$_all_values"="$_value"];thenecho"export $_listname=$_value"elseecho"export $_listname=$_value:\$$_listname"fififiunset _contained_value
# restore the field separatorIFS="$_colcon_prefix_bash_prepend_unique_value_IFS"unset _colcon_prefix_bash_prepend_unique_value_IFS
# export the updated variableevalexport$_listname=\"$_all_values\"
unset _all_values
unset _values
unset _value
unset _listname
}
for _item in $_values; dofor循环,_item表示每次循环从$_values拿出一个变量,$_values是需要添加的变量(此函数的第二个参数)
if [ -z "$_item" ]; then:这行代码检查当前值$_item是否为空,如果空就跳
if [ "$_item" = "$_value" ]; then:检查新添加的这个路径是否已经存在了
# iterate over existing values in the variablefor_itemin$_values;do# ignore empty stringsif[-z"$_item"];thencontinuefi# ignore duplicates of _valueif["$_item"="$_value"];then_contained_value=1continuefi# keep non-duplicate values_all_values="$_all_values:$_item"done
然后是这个函数后续部分
unset _item
if[-z"$_contained_value"];thenif[-n"$COLCON_TRACE"];thenif["$_all_values"="$_value"];thenecho"export $_listname=$_value"elseecho"export $_listname=$_value:\$$_listname"fififiunset _contained_value
# restore the field separatorIFS="$_colcon_prefix_bash_prepend_unique_value_IFS"unset _colcon_prefix_bash_prepend_unique_value_IFS
# export the updated variableevalexport$_listname=\"$_all_values\"
unset _all_values
unset _values
unset _value
unset _listname
# add this prefix to the COLCON_PREFIX_PATH
_colcon_prefix_bash_prepend_unique_value COLCON_PREFIX_PATH "$_colcon_prefix_bash_COLCON_CURRENT_PREFIX"unset _colcon_prefix_bash_prepend_unique_value
# check environment variable for custom Python executableif[-n"$COLCON_PYTHON_EXECUTABLE"];thenif[!-f"$COLCON_PYTHON_EXECUTABLE"];thenecho"error: COLCON_PYTHON_EXECUTABLE '$COLCON_PYTHON_EXECUTABLE' doesn't exist"return1fi_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 backif[!-f"$_colcon_python_executable"];thenif! /usr/bin/env python3 --version> /dev/null 2> /dev/null;thenecho"error: unable to find python3 executable"return1fi_colcon_python_executable=`/usr/bin/env python3 -c"import sys; print(sys.executable)"`fifi
上述代码逻辑很简单就是判断是否指定了解释器路径,没有就使用默认的`/usr/bin/python3
if ! /usr/bin/env python3 --version > /dev/null 2> /dev/null; then检测python3是否存在
# function to source another script with conditional trace output# first argument: the path of the script_colcon_prefix_sh_source_script(){if[-f"$1"];thenif[-n"$COLCON_TRACE"];thenecho"# . \"$1\""fi."$1"elseecho"not found: \"$1\""1>&2fi}
来看看最后的部分,获取所有命令,并执行
# get all commands in topological order_colcon_ordered_commands="$($_colcon_python_executable "$_colcon_prefix_bash_COLCON_CURRENT_PREFIX/_local_setup_util_sh.py"shbash --merged-install)"unset _colcon_python_executable
if[-n"$COLCON_TRACE"];thenecho"$(declare-f _colcon_prefix_sh_source_script)"echo"# Execute generated script:"echo"# <<<"echo"${_colcon_ordered_commands}"echo"# >>>"echo"unset _colcon_prefix_sh_source_script"fieval"${_colcon_ordered_commands}"unset _colcon_ordered_commands
unset _colcon_prefix_sh_source_script
unset _colcon_prefix_bash_COLCON_CURRENT_PREFIX
exportTROS_DISTRO=
_colcon_ordered_commands="$($_colcon_python_executable "$_colcon_prefix_bash_COLCON_CURRENT_PREFIX/_local_setup_util_sh.py" sh bash --merged-install)"这一行调用Python脚本_local_setup_util_sh.py(这个下一期再讲吧),该脚本同样位于当前脚本所在目录下的_colcon_prefix_bash_COLCON_CURRENT_PREFIX目录中。
# generated from colcon_core/shell/template/prefix.sh.em# This script extends the environment with all packages contained in this# prefix path.# since a plain shell script can't determine its own path when being sourced# either use the provided COLCON_CURRENT_PREFIX# or fall back to the build time prefix (if it exists)_colcon_prefix_sh_COLCON_CURRENT_PREFIX="/root/dev_ws/install"if[-z"$COLCON_CURRENT_PREFIX"];thenif[!-d"$_colcon_prefix_sh_COLCON_CURRENT_PREFIX"];thenecho"The build time path \"$_colcon_prefix_sh_COLCON_CURRENT_PREFIX\" doesn't exist. Either source a script for a different shell or set the environment variable \"COLCON_CURRENT_PREFIX\" explicitly."1>&2unset _colcon_prefix_sh_COLCON_CURRENT_PREFIX
return1fielse_colcon_prefix_sh_COLCON_CURRENT_PREFIX="$COLCON_CURRENT_PREFIX"fi# 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_sh_prepend_unique_value(){# arguments_listname="$1"_value="$2"# get values from variableeval_values=\"\$$_listname\"
# backup the field separator_colcon_prefix_sh_prepend_unique_value_IFS="$IFS"IFS=":"# start with the new value_all_values="$_value"_contained_value=""# iterate over existing values in the variablefor_itemin$_values;do# ignore empty stringsif[-z"$_item"];thencontinuefi# ignore duplicates of _valueif["$_item"="$_value"];then_contained_value=1continuefi# keep non-duplicate values_all_values="$_all_values:$_item"doneunset _item
if[-z"$_contained_value"];thenif[-n"$COLCON_TRACE"];thenif["$_all_values"="$_value"];thenecho"export $_listname=$_value"elseecho"export $_listname=$_value:\$$_listname"fififiunset _contained_value
# restore the field separatorIFS="$_colcon_prefix_sh_prepend_unique_value_IFS"unset _colcon_prefix_sh_prepend_unique_value_IFS
# export the updated variableevalexport$_listname=\"$_all_values\"
unset _all_values
unset _values
unset _value
unset _listname
}# add this prefix to the COLCON_PREFIX_PATH
_colcon_prefix_sh_prepend_unique_value COLCON_PREFIX_PATH "$_colcon_prefix_sh_COLCON_CURRENT_PREFIX"unset _colcon_prefix_sh_prepend_unique_value
# check environment variable for custom Python executableif[-n"$COLCON_PYTHON_EXECUTABLE"];thenif[!-f"$COLCON_PYTHON_EXECUTABLE"];thenecho"error: COLCON_PYTHON_EXECUTABLE '$COLCON_PYTHON_EXECUTABLE' doesn't exist"return1fi_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 backif[!-f"$_colcon_python_executable"];thenif! /usr/bin/env python3 --version> /dev/null 2> /dev/null;thenecho"error: unable to find python3 executable"return1fi_colcon_python_executable=`/usr/bin/env python3 -c"import sys; print(sys.executable)"`fifi# function to source another script with conditional trace output# first argument: the path of the script_colcon_prefix_sh_source_script(){if[-f"$1"];thenif[-n"$COLCON_TRACE"];thenecho"# . \"$1\""fi."$1"elseecho"not found: \"$1\""1>&2fi}# get all commands in topological order_colcon_ordered_commands="$($_colcon_python_executable "$_colcon_prefix_sh_COLCON_CURRENT_PREFIX/_local_setup_util_sh.py"sh)"unset _colcon_python_executable
if[-n"$COLCON_TRACE"];thenecho"_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
}"echo"# Execute generated script:"echo"# <<<"echo"${_colcon_ordered_commands}"echo"# >>>"echo"unset _colcon_prefix_sh_source_script"fieval"${_colcon_ordered_commands}"unset _colcon_ordered_commands
unset _colcon_prefix_sh_source_script
unset _colcon_prefix_sh_COLCON_CURRENT_PREFIX
先来看看第一部分
# since a plain shell script can't determine its own path when being sourced# either use the provided COLCON_CURRENT_PREFIX# or fall back to the build time prefix (if it exists)_colcon_prefix_sh_COLCON_CURRENT_PREFIX="/root/dev_ws/install"if[-z"$COLCON_CURRENT_PREFIX"];thenif[!-d"$_colcon_prefix_sh_COLCON_CURRENT_PREFIX"];thenecho"The build time path \"$_colcon_prefix_sh_COLCON_CURRENT_PREFIX\" doesn't exist. Either source a script for a different shell or set the environment variable \"COLCON_CURRENT_PREFIX\" explicitly."1>&2unset _colcon_prefix_sh_COLCON_CURRENT_PREFIX
return1fielse_colcon_prefix_sh_COLCON_CURRENT_PREFIX="$COLCON_CURRENT_PREFIX"fi
# 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_sh_prepend_unique_value(){# arguments_listname="$1"_value="$2"# get values from variableeval_values=\"\$$_listname\"
# backup the field separator_colcon_prefix_sh_prepend_unique_value_IFS="$IFS"IFS=":"# start with the new value_all_values="$_value"_contained_value=""# iterate over existing values in the variablefor_itemin$_values;do# ignore empty stringsif[-z"$_item"];thencontinuefi# ignore duplicates of _valueif["$_item"="$_value"];then_contained_value=1continuefi# keep non-duplicate values_all_values="$_all_values:$_item"doneunset _item
if[-z"$_contained_value"];thenif[-n"$COLCON_TRACE"];thenif["$_all_values"="$_value"];thenecho"export $_listname=$_value"elseecho"export $_listname=$_value:\$$_listname"fififiunset _contained_value
# restore the field separatorIFS="$_colcon_prefix_sh_prepend_unique_value_IFS"unset _colcon_prefix_sh_prepend_unique_value_IFS
# export the updated variableevalexport$_listname=\"$_all_values\"
unset _all_values
unset _values
unset _value
unset _listname
}
# add this prefix to the COLCON_PREFIX_PATH
_colcon_prefix_sh_prepend_unique_value COLCON_PREFIX_PATH "$_colcon_prefix_sh_COLCON_CURRENT_PREFIX"unset _colcon_prefix_sh_prepend_unique_value
# check environment variable for custom Python executableif[-n"$COLCON_PYTHON_EXECUTABLE"];thenif[!-f"$COLCON_PYTHON_EXECUTABLE"];thenecho"error: COLCON_PYTHON_EXECUTABLE '$COLCON_PYTHON_EXECUTABLE' doesn't exist"return1fi_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 backif[!-f"$_colcon_python_executable"];thenif! /usr/bin/env python3 --version> /dev/null 2> /dev/null;thenecho"error: unable to find python3 executable"return1fi_colcon_python_executable=`/usr/bin/env python3 -c"import sys; print(sys.executable)"`fifi
那么最后一部分,其实和上述之前的代码大差不差,那我也不多说了
# function to source another script with conditional trace output# first argument: the path of the script_colcon_prefix_sh_source_script(){if[-f"$1"];thenif[-n"$COLCON_TRACE"];thenecho"# . \"$1\""fi."$1"elseecho"not found: \"$1\""1>&2fi}# get all commands in topological order_colcon_ordered_commands="$($_colcon_python_executable "$_colcon_prefix_sh_COLCON_CURRENT_PREFIX/_local_setup_util_sh.py"sh)"unset _colcon_python_executable
if[-n"$COLCON_TRACE"];thenecho"_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
}"echo"# Execute generated script:"echo"# <<<"echo"${_colcon_ordered_commands}"echo"# >>>"echo"unset _colcon_prefix_sh_source_script"fieval"${_colcon_ordered_commands}"unset _colcon_ordered_commands
unset _colcon_prefix_sh_source_script
unset _colcon_prefix_sh_COLCON_CURRENT_PREFIX