|
| 1 | +#!/usr/bin/env python |
| 2 | +import sys |
| 3 | +import os |
| 4 | +import subprocess |
| 5 | +import argparse |
| 6 | + |
| 7 | +def get_path(name): |
| 8 | + path = os.environ.get(name, "") |
| 9 | + return path.split(":") |
| 10 | + |
| 11 | +# Import spack parameters through the build environment. |
| 12 | +spack_lib = os.environ.get("SPACK_LIB") |
| 13 | +spack_deps = get_path("SPACK_DEPENDENCIES") |
| 14 | +spack_env_path = get_path("SPACK_ENV_PATH") |
| 15 | +if not spack_lib or spack_deps == None: |
| 16 | + print "%s must be run from spack." % os.path.abspath(sys.argv[0]) |
| 17 | + sys.exit(1) |
| 18 | + |
| 19 | +# Figure out what type of operation we're doing |
| 20 | +command = os.path.basename(sys.argv[0]) |
| 21 | + |
| 22 | +# Grab a minimal set of spack packages |
| 23 | +sys.path.append(spack_lib) |
| 24 | +from spack.utils import * |
| 25 | +from spack.compilation import parse_rpaths |
| 26 | +import spack.tty as tty |
| 27 | + |
| 28 | +parser = argparse.ArgumentParser(add_help=False) |
| 29 | +parser.add_argument("-I", action='append', default=[], dest='include_path') |
| 30 | +parser.add_argument("-L", action='append', default=[], dest='lib_path') |
| 31 | +parser.add_argument("-l", action='append', default=[], dest='libs') |
| 32 | + |
| 33 | +options, other_args = parser.parse_known_args() |
| 34 | +rpaths, other_args = parse_rpaths(other_args) |
| 35 | + |
| 36 | +if rpaths: |
| 37 | + tty.warn("Spack stripping non-spack rpaths: ", *rpaths) |
| 38 | + |
| 39 | +# Find the actual command the build is trying to run by removing |
| 40 | +# Spack's env paths from the path. We use this later for which() |
| 41 | +script_dir = os.path.dirname(os.path.expanduser(__file__)) |
| 42 | +clean_path = get_path("PATH") |
| 43 | +remove_items(clean_path, '.') |
| 44 | +for path in spack_env_path: |
| 45 | + remove_items(clean_path, path) |
| 46 | + |
| 47 | +# Add dependence's paths to our compiler flags. |
| 48 | +def append_if_dir(path_list, prefix, *dirs): |
| 49 | + full_path = os.path.join(prefix, *dirs) |
| 50 | + if os.path.isdir(full_path): |
| 51 | + path_list.append(full_path) |
| 52 | + |
| 53 | +for prefix in spack_deps: |
| 54 | + append_if_dir(options.include_path, prefix, "include") |
| 55 | + append_if_dir(options.lib_path, prefix, "lib") |
| 56 | + append_if_dir(options.lib_path, prefix, "lib64") |
| 57 | + |
| 58 | +# Add our modified arguments to it. |
| 59 | +cmd = which(command, path=clean_path) |
| 60 | +arguments = ['-I%s' % path for path in options.include_path] |
| 61 | +arguments += other_args |
| 62 | +arguments += ['-L%s' % path for path in options.lib_path] |
| 63 | +arguments += ['-l%s' % path for path in options.libs] |
| 64 | + |
| 65 | +# Unset some pesky environment variables |
| 66 | +pop_keys(os.environ, "LD_LIBRARY_PATH", "LD_RUN_PATH", "DYLD_LIBRARY_PATH") |
| 67 | + |
| 68 | +rcode = cmd(*arguments, fail_on_error=False) |
| 69 | +sys.exit(rcode) |
0 commit comments