From 23dba8d27ba5f5659e0315ddf7b986781dad469f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jukka=20Jyl=C3=A4nki?= Date: Fri, 20 Jul 2018 10:02:55 +0300 Subject: [PATCH] Remove redundant checking for hasattr(self, 'activated_env') since activated_environment() function already does that. Also change activated_environment() to return a pre-split list instead of a string that caller is expected to split. --- emsdk | 34 ++++++++++++++++------------------ 1 file changed, 16 insertions(+), 18 deletions(-) diff --git a/emsdk b/emsdk index 3c40a3e..ff3948c 100755 --- a/emsdk +++ b/emsdk @@ -1171,9 +1171,9 @@ class Tool: def activated_environment(self): if hasattr(self, 'activated_env'): - return self.expand_vars(self.activated_env) + return self.expand_vars(self.activated_env).split(';') else: - return '' + return [] def compatible_with_this_os(self): if hasattr(self, 'os'): @@ -1269,13 +1269,12 @@ 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'): - 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 + envs = self.activated_environment() + 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('\\', '/') @@ -1288,8 +1287,8 @@ class Tool: return True def win_activate_env_vars(self, permanently_activate): - if WINDOWS and hasattr(self, 'activated_env'): - envs = self.activated_environment().split(';') + if WINDOWS: + envs = self.activated_environment() for env in envs: (key, value) = parse_key_value(env) @@ -1956,13 +1955,12 @@ def construct_env(tools_to_activate, permanent): mkdir_p(em_cache_dir) for tool in tools_to_activate: - if hasattr(tool, 'activated_env'): - 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)] + envs = tool.activated_environment() + 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:')