Skip to content

Commit

Permalink
modify logic of sourcing env hooks to provide context of workspace to…
Browse files Browse the repository at this point in the history
… each env hook (#490)
  • Loading branch information
dirk-thomas committed Jul 26, 2013
1 parent a7bedd6 commit a0d699a
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 28 deletions.
26 changes: 21 additions & 5 deletions cmake/templates/_setup_util.py.in
Original file line number Diff line number Diff line change
Expand Up @@ -200,7 +200,9 @@ def find_env_hooks(environ, cmake_prefix_path):
lines.append(comment('found environment hooks in workspaces'))

generic_env_hooks = []
generic_env_hooks_workspace = []
specific_env_hooks = []
specific_env_hooks_workspace = []
generic_env_hooks_by_filename = {}
specific_env_hooks_by_filename = {}
generic_env_hook_ext = 'bat' if IS_WINDOWS else 'sh'
Expand All @@ -212,18 +214,32 @@ def find_env_hooks(environ, cmake_prefix_path):
if os.path.isdir(env_hook_dir):
for filename in sorted(os.listdir(env_hook_dir)):
if filename.endswith('.%s' % generic_env_hook_ext):
generic_env_hooks.append(os.path.join(env_hook_dir, filename))
# remove previous env hook with same name if present
if filename in generic_env_hooks_by_filename:
generic_env_hooks.remove(generic_env_hooks_by_filename[filename])
i = generic_env_hooks.index(generic_env_hooks_by_filename[filename])
generic_env_hooks.pop(i)
generic_env_hooks_workspace.pop(i)
# append env hook
generic_env_hooks.append(os.path.join(env_hook_dir, filename))
generic_env_hooks_workspace.append(workspace)
generic_env_hooks_by_filename[filename] = generic_env_hooks[-1]
elif specific_env_hook_ext is not None and filename.endswith('.%s' % specific_env_hook_ext):
specific_env_hooks.append(os.path.join(env_hook_dir, filename))
# remove previous env hook with same name if present
if filename in specific_env_hooks_by_filename:
specific_env_hooks.remove(specific_env_hooks_by_filename[filename])
i = specific_env_hooks.index(specific_env_hooks_by_filename[filename])
specific_env_hooks.pop(i)
specific_env_hooks_workspace.pop(i)
# append env hook
specific_env_hooks.append(os.path.join(env_hook_dir, filename))
specific_env_hooks_workspace.append(workspace)
specific_env_hooks_by_filename[filename] = specific_env_hooks[-1]
lines.append(assignment('_CATKIN_ENVIRONMENT_HOOKS', os.pathsep.join(generic_env_hooks + specific_env_hooks)))
env_hooks = generic_env_hooks + specific_env_hooks
env_hooks_workspace = generic_env_hooks_workspace + specific_env_hooks_workspace
count = len(env_hooks)
lines.append(assignment('_CATKIN_ENVIRONMENT_HOOKS_COUNT', count))
for i in range(count):
lines.append(assignment('_CATKIN_ENVIRONMENT_HOOKS_%d' % i, env_hooks[i]))
lines.append(assignment('_CATKIN_ENVIRONMENT_HOOKS_%d_WORKSPACE' % i, env_hooks_workspace[i]))
return lines


Expand Down
34 changes: 11 additions & 23 deletions cmake/templates/setup.sh.in
Original file line number Diff line number Diff line change
Expand Up @@ -47,30 +47,18 @@ CATKIN_SHELL=$CATKIN_SHELL "$_SETUP_UTIL" $@ > $_SETUP_TMP
. $_SETUP_TMP
rm -f $_SETUP_TMP

# save value of IFS, including if it was unset
# the "+x" syntax helps differentiate unset from empty
_IFS=$IFS
if [ -z ${IFS+x} ]; then
_IFS_WAS_UNSET=1
fi

# source all environment hooks
IFS=":"
for _envfile in $_CATKIN_ENVIRONMENT_HOOKS; do
# restore value of IFS, including if it was unset
IFS=$_IFS
if [ $_IFS_WAS_UNSET ]; then
unset IFS
fi
_i=0
while [ $_i -lt $_CATKIN_ENVIRONMENT_HOOKS_COUNT ]; do
eval _envfile=\$_CATKIN_ENVIRONMENT_HOOKS_$_i
unset _CATKIN_ENVIRONMENT_HOOKS_$_i
eval _envfile_workspace=\$_CATKIN_ENVIRONMENT_HOOKS_${_i}_WORKSPACE
unset _CATKIN_ENVIRONMENT_HOOKS_${_i}_WORKSPACE
# set workspace for environment hook
CATKIN_ENV_HOOK_WORKSPACE=$_envfile_workspace
. "$_envfile"
unset CATKIN_ENV_HOOK_WORKSPACE
_i=$((_i + 1))
done

# restore value of IFS, including if it was unset
IFS=$_IFS
if [ $_IFS_WAS_UNSET ]; then
unset IFS
unset _IFS_WAS_UNSET
fi
unset _IFS

unset _CATKIN_ENVIRONMENT_HOOKS
unset _CATKIN_ENVIRONMENT_HOOKS_COUNT

0 comments on commit a0d699a

Please sign in to comment.