Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow chaining of workspaces #24

Merged
merged 5 commits into from
Jun 27, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 10 additions & 2 deletions bin/rob_folders_source.sh
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,9 @@ if [ -z "$ROB_FOLDERS_ACTIVE_ENV" ]; then
export ROB_FOLDERS_EMPTY_LD_LIBRARY_PATH=${LD_LIBRARY_PATH}
export ROB_FOLDERS_EMPTY_QML_IMPORT_PATH=${QML_IMPORT_PATH}
export ROB_FOLDERS_EMPTY_PYTHONPATH=${PYTHONPATH}
export ROB_FOLDERS_EMPTY_AMENT_PREFIX_PATH=${AMENT_PREFIX_PATH}
export ROB_FOLDERS_EMPTY_COLCON_PREFIX_PATH=${COLCON_PREFIX_PATH}
export ROB_FOLDERS_EMPTY_PS1=${PS1}

if [ ! -z "${ROB_FOLDERS_EMPTY_CMAKE_PATH}" ] && [ -z $ROB_FOLDERS_IGNORE_CMAKE_PREFIX_PATH ]
then
Expand Down Expand Up @@ -127,6 +130,8 @@ reset_environment()
export LD_LIBRARY_PATH=${ROB_FOLDERS_EMPTY_LD_LIBRARY_PATH}
export QML_IMPORT_PATH=${ROB_FOLDERS_EMPTY_QML_IMPORT_PATH}
export PYTHONPATH=${ROB_FOLDERS_EMPTY_PYTHONPATH}
export AMENT_PREFIX_PATH=${ROB_FOLDERS_EMPTY_AMENT_PREFIX_PATH}
export COLCON_PREFIX_PATH=${ROB_FOLDERS_EMPTY_COLCON_PREFIX_PATH}
}


Expand Down Expand Up @@ -159,16 +164,19 @@ fzirob()

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

if [ -f ${checkout_dir}/.cur_env ]; then
# Since the python command writes the .cur_env file there is a race condition when
# running change_environment commands in parallel. Thus it can happen that reading the
# file returns an empty value. This race condition only occurs on a very high io load
# and usually this while look should only be entered once.
ROB_FOLDERS_ACTIVE_ENV=$(cat "${checkout_dir}"/.cur_env) || true
while [ -z "$ROB_FOLDERS_ACTIVE_ENV" ]; do
export ROB_FOLDERS_ACTIVE_ENV=$(cat ${checkout_dir}/.cur_env)
ROB_FOLDERS_ACTIVE_ENV=$(cat "${checkout_dir}"/.cur_env) || true
done
export ROB_FOLDERS_ACTIVE_ENV
environment_dir="${checkout_dir}/${ROB_FOLDERS_ACTIVE_ENV}"
if [ -f ${environment_dir}/setup.sh ]; then
source ${environment_dir}/setup.sh
Expand All @@ -186,7 +194,7 @@ fzirob()
if [ -z "${ROB_FOLDERS_DISABLE_PROMPT_MODIFICATION:-}" ] ; then
env_prompt="[${ROB_FOLDERS_ACTIVE_ENV}]"
if [ -n "${PS1##*"$env_prompt"*}" ]; then
PS1="${env_prompt} ${PS1:-}"
PS1="${env_prompt} ${ROB_FOLDERS_EMPTY_PS1:-}"
export PS1
fi
fi
Expand Down
4 changes: 3 additions & 1 deletion bin/source_environment.sh
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ fi

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

# This is the environment's name, which we will print out later
Expand Down Expand Up @@ -130,6 +130,8 @@ if [ -d $environment_dir ]; then
export LD_LIBRARY_PATH=${ROB_FOLDERS_EMPTY_LD_LIBRARY_PATH}
export QML_IMPORT_PATH=${ROB_FOLDERS_EMPTY_QML_IMPORT_PATH}
export PYTHONPATH=${ROB_FOLDERS_EMPTY_PYTHONPATH}
export AMENT_PREFIX_PATH=${ROB_FOLDERS_EMPTY_AMENT_PREFIX_PATH}
export COLCON_PREFIX_PATH=${ROB_FOLDERS_EMPTY_COLCON_PREFIX_PATH}
fi
fi

Expand Down
26 changes: 26 additions & 0 deletions docs/usage.rst
Original file line number Diff line number Diff line change
Expand Up @@ -81,13 +81,39 @@ To activate or source an environment, use the ``fzirob change_environment
ENV_NAME`` command. This command sources the appropriate setup scripts of the
environment depending on its contents.


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

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

.. note::

Using ``fzirob change_environment`` will reset your shell environment before sourcing a
``robot_folders`` environment. Specifically, the following variables will be reset to the state
they have been at the point when robot_folders was sourced (the ``rob_folders_source.sh`` file,
usually sourced in the ``~/.bashrc`` file).

* ``CMAKE_PATH``
* ``PATH``
* ``LD_LIBRARY_PATH``
* ``QML_IMPORT_PATH``
* ``PYTHONPATH``
* ``AMENT_PREFIX_PATH``
* ``COLCON_PREFIX_PATH``
* ``PS1``


Adding custom source commands
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

In addition to the environment's workspace setup files, each environment contains a
``setup_local.sh`` file that will get sourced during the ``change_environment`` call after the
workspaces in an environment have been sourced.


Using underlay environments
---------------------------

Expand Down
Loading