summaryrefslogtreecommitdiff
path: root/bin/spack
blob: 3ad3a07bbc1596a7a70e30555bc4176fa3c23aad (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
#!/usr/bin/env python
import sys
if not sys.version_info[:2] >= (2,7):
    sys.exit("Spack requires Python 2.7.  Version was %s." % sys.version_info)

import os
import argparse

# Find spack's location and its prefix.
SPACK_FILE = os.path.realpath(os.path.expanduser(__file__))
os.environ["SPACK_FILE"] = SPACK_FILE
SPACK_PREFIX = os.path.dirname(os.path.dirname(SPACK_FILE))

# Allow spack libs to be imported in our scripts
SPACK_LIB_PATH = os.path.join(SPACK_PREFIX, "lib", "spack")
sys.path.insert(0, SPACK_LIB_PATH)

# clean up the scope and start using spack package instead.
del SPACK_FILE, SPACK_PREFIX, SPACK_LIB_PATH
import spack
import spack.tty as tty
from spack.error import SpackError

# Command parsing
parser = argparse.ArgumentParser(
    description='Spack: the Supercomputing PACKage Manager.')
parser.add_argument('-V', '--version', action='version',
                    version="%s" % spack.spack_version)
parser.add_argument('-v', '--verbose', action='store_true', dest='verbose',
                    help="print additional output during builds")
parser.add_argument('-d', '--debug', action='store_true', dest='debug',
                    help="write out debug logs during compile")
parser.add_argument('-m', '--mock', action='store_true', dest='mock',
                    help="Use mock packages instead of real ones.")

# each command module implements a parser() function, to which we pass its
# subparser for setup.
subparsers = parser.add_subparsers(metavar='COMMAND', dest="command")

import spack.cmd
for cmd in spack.cmd.commands:
    module = spack.cmd.get_module(cmd)
    subparser = subparsers.add_parser(cmd, help=module.description)
    module.setup_parser(subparser)
args = parser.parse_args()

# Set up environment based on args.
spack.verbose = args.verbose
spack.debug = args.debug
if args.mock:
    from spack.util.filesystem import new_path
    mock_path = new_path(spack.module_path, 'test', 'mock_packages')
    spack.packages_path = mock_path

# Try to load the particular command asked for and run it
command = spack.cmd.get_command(args.command)
try:
    command(parser, args)
except SpackError, e:
    if spack.debug:
        # In debug mode, raise with a full stack trace.
        raise
    else:
        # Otherwise print a nice simple message.
        tty.die(e.message)
except KeyboardInterrupt:
    tty.die("Got a keyboard interrupt from the user.")