Skip to content

Commit

Permalink
Merge pull request #101 from ament/pass_env_with_list_value
Browse files Browse the repository at this point in the history
merge env values which were split on semicolons
  • Loading branch information
dirk-thomas authored Aug 4, 2017
2 parents de6dd32 + 00e3224 commit b446deb
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 30 deletions.
28 changes: 2 additions & 26 deletions ament_cmake_test/cmake/ament_add_test.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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})

Expand Down
28 changes: 24 additions & 4 deletions ament_cmake_test/cmake/run_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)))
Expand Down

0 comments on commit b446deb

Please sign in to comment.