2013-06-03 04:54:46 +08:00
|
|
|
#!/usr/bin/env python
|
2014-01-08 17:21:02 +08:00
|
|
|
##############################################################################
|
2016-05-12 12:22:25 +08:00
|
|
|
# Copyright (c) 2013-2016, Lawrence Livermore National Security, LLC.
|
2014-01-08 17:21:02 +08:00
|
|
|
# Produced at the Lawrence Livermore National Laboratory.
|
|
|
|
#
|
|
|
|
# This file is part of Spack.
|
2016-05-12 12:22:25 +08:00
|
|
|
# Created by Todd Gamblin, tgamblin@llnl.gov, All rights reserved.
|
2014-01-08 17:21:02 +08:00
|
|
|
# LLNL-CODE-647188
|
|
|
|
#
|
2015-12-09 17:24:15 +08:00
|
|
|
# For details, see https://github.com/llnl/spack
|
2014-01-08 17:21:02 +08:00
|
|
|
# Please also see the LICENSE file for our notice and the LGPL.
|
|
|
|
#
|
|
|
|
# This program is free software; you can redistribute it and/or modify
|
2016-05-12 12:22:25 +08:00
|
|
|
# it under the terms of the GNU Lesser General Public License (as
|
|
|
|
# published by the Free Software Foundation) version 2.1, February 1999.
|
2014-01-08 17:21:02 +08:00
|
|
|
#
|
|
|
|
# This program is distributed in the hope that it will be useful, but
|
|
|
|
# WITHOUT ANY WARRANTY; without even the IMPLIED WARRANTY OF
|
|
|
|
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the terms and
|
2016-05-12 12:22:25 +08:00
|
|
|
# conditions of the GNU Lesser General Public License for more details.
|
2014-01-08 17:21:02 +08:00
|
|
|
#
|
2016-05-12 12:22:25 +08:00
|
|
|
# You should have received a copy of the GNU Lesser General Public
|
|
|
|
# License along with this program; if not, write to the Free Software
|
|
|
|
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
2014-01-08 17:21:02 +08:00
|
|
|
##############################################################################
|
2013-06-03 04:54:46 +08:00
|
|
|
import sys
|
2014-08-11 09:00:20 +08:00
|
|
|
if not sys.version_info[:2] >= (2,6):
|
2014-12-20 03:09:37 +08:00
|
|
|
v_info = sys.version_info[:3]
|
|
|
|
sys.exit("Spack requires Python 2.6 or higher. This is Python %d.%d.%d." % v_info)
|
2013-02-14 09:50:44 +08:00
|
|
|
|
|
|
|
import os
|
|
|
|
|
|
|
|
# Find spack's location and its prefix.
|
2013-05-16 07:47:50 +08:00
|
|
|
SPACK_FILE = os.path.realpath(os.path.expanduser(__file__))
|
|
|
|
os.environ["SPACK_FILE"] = SPACK_FILE
|
2013-02-14 09:50:44 +08:00
|
|
|
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)
|
2015-11-12 10:04:22 +08:00
|
|
|
SPACK_EXTERNAL_LIBS = os.path.join(SPACK_LIB_PATH, "external")
|
|
|
|
sys.path.insert(0, SPACK_EXTERNAL_LIBS)
|
2013-02-14 09:50:44 +08:00
|
|
|
|
2015-11-26 10:33:52 +08:00
|
|
|
import warnings
|
2016-01-25 23:29:51 +08:00
|
|
|
# Avoid warnings when nose is installed with the python exe being used to run
|
|
|
|
# spack. Note this must be done after Spack's external libs directory is added
|
|
|
|
# to sys.path.
|
2015-11-26 10:33:52 +08:00
|
|
|
with warnings.catch_warnings():
|
2015-12-03 10:10:28 +08:00
|
|
|
warnings.filterwarnings("ignore", ".*nose was already imported")
|
2015-11-26 10:33:52 +08:00
|
|
|
import nose
|
|
|
|
|
2015-11-24 09:39:59 +08:00
|
|
|
# Quick and dirty check to clean orphaned .pyc files left over from
|
|
|
|
# previous revisions. These files were present in earlier versions of
|
|
|
|
# Spack, were removed, but shadow system modules that Spack still
|
|
|
|
# imports. If we leave them, Spack will fail in mysterious ways.
|
|
|
|
# TODO: more elegant solution for orphaned pyc files.
|
|
|
|
orphaned_pyc_files = [os.path.join(SPACK_EXTERNAL_LIBS, n)
|
|
|
|
for n in ('functools.pyc', 'ordereddict.pyc')]
|
|
|
|
for pyc_file in orphaned_pyc_files:
|
|
|
|
if not os.path.exists(pyc_file):
|
|
|
|
continue
|
|
|
|
try:
|
|
|
|
os.remove(pyc_file)
|
|
|
|
except OSError as e:
|
2016-01-25 23:29:51 +08:00
|
|
|
print "WARNING: Spack may fail mysteriously. Couldn't remove orphaned .pyc file: %s" % pyc_file
|
2015-11-24 09:39:59 +08:00
|
|
|
|
2014-03-17 07:03:49 +08:00
|
|
|
# If there is no working directory, use the spack prefix.
|
|
|
|
try:
|
2014-05-20 07:07:42 +08:00
|
|
|
working_dir = os.getcwd()
|
2014-03-17 07:03:49 +08:00
|
|
|
except OSError:
|
|
|
|
os.chdir(SPACK_PREFIX)
|
2014-07-03 14:22:38 +08:00
|
|
|
working_dir = SPACK_PREFIX
|
2014-03-17 07:03:49 +08:00
|
|
|
|
2013-02-14 09:50:44 +08:00
|
|
|
# clean up the scope and start using spack package instead.
|
|
|
|
del SPACK_FILE, SPACK_PREFIX, SPACK_LIB_PATH
|
2014-03-13 10:24:47 +08:00
|
|
|
import llnl.util.tty as tty
|
2015-05-18 13:29:08 +08:00
|
|
|
from llnl.util.tty.color import *
|
2013-02-14 09:50:44 +08:00
|
|
|
import spack
|
2013-10-08 08:57:27 +08:00
|
|
|
from spack.error import SpackError
|
2014-08-11 02:48:07 +08:00
|
|
|
from external import argparse
|
2013-02-14 09:50:44 +08:00
|
|
|
|
|
|
|
# Command parsing
|
|
|
|
parser = argparse.ArgumentParser(
|
2015-05-18 13:29:08 +08:00
|
|
|
formatter_class=argparse.RawTextHelpFormatter,
|
|
|
|
description="Spack: the Supercomputing PACKage Manager." + colorize("""
|
|
|
|
|
|
|
|
spec expressions:
|
|
|
|
PACKAGE [CONSTRAINTS]
|
|
|
|
|
|
|
|
CONSTRAINTS:
|
|
|
|
@c{@version}
|
|
|
|
@g{%compiler @compiler_version}
|
|
|
|
@B{+variant}
|
|
|
|
@r{-variant} or @r{~variant}
|
|
|
|
@m{=architecture}
|
|
|
|
[^DEPENDENCY [CONSTRAINTS] ...]"""))
|
|
|
|
|
2015-02-15 17:44:38 +08:00
|
|
|
parser.add_argument('-d', '--debug', action='store_true',
|
2014-03-14 05:24:47 +08:00
|
|
|
help="Write out debug logs during compile")
|
2015-12-17 07:54:15 +08:00
|
|
|
parser.add_argument('-D', '--pdb', action='store_true',
|
|
|
|
help="Run spack under the pdb debugger")
|
2015-02-15 17:44:38 +08:00
|
|
|
parser.add_argument('-k', '--insecure', action='store_true',
|
2015-04-08 01:29:07 +08:00
|
|
|
help="Do not check ssl certificates when downloading.")
|
2015-02-15 17:44:38 +08:00
|
|
|
parser.add_argument('-m', '--mock', action='store_true',
|
2013-11-24 05:04:36 +08:00
|
|
|
help="Use mock packages instead of real ones.")
|
2015-02-15 17:44:38 +08:00
|
|
|
parser.add_argument('-p', '--profile', action='store_true',
|
|
|
|
help="Profile execution using cProfile.")
|
2015-04-08 01:29:07 +08:00
|
|
|
parser.add_argument('-v', '--verbose', action='store_true',
|
|
|
|
help="Print additional output during builds")
|
|
|
|
parser.add_argument('-V', '--version', action='version',
|
|
|
|
version="%s" % spack.spack_version)
|
2013-02-14 09:50:44 +08:00
|
|
|
|
|
|
|
# each command module implements a parser() function, to which we pass its
|
|
|
|
# subparser for setup.
|
2013-12-12 20:25:31 +08:00
|
|
|
subparsers = parser.add_subparsers(metavar='SUBCOMMAND', dest="command")
|
2013-02-14 09:50:44 +08:00
|
|
|
|
|
|
|
import spack.cmd
|
|
|
|
for cmd in spack.cmd.commands:
|
|
|
|
module = spack.cmd.get_module(cmd)
|
2013-02-22 16:20:24 +08:00
|
|
|
subparser = subparsers.add_parser(cmd, help=module.description)
|
2013-02-14 09:50:44 +08:00
|
|
|
module.setup_parser(subparser)
|
2014-08-17 05:53:57 +08:00
|
|
|
|
|
|
|
# Just print help and exit if run with no arguments at all
|
|
|
|
if len(sys.argv) == 1:
|
|
|
|
parser.print_help()
|
|
|
|
sys.exit(1)
|
|
|
|
|
|
|
|
# actually parse the args.
|
2013-02-14 09:50:44 +08:00
|
|
|
args = parser.parse_args()
|
|
|
|
|
2015-02-15 17:44:38 +08:00
|
|
|
def main():
|
|
|
|
# Set up environment based on args.
|
|
|
|
tty.set_verbose(args.verbose)
|
|
|
|
tty.set_debug(args.debug)
|
|
|
|
spack.debug = args.debug
|
|
|
|
|
2015-05-13 05:52:41 +08:00
|
|
|
if spack.debug:
|
|
|
|
import spack.util.debug as debug
|
|
|
|
debug.register_interrupt_handler()
|
|
|
|
|
2016-05-27 11:30:05 +08:00
|
|
|
from spack.yaml_version_check import check_yaml_versions
|
|
|
|
check_yaml_versions()
|
|
|
|
|
2015-02-15 17:44:38 +08:00
|
|
|
spack.spack_working_dir = working_dir
|
|
|
|
if args.mock:
|
2015-11-29 08:21:31 +08:00
|
|
|
from spack.repository import RepoPath
|
|
|
|
spack.repo.swap(RepoPath(spack.mock_packages_path))
|
2015-02-15 17:44:38 +08:00
|
|
|
|
|
|
|
# If the user asked for it, don't check ssl certs.
|
|
|
|
if args.insecure:
|
2015-10-08 15:14:44 +08:00
|
|
|
tty.warn("You asked for --insecure, which does not check SSL certificates.")
|
2015-02-15 17:44:38 +08:00
|
|
|
spack.curl.add_default_arg('-k')
|
|
|
|
|
|
|
|
# Try to load the particular command asked for and run it
|
|
|
|
command = spack.cmd.get_command(args.command)
|
|
|
|
try:
|
|
|
|
return_val = command(parser, args)
|
2016-04-12 22:54:51 +08:00
|
|
|
except SpackError as e:
|
2015-06-07 06:50:01 +08:00
|
|
|
e.die()
|
2015-02-15 17:44:38 +08:00
|
|
|
except KeyboardInterrupt:
|
|
|
|
sys.stderr.write('\n')
|
|
|
|
tty.die("Keyboard interrupt.")
|
|
|
|
|
2015-12-21 09:15:02 +08:00
|
|
|
# Allow commands to return values if they want to exit with some other code.
|
2015-02-15 17:44:38 +08:00
|
|
|
if return_val is None:
|
|
|
|
sys.exit(0)
|
|
|
|
elif isinstance(return_val, int):
|
|
|
|
sys.exit(return_val)
|
2013-10-08 08:57:27 +08:00
|
|
|
else:
|
2015-02-15 17:44:38 +08:00
|
|
|
tty.die("Bad return value from command %s: %s" % (args.command, return_val))
|
2015-01-05 15:33:15 +08:00
|
|
|
|
2015-02-15 17:44:38 +08:00
|
|
|
if args.profile:
|
|
|
|
import cProfile
|
|
|
|
cProfile.run('main()', sort='tottime')
|
2015-12-17 07:54:15 +08:00
|
|
|
elif args.pdb:
|
|
|
|
import pdb
|
|
|
|
pdb.run('main()')
|
2015-01-05 15:33:15 +08:00
|
|
|
else:
|
2015-02-15 17:44:38 +08:00
|
|
|
main()
|