Add support for multiple environment items to be present in activated_env, separated by semicolon ;.

This commit is contained in:
Jukka Jylänki
2018-07-19 12:17:56 +03:00
parent 18b21ddad6
commit cac082054a

36
emsdk
View File

@@ -1270,14 +1270,13 @@ class Tool:
# Returns true if the system environment variables requires by this tool are currently active.
def is_env_active(self):
if hasattr(self, 'activated_env'):
(key, value) = parse_key_value(self.activated_environment())
if not key in os.environ or to_unix_path(os.environ[key]) != to_unix_path(value):
if VERBOSE: print(str(self) + ' is not active, because environment variable key="' + key + '" has value "' + str(os.getenv(key)) + '" but should have value "' + value + '"')
return False
# if WINDOWS:
# env_var = win_get_active_environment_variable(key)
# if env_var != value:
# return False
envs = self.activated_environment().split(';')
for env in envs:
(key, value) = parse_key_value(env)
if not key in os.environ or to_unix_path(os.environ[key]) != to_unix_path(value):
if VERBOSE: print(str(self) + ' is not active, because environment variable key="' + key + '" has value "' + str(os.getenv(key)) + '" but should have value "' + value + '"')
return False
if hasattr(self, 'activated_path'):
path = self.expand_vars(self.activated_path).replace('\\', '/')
path = path.split(ENVPATH_SEPARATOR)
@@ -1290,11 +1289,14 @@ class Tool:
def win_activate_env_vars(self, permanently_activate):
if WINDOWS and hasattr(self, 'activated_env'):
(key, value) = parse_key_value(self.activated_environment())
if permanently_activate:
win_delete_environment_variable(key, False) # If there is an env var for the LOCAL USER with same name, it will hide the system var, so must remove that first.
envs = self.activated_environment().split(';')
for env in envs:
(key, value) = parse_key_value(env)
win_set_environment_variable(key, value, permanently_activate)
if permanently_activate:
win_delete_environment_variable(key, False) # If there is an env var for the LOCAL USER with same name, it will hide the system var, so must remove that first.
win_set_environment_variable(key, value, permanently_activate)
# If this tool can be installed on this system, this function returns True.
# Otherwise, this function returns a string that describes the reason why this tool is not available.
@@ -1955,10 +1957,12 @@ def construct_env(tools_to_activate, permanent):
for tool in tools_to_activate:
if hasattr(tool, 'activated_env'):
(key, value) = parse_key_value(tool.activated_env)
value = to_native_path(tool.expand_vars(value))
if not key in os.environ or to_unix_path(os.environ[key]) != to_unix_path(value): # Don't set env. vars which are already set to the correct value.
env_vars_to_add += [(key, value)]
envs = tool.activated_environment().split(';')
for env in envs:
(key, value) = parse_key_value(env)
value = to_native_path(tool.expand_vars(value))
if not key in os.environ or to_unix_path(os.environ[key]) != to_unix_path(value): # Don't set env. vars which are already set to the correct value.
env_vars_to_add += [(key, value)]
if len(env_vars_to_add) > 0:
print('Setting environment variables:')