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..974e3819 100644 --- a/ament_cmake_test/cmake/run_test.py +++ b/ament_cmake_test/cmake/run_test.py @@ -129,20 +129,40 @@ def log(msg, **kwargs): env = dict(os.environ) if args.env: log('-- run_test.py: extra environment variables:') + previous_key = None + updated_env_keys = set() for env_str in args.env: - key, value = separate_env_vars(env_str, 'env', parser) - log(' - {0}={1}'.format(key, value)) + # 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) 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 for env_str in args.append_env: - key, value = separate_env_vars(env_str, 'append-env', parser) - log(' - {0}={1}'.format(key, value)) + # 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 + log(' - {0}+={1}'.format(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)))