Skip to content

Commit fa741e5

Browse files
fmauchOberacda
andauthored
Cleanup environment before sourcing (#24)
When sourcing an environment, the shell env now gets cleaned of any modifications done to the variables that robot_folders manipulates. This way, users can source an environment in any shell. If users want to explicitly source multiple environments, they should do that through underlays. Co-authored-by: David Oberacker <[email protected]>
1 parent dc6208d commit fa741e5

File tree

3 files changed

+39
-3
lines changed

3 files changed

+39
-3
lines changed

bin/rob_folders_source.sh

+10-2
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,9 @@ if [ -z "$ROB_FOLDERS_ACTIVE_ENV" ]; then
4949
export ROB_FOLDERS_EMPTY_LD_LIBRARY_PATH=${LD_LIBRARY_PATH}
5050
export ROB_FOLDERS_EMPTY_QML_IMPORT_PATH=${QML_IMPORT_PATH}
5151
export ROB_FOLDERS_EMPTY_PYTHONPATH=${PYTHONPATH}
52+
export ROB_FOLDERS_EMPTY_AMENT_PREFIX_PATH=${AMENT_PREFIX_PATH}
53+
export ROB_FOLDERS_EMPTY_COLCON_PREFIX_PATH=${COLCON_PREFIX_PATH}
54+
export ROB_FOLDERS_EMPTY_PS1=${PS1}
5255

5356
if [ ! -z "${ROB_FOLDERS_EMPTY_CMAKE_PATH}" ] && [ -z $ROB_FOLDERS_IGNORE_CMAKE_PREFIX_PATH ]
5457
then
@@ -127,6 +130,8 @@ reset_environment()
127130
export LD_LIBRARY_PATH=${ROB_FOLDERS_EMPTY_LD_LIBRARY_PATH}
128131
export QML_IMPORT_PATH=${ROB_FOLDERS_EMPTY_QML_IMPORT_PATH}
129132
export PYTHONPATH=${ROB_FOLDERS_EMPTY_PYTHONPATH}
133+
export AMENT_PREFIX_PATH=${ROB_FOLDERS_EMPTY_AMENT_PREFIX_PATH}
134+
export COLCON_PREFIX_PATH=${ROB_FOLDERS_EMPTY_COLCON_PREFIX_PATH}
130135
}
131136

132137

@@ -159,16 +164,19 @@ fzirob()
159164

160165
if [ $? -eq 0 ]; then
161166
if [ $1 = "change_environment" ] && [ "$2" != "--help" ]; then
167+
reset_environment
162168
checkout_dir=$(rob_folders get_checkout_base_dir)
163169

164170
if [ -f ${checkout_dir}/.cur_env ]; then
165171
# Since the python command writes the .cur_env file there is a race condition when
166172
# running change_environment commands in parallel. Thus it can happen that reading the
167173
# file returns an empty value. This race condition only occurs on a very high io load
168174
# and usually this while look should only be entered once.
175+
ROB_FOLDERS_ACTIVE_ENV=$(cat "${checkout_dir}"/.cur_env) || true
169176
while [ -z "$ROB_FOLDERS_ACTIVE_ENV" ]; do
170-
export ROB_FOLDERS_ACTIVE_ENV=$(cat ${checkout_dir}/.cur_env)
177+
ROB_FOLDERS_ACTIVE_ENV=$(cat "${checkout_dir}"/.cur_env) || true
171178
done
179+
export ROB_FOLDERS_ACTIVE_ENV
172180
environment_dir="${checkout_dir}/${ROB_FOLDERS_ACTIVE_ENV}"
173181
if [ -f ${environment_dir}/setup.sh ]; then
174182
source ${environment_dir}/setup.sh
@@ -186,7 +194,7 @@ fzirob()
186194
if [ -z "${ROB_FOLDERS_DISABLE_PROMPT_MODIFICATION:-}" ] ; then
187195
env_prompt="[${ROB_FOLDERS_ACTIVE_ENV}]"
188196
if [ -n "${PS1##*"$env_prompt"*}" ]; then
189-
PS1="${env_prompt} ${PS1:-}"
197+
PS1="${env_prompt} ${ROB_FOLDERS_EMPTY_PS1:-}"
190198
export PS1
191199
fi
192200
fi

bin/source_environment.sh

+3-1
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@ fi
7373

7474
if [ -z ${rob_folders_overlay+x} ]; then
7575
echo "Sourcing environment '$environment_dir'"
76-
ROB_FOLDERS_ROOT_ENV=$environment_dir
76+
export ROB_FOLDERS_ROOT_ENV=$environment_dir
7777
fi
7878

7979
# This is the environment's name, which we will print out later
@@ -130,6 +130,8 @@ if [ -d $environment_dir ]; then
130130
export LD_LIBRARY_PATH=${ROB_FOLDERS_EMPTY_LD_LIBRARY_PATH}
131131
export QML_IMPORT_PATH=${ROB_FOLDERS_EMPTY_QML_IMPORT_PATH}
132132
export PYTHONPATH=${ROB_FOLDERS_EMPTY_PYTHONPATH}
133+
export AMENT_PREFIX_PATH=${ROB_FOLDERS_EMPTY_AMENT_PREFIX_PATH}
134+
export COLCON_PREFIX_PATH=${ROB_FOLDERS_EMPTY_COLCON_PREFIX_PATH}
133135
fi
134136
fi
135137

docs/usage.rst

+26
Original file line numberDiff line numberDiff line change
@@ -81,13 +81,39 @@ To activate or source an environment, use the ``fzirob change_environment
8181
ENV_NAME`` command. This command sources the appropriate setup scripts of the
8282
environment depending on its contents.
8383

84+
8485
You can use tab completion on the environments so typing ``fzirob
8586
change_environment`` and then pressing :kbd:`Tab` should list all environments
8687
present.
8788

8889
Executing ``fzirob change_environment`` without any environment specified will
8990
source the most recently sourced environment.
9091

92+
.. note::
93+
94+
Using ``fzirob change_environment`` will reset your shell environment before sourcing a
95+
``robot_folders`` environment. Specifically, the following variables will be reset to the state
96+
they have been at the point when robot_folders was sourced (the ``rob_folders_source.sh`` file,
97+
usually sourced in the ``~/.bashrc`` file).
98+
99+
* ``CMAKE_PATH``
100+
* ``PATH``
101+
* ``LD_LIBRARY_PATH``
102+
* ``QML_IMPORT_PATH``
103+
* ``PYTHONPATH``
104+
* ``AMENT_PREFIX_PATH``
105+
* ``COLCON_PREFIX_PATH``
106+
* ``PS1``
107+
108+
109+
Adding custom source commands
110+
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
111+
112+
In addition to the environment's workspace setup files, each environment contains a
113+
``setup_local.sh`` file that will get sourced during the ``change_environment`` call after the
114+
workspaces in an environment have been sourced.
115+
116+
91117
Using underlay environments
92118
---------------------------
93119

0 commit comments

Comments
 (0)