Skip to content
This repository has been archived by the owner on Jun 14, 2021. It is now read-only.

Commit

Permalink
Merge branch 'dev' into feature/#135/save-compiler-env
Browse files Browse the repository at this point in the history
  • Loading branch information
benoit-dubreuil committed Apr 12, 2021
2 parents d367ace + 519e05e commit a03c345
Showing 1 changed file with 6 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,6 @@
import subprocess
from typing import Final, MutableMapping, Optional

_ENV_VAR_MULTI_VALUES_SEP: Final[str] = ';'


class EnvMSVC(contextlib.AbstractContextManager):
import build_system.compiler.installed_instance.msvc
Expand Down Expand Up @@ -48,13 +46,13 @@ def __append_vcvars_to_local_env(self):
local_env = os.environ

for vcvar_key, vcvars_var_value in self.vcvars.items():
formatted_vcvars_var_value = _ENV_VAR_MULTI_VALUES_SEP.join(vcvars_var_value)
formatted_vcvars_var_value = os.path.sep.join(vcvars_var_value)

if vcvar_key in local_env and len(local_env[vcvar_key]) > 0:
matching_local_env_var_value = local_env[vcvar_key]

if matching_local_env_var_value[-1] != _ENV_VAR_MULTI_VALUES_SEP:
matching_local_env_var_value += _ENV_VAR_MULTI_VALUES_SEP
if matching_local_env_var_value[-1] != os.path.sep:
matching_local_env_var_value += os.path.sep

local_env[vcvar_key] = matching_local_env_var_value + formatted_vcvars_var_value
else:
Expand All @@ -65,13 +63,13 @@ def __remove_vcvars_from_local_env(self):

for vcvar_key, vcvars_var_value in self.vcvars.items():
if vcvar_key in local_env:
formatted_vcvars_var_value = _ENV_VAR_MULTI_VALUES_SEP.join(vcvars_var_value)
formatted_vcvars_var_value = os.path.sep.join(vcvars_var_value)

matching_local_env_var_value = local_env[vcvar_key]

# Replace instead of search -> KISS
new_matching_local_env_var_value = matching_local_env_var_value.replace(formatted_vcvars_var_value, str())
new_matching_local_env_var_value = new_matching_local_env_var_value.strip(_ENV_VAR_MULTI_VALUES_SEP + ' ')
new_matching_local_env_var_value = new_matching_local_env_var_value.strip(os.path.sep + ' ')

if len(new_matching_local_env_var_value) <= 0:
del local_env[vcvar_key]
Expand Down Expand Up @@ -107,7 +105,7 @@ def __interpret_local_en_vars() -> dict[str, list[str]]:

for env_var_key, env_var_value in local_env.items():
if (env_var_value is not None) and (len(env_var_value) > 0):
split_values: list[str] = env_var_value.strip().split(sep=_ENV_VAR_MULTI_VALUES_SEP)
split_values: list[str] = env_var_value.strip().split(sep=os.path.sep)
interpreted_local_env[env_var_key.upper()] = split_values

return interpreted_local_env
Expand Down

0 comments on commit a03c345

Please sign in to comment.