Skip to content

Commit

Permalink
fix windows support, refactor
Browse files Browse the repository at this point in the history
  • Loading branch information
trws committed Apr 19, 2022
1 parent e4e4054 commit 1e3531b
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 8 deletions.
31 changes: 24 additions & 7 deletions lib/spack/spack/build_environment.py
Original file line number Diff line number Diff line change
Expand Up @@ -162,14 +162,32 @@ def clean_environment():
# unlike the other functions so it doesn't overwrite what the modules load.
env = EnvironmentModifications()

# clear *everything*
for n in os.environ.keys():
env.unset(n)
env_name_whitelist = list(map(re.compile, (
r'SPACK',
r'^SPACK_.*', # keep SPACK_ROOT and company
r'EDITOR',
r'PATH',
r'PATHEXT',
)))

if sys.platform == 'win32':
env_name_whitelist.extend(
map(
re.compile,
(
r'SPACKINSTDIR', # one random windows one
r'TMP',
r'TEMP',
r'SYSTEMDRIVE',
r'SYSTEMROOT', # required for cl.exe
)
)
)

# Spack needs SPACK_ROOT, and other spack stuff, though so we need to restore them
# clear *everything* not in the whitelist
for n in os.environ.keys():
if 'SPACK_' in n:
env.restore(n)
if not any(r.match(n) for r in env_name_whitelist):
env.unset(n)

# On Cray "cluster" systems, unset CRAY_LD_LIBRARY_PATH to avoid
# interference with Spack dependencies.
Expand All @@ -191,7 +209,6 @@ def clean_environment():
else:
env.restore('LC_ALL')

env.restore('PATH')
# Remove any macports installs from the PATH. The macports ld can
# cause conflicts with the built-in linker on el capitan. Solves
# assembler issues, e.g.:
Expand Down
2 changes: 1 addition & 1 deletion lib/spack/spack/util/path.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ def replacements():
import spack.paths
return {
'spack': spack.paths.prefix,
'user': getpass.getuser(),
'user': os.getlogin(),
'tempdir': tempfile.gettempdir(),
'user_cache_path': spack.paths.user_cache_path}

Expand Down

0 comments on commit 1e3531b

Please sign in to comment.