From 6585679879bb7b6d4cdd18b9c26031deadc3bfc7 Mon Sep 17 00:00:00 2001 From: Jonathan Bohren Date: Thu, 21 Apr 2016 13:53:57 -0400 Subject: [PATCH 1/3] resultspace: Fixing environment cache checking which could blow away environment if there are no env hooks in the resultspace (fixes #350) --- catkin_tools/resultspace.py | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/catkin_tools/resultspace.py b/catkin_tools/resultspace.py index 25dd742e..3a29e5d9 100644 --- a/catkin_tools/resultspace.py +++ b/catkin_tools/resultspace.py @@ -67,9 +67,8 @@ def get_resultspace_environment(result_space_path, base_env={}, quiet=False, cac env_hooks = [] # Check the cache first, if desired - if cached: - cached_env_hooks = _resultspace_env_hooks_cache.get(result_space_path, []) - if result_space_path in _resultspace_env_cache and env_hooks == cached_env_hooks: + if cached and result_space_path in _resultspace_env_hooks_cache and result_space_path in _resultspace_env_cache: + if env_hooks == _resultspace_env_hooks_cache.get(result_space_path): return dict(_resultspace_env_cache[result_space_path]) # Check to make sure result_space_path is a valid directory From ccbb9feeae3edd3fbcada506810ae277ad79836b Mon Sep 17 00:00:00 2001 From: Jonathan Bohren Date: Thu, 21 Apr 2016 16:47:53 -0400 Subject: [PATCH 2/3] resultspace: Base loaded resultspace env off of current environment, unless otherwise specified --- catkin_tools/resultspace.py | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/catkin_tools/resultspace.py b/catkin_tools/resultspace.py index 3a29e5d9..dde16ef5 100644 --- a/catkin_tools/resultspace.py +++ b/catkin_tools/resultspace.py @@ -38,8 +38,7 @@ _resultspace_env_cache = {} _resultspace_env_hooks_cache = {} - -def get_resultspace_environment(result_space_path, base_env={}, quiet=False, cached=True, strict=True): +def get_resultspace_environment(result_space_path, base_env=None, quiet=False, cached=True, strict=True): """Get the environemt variables which result from sourcing another catkin workspace's setup files as the string output of `cmake -E environment`. This cmake command is used to be as portable as possible. @@ -56,6 +55,10 @@ def get_resultspace_environment(result_space_path, base_env={}, quiet=False, cac :returns: a dictionary of environment variables and their values """ + # Set bae environment to the current environment + if base_env is None: + base_env = dict(os.environ) + # Get the MD5 checksums for the current env hooks # TODO: the env hooks path should be defined somewhere env_hooks_path = os.path.join(result_space_path, 'etc', 'catkin', 'profile.d') @@ -173,7 +176,7 @@ def get_resultspace_environment(result_space_path, base_env={}, quiet=False, cac return dict(env_dict) -def load_resultspace_environment(result_space_path, cached=True): +def load_resultspace_environment(result_space_path, base_env=None, cached=True): """Load the environemt variables which result from sourcing another workspace path into this process's environment. @@ -182,7 +185,7 @@ def load_resultspace_environment(result_space_path, cached=True): :param cached: use the cached environment :type cached: bool """ - env_dict = get_resultspace_environment(result_space_path, cached=cached) + env_dict = get_resultspace_environment(result_space_path, base_env=base_env, cached=cached) try: os.environ.update(env_dict) except TypeError: From 6bc4b53590e4f1f2f4ed757c4f813e13f2adc370 Mon Sep 17 00:00:00 2001 From: Jonathan Bohren Date: Thu, 21 Apr 2016 16:48:34 -0400 Subject: [PATCH 3/3] resultspace: Avoid caching issue when loading the same resultspace with different base environments --- catkin_tools/resultspace.py | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/catkin_tools/resultspace.py b/catkin_tools/resultspace.py index dde16ef5..1255a001 100644 --- a/catkin_tools/resultspace.py +++ b/catkin_tools/resultspace.py @@ -35,8 +35,9 @@ DEFAULT_SHELL = '/bin/bash' # Cache for result-space environments +# Maps absolute paths to 3-tuples: (base_env, hooks, result_env} _resultspace_env_cache = {} -_resultspace_env_hooks_cache = {} + def get_resultspace_environment(result_space_path, base_env=None, quiet=False, cached=True, strict=True): """Get the environemt variables which result from sourcing another catkin @@ -70,9 +71,10 @@ def get_resultspace_environment(result_space_path, base_env=None, quiet=False, c env_hooks = [] # Check the cache first, if desired - if cached and result_space_path in _resultspace_env_hooks_cache and result_space_path in _resultspace_env_cache: - if env_hooks == _resultspace_env_hooks_cache.get(result_space_path): - return dict(_resultspace_env_cache[result_space_path]) + if cached and result_space_path in _resultspace_env_cache: + (cached_base_env, cached_env_hooks, result_env) = _resultspace_env_cache.get(result_space_path) + if env_hooks == cached_env_hooks and cached_base_env == base_env: + return dict(result_env) # Check to make sure result_space_path is a valid directory if not os.path.isdir(result_space_path): @@ -162,8 +164,7 @@ def get_resultspace_environment(result_space_path, base_env=None, quiet=False, c # Check to make sure we got some kind of environment if len(env_dict) > 0: # Cache the result - _resultspace_env_cache[result_space_path] = env_dict - _resultspace_env_hooks_cache[result_space_path] = env_hooks + _resultspace_env_cache[result_space_path] = (base_env, env_hooks, env_dict) else: print("WARNING: Sourced environment from `{}` has no environment variables. Something is wrong.".format( setup_file_path))