summaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
authorHarmen Stoppels <harmenstoppels@gmail.com>2023-07-04 10:54:13 +0200
committerGitHub <noreply@github.com>2023-07-04 10:54:13 +0200
commit08f23f48024c454428260d75429c8b8753942fe0 (patch)
tree7540b5eb482236d3350ac7b44416a8ff9d4ef3a3 /lib
parente9dc6dc96cf4aa912dcff12413c10e51f73631cb (diff)
downloadspack-08f23f48024c454428260d75429c8b8753942fe0.tar.gz
spack-08f23f48024c454428260d75429c8b8753942fe0.tar.bz2
spack-08f23f48024c454428260d75429c8b8753942fe0.tar.xz
spack-08f23f48024c454428260d75429c8b8753942fe0.zip
macos sip: apply on macos only, dont store LD_LIBRARY_PATH (#38687)
Diffstat (limited to 'lib')
-rw-r--r--lib/spack/spack/main.py32
1 files changed, 20 insertions, 12 deletions
diff --git a/lib/spack/spack/main.py b/lib/spack/spack/main.py
index 00131114f6..8d4e73bc65 100644
--- a/lib/spack/spack/main.py
+++ b/lib/spack/spack/main.py
@@ -855,6 +855,23 @@ def print_setup_info(*info):
shell_set("_sp_module_prefix", "not_installed")
+def restore_macos_dyld_vars():
+ """
+ Spack mutates DYLD_* variables in `spack load` and `spack env activate`.
+ Unlike Linux, macOS SIP clears these variables in new processes, meaning
+ that os.environ["DYLD_*"] in our Python process is not the same as the user's
+ shell. Therefore, we store the user's DYLD_* variables in SPACK_DYLD_* and
+ restore them here.
+ """
+ if not sys.platform == "darwin":
+ return
+
+ for dyld_var in ("DYLD_LIBRARY_PATH", "DYLD_FALLBACK_LIBRARY_PATH"):
+ stored_var_name = f"SPACK_{dyld_var}"
+ if stored_var_name in os.environ:
+ os.environ[dyld_var] = os.environ[stored_var_name]
+
+
def _main(argv=None):
"""Logic for the main entry point for the Spack command.
@@ -887,18 +904,6 @@ def _main(argv=None):
parser.add_argument("command", nargs=argparse.REMAINDER)
args, unknown = parser.parse_known_args(argv)
- # Recover stored LD_LIBRARY_PATH variables from spack shell function
- # This is necessary because MacOS System Integrity Protection clears
- # (DY?)LD_LIBRARY_PATH variables on process start.
- # Spack clears these variables before building and installing packages,
- # but needs to know the prior state for commands like `spack load` and
- # `spack env activate that modify the user environment.
- recovered_vars = ("LD_LIBRARY_PATH", "DYLD_LIBRARY_PATH", "DYLD_FALLBACK_LIBRARY_PATH")
- for var in recovered_vars:
- stored_var_name = "SPACK_%s" % var
- if stored_var_name in os.environ:
- os.environ[var] = os.environ[stored_var_name]
-
# Just print help and exit if run with no arguments at all
no_args = (len(sys.argv) == 1) if argv is None else (len(argv) == 0)
if no_args:
@@ -921,6 +926,9 @@ def _main(argv=None):
# scopes, then environment configuration here.
# ------------------------------------------------------------------------
+ # Make spack load / env activate work on macOS
+ restore_macos_dyld_vars()
+
# make spack.config aware of any command line configuration scopes
if args.config_scopes:
spack.config.command_line_scopes = args.config_scopes