diff --git a/colcon_core/shell/__init__.py b/colcon_core/shell/__init__.py index 1e1eaeaa..faa103ff 100644 --- a/colcon_core/shell/__init__.py +++ b/colcon_core/shell/__init__.py @@ -188,7 +188,11 @@ def create_hook_set_value( :param str pkg_name: The package name :param str name: The name of the environment variable :param str value: The value to be set. If an empty string is passed the - environment variable should be set to the prefix path. + environment variable should be set to the prefix path at the time the + hook is sourced (from COLCON_CURRENT_PREFIX). + Note that the install-space may have been relocated, and the final + value may differ from the value of argument prefix_path, where + the hook was originally installed to. :returns: The relative path to the created hook script :rtype: Path """ diff --git a/colcon_core/shell/bat.py b/colcon_core/shell/bat.py index 5f2463eb..2ae4bc76 100644 --- a/colcon_core/shell/bat.py +++ b/colcon_core/shell/bat.py @@ -95,7 +95,7 @@ def create_hook_set_value( # noqa: D102 ('%s.bat' % env_hook_name) logger.info("Creating environment hook '%s'" % hook_path) if value == '': - value = '%COLCON_PREFIX_PATH%' + value = '%COLCON_CURRENT_PREFIX%' expand_template( Path(__file__).parent / 'template' / 'hook_set_value.bat.em', hook_path, {'name': name, 'value': value}) diff --git a/colcon_core/shell/sh.py b/colcon_core/shell/sh.py index e46840f8..64005512 100644 --- a/colcon_core/shell/sh.py +++ b/colcon_core/shell/sh.py @@ -97,7 +97,7 @@ def create_hook_set_value( # noqa: D102 ('%s.sh' % env_hook_name) logger.info("Creating environment hook '%s'" % hook_path) if value == '': - value = '$COLCON_PREFIX_PATH' + value = '$COLCON_CURRENT_PREFIX' expand_template( Path(__file__).parent / 'template' / 'hook_set_value.sh.em', hook_path, {'name': name, 'value': value})