From 0fa8ed833043d6225b9b091c4532ab99673a2476 Mon Sep 17 00:00:00 2001 From: Dirk Thomas Date: Fri, 4 Aug 2017 13:46:02 -0700 Subject: [PATCH 1/2] merge env values which were split on semicolons --- ament_cmake_test/cmake/ament_add_test.cmake | 28 ++------------------- ament_cmake_test/cmake/run_test.py | 20 +++++++++++++-- 2 files changed, 20 insertions(+), 28 deletions(-) diff --git a/ament_cmake_test/cmake/ament_add_test.cmake b/ament_cmake_test/cmake/ament_add_test.cmake index 329b2f9e..7c8723e2 100644 --- a/ament_cmake_test/cmake/ament_add_test.cmake +++ b/ament_cmake_test/cmake/ament_add_test.cmake @@ -88,19 +88,7 @@ function(ament_add_test testname) list(APPEND cmd_wrapper "--output-file" "${ARG_OUTPUT_FILE}") endif() if(ARG_ENV) - list(APPEND cmd_wrapper "--env") - foreach(_env ${ARG_ENV}) - # TODO(wjwwood): remove this when we have a better way to pass PATH lists - # to environment variables on Windows. - if(WIN32) - # In order to pass a ;-separated list of paths into this function on - # Windows, the calling code may have had to replace ;'s to avoid it - # them from being interpreted as a CMake list, so undo that - # substitution here. - string(REPLACE "\;" ";" _env "${_env}") - endif() - list(APPEND cmd_wrapper "${_env}") - endforeach() + list(APPEND cmd_wrapper "--env" ${ARG_ENV}) endif() if(ARG_APPEND_LIBRARY_DIRS) if(WIN32) @@ -117,19 +105,7 @@ function(ament_add_test testname) endforeach() endif() if(ARG_APPEND_ENV) - list(APPEND cmd_wrapper "--append-env") - foreach(_env ${ARG_APPEND_ENV}) - # TODO(wjwwood): remove this when we have a better way to pass PATH lists - # to environment variables on Windows. - if(WIN32) - # In order to pass a ;-separated list of paths into this function on - # Windows, the calling code may have had to replace ;'s to avoid it - # them from being interpreted as a CMake list, so undo that - # substitution here. - string(REPLACE "\;" ";" _env "${_env}") - endif() - list(APPEND cmd_wrapper "${_env}") - endforeach() + list(APPEND cmd_wrapper "--append-env" ${ARG_APPEND_ENV}) endif() list(APPEND cmd_wrapper "--command" ${ARG_COMMAND}) diff --git a/ament_cmake_test/cmake/run_test.py b/ament_cmake_test/cmake/run_test.py index 83ea42a0..6165c810 100644 --- a/ament_cmake_test/cmake/run_test.py +++ b/ament_cmake_test/cmake/run_test.py @@ -129,20 +129,36 @@ def log(msg, **kwargs): env = dict(os.environ) if args.env: log('-- run_test.py: extra environment variables:') + previous_key = None for env_str in args.env: - key, value = separate_env_vars(env_str, 'env', parser) + # if CMake has split a single value containing semicolons + # into multiple arguments they are put back together here + if previous_key and '=' not in env_str: + key = previous_key + value = env[key] + ';' + env_str + else: + key, value = separate_env_vars(env_str, 'env', parser) log(' - {0}={1}'.format(key, value)) env[key] = value + previous_key = key if args.append_env: log('-- run_test.py: extra environment variables to append:') + previous_key = None for env_str in args.append_env: - key, value = separate_env_vars(env_str, 'append-env', parser) + # if CMake has split a single value containing semicolons + # into multiple arguments they are put back together here + if previous_key and '=' not in env_str: + key = previous_key + value = env[key] + ';' + env_str + else: + key, value = separate_env_vars(env_str, 'append-env', parser) log(' - {0}={1}'.format(key, value)) if key not in env: env[key] = '' if not env[key].endswith(os.pathsep): env[key] += os.pathsep env[key] += value + previous_key = key log("-- run_test.py: invoking following command in '%s':\n - %s" % (os.getcwd(), ' '.join(args.command))) From 00e32249aa7fe295a339a268f6483ef032bfae11 Mon Sep 17 00:00:00 2001 From: William Woodall Date: Fri, 4 Aug 2017 15:27:26 -0700 Subject: [PATCH 2/2] print set env message all at once (#102) * print set env message all at once * address comments --- ament_cmake_test/cmake/run_test.py | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/ament_cmake_test/cmake/run_test.py b/ament_cmake_test/cmake/run_test.py index 6165c810..974e3819 100644 --- a/ament_cmake_test/cmake/run_test.py +++ b/ament_cmake_test/cmake/run_test.py @@ -130,6 +130,7 @@ def log(msg, **kwargs): if args.env: log('-- run_test.py: extra environment variables:') previous_key = None + updated_env_keys = set() for env_str in args.env: # if CMake has split a single value containing semicolons # into multiple arguments they are put back together here @@ -138,9 +139,11 @@ def log(msg, **kwargs): value = env[key] + ';' + env_str else: key, value = separate_env_vars(env_str, 'env', parser) - log(' - {0}={1}'.format(key, value)) env[key] = value + updated_env_keys.add(key) previous_key = key + for key in updated_env_keys: + log(' - {0}={1}'.format(key, env[key])) if args.append_env: log('-- run_test.py: extra environment variables to append:') previous_key = None @@ -150,9 +153,10 @@ def log(msg, **kwargs): if previous_key and '=' not in env_str: key = previous_key value = env[key] + ';' + env_str + log(' - {0}+={1}'.format(key, env_str)) else: key, value = separate_env_vars(env_str, 'append-env', parser) - log(' - {0}={1}'.format(key, value)) + log(' - {0}+={1}'.format(key, value)) if key not in env: env[key] = '' if not env[key].endswith(os.pathsep):