| 
									
										
										
										
											2013-06-02 13:54:46 -07:00
										 |  |  | #!/usr/bin/env python | 
					
						
							| 
									
										
										
										
											2014-01-08 10:21:02 +01:00
										 |  |  | ############################################################################## | 
					
						
							| 
									
										
										
										
											2016-05-11 21:22:25 -07:00
										 |  |  | # Copyright (c) 2013-2016, Lawrence Livermore National Security, LLC. | 
					
						
							| 
									
										
										
										
											2014-01-08 10:21:02 +01:00
										 |  |  | # Produced at the Lawrence Livermore National Laboratory. | 
					
						
							|  |  |  | # | 
					
						
							|  |  |  | # This file is part of Spack. | 
					
						
							| 
									
										
										
										
											2016-05-11 21:22:25 -07:00
										 |  |  | # Created by Todd Gamblin, tgamblin@llnl.gov, All rights reserved. | 
					
						
							| 
									
										
										
										
											2014-01-08 10:21:02 +01:00
										 |  |  | # LLNL-CODE-647188 | 
					
						
							|  |  |  | # | 
					
						
							| 
									
										
										
										
											2015-12-09 01:24:15 -08:00
										 |  |  | # For details, see https://github.com/llnl/spack | 
					
						
							| 
									
										
										
										
											2014-01-08 10:21:02 +01: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-11 21:22:25 -07: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 10:21:02 +01: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-11 21:22:25 -07:00
										 |  |  | # conditions of the GNU Lesser General Public License for more details. | 
					
						
							| 
									
										
										
										
											2014-01-08 10:21:02 +01:00
										 |  |  | # | 
					
						
							| 
									
										
										
										
											2016-05-11 21:22:25 -07: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 10:21:02 +01:00
										 |  |  | ############################################################################## | 
					
						
							| 
									
										
										
										
											2013-06-02 13:54:46 -07:00
										 |  |  | import sys | 
					
						
							| 
									
										
										
										
											2014-08-10 18:00:20 -07:00
										 |  |  | if not sys.version_info[:2] >= (2,6): | 
					
						
							| 
									
										
										
										
											2014-12-19 11: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-13 17:50:44 -08:00
										 |  |  | 
 | 
					
						
							|  |  |  | import os | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | # Find spack's location and its prefix. | 
					
						
							| 
									
										
										
										
											2013-05-15 16:47:50 -07:00
										 |  |  | SPACK_FILE = os.path.realpath(os.path.expanduser(__file__)) | 
					
						
							|  |  |  | os.environ["SPACK_FILE"] = SPACK_FILE | 
					
						
							| 
									
										
										
										
											2013-02-13 17: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-11 18:04:22 -08:00
										 |  |  | SPACK_EXTERNAL_LIBS = os.path.join(SPACK_LIB_PATH, "external") | 
					
						
							|  |  |  | sys.path.insert(0, SPACK_EXTERNAL_LIBS) | 
					
						
							| 
									
										
										
										
											2013-02-13 17:50:44 -08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-11-25 18:33:52 -08:00
										 |  |  | import warnings | 
					
						
							| 
									
										
										
										
											2016-01-25 09:29:51 -06: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-25 18:33:52 -08:00
										 |  |  | with warnings.catch_warnings(): | 
					
						
							| 
									
										
										
										
											2015-12-02 18:10:28 -08:00
										 |  |  |     warnings.filterwarnings("ignore", ".*nose was already imported") | 
					
						
							| 
									
										
										
										
											2015-11-25 18:33:52 -08:00
										 |  |  |     import nose | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-11-23 17: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 09:29:51 -06:00
										 |  |  |         print "WARNING: Spack may fail mysteriously. Couldn't remove orphaned .pyc file: %s" % pyc_file | 
					
						
							| 
									
										
										
										
											2015-11-23 17:39:59 -08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2014-03-16 16:03:49 -07:00
										 |  |  | # If there is no working directory, use the spack prefix. | 
					
						
							|  |  |  | try: | 
					
						
							| 
									
										
										
										
											2014-05-19 16:07:42 -07:00
										 |  |  |     working_dir = os.getcwd() | 
					
						
							| 
									
										
										
										
											2014-03-16 16:03:49 -07:00
										 |  |  | except OSError: | 
					
						
							|  |  |  |     os.chdir(SPACK_PREFIX) | 
					
						
							| 
									
										
										
										
											2014-07-02 23:22:38 -07:00
										 |  |  |     working_dir = SPACK_PREFIX | 
					
						
							| 
									
										
										
										
											2014-03-16 16:03:49 -07:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2013-02-13 17:50:44 -08:00
										 |  |  | # clean up the scope and start using spack package instead. | 
					
						
							|  |  |  | del SPACK_FILE, SPACK_PREFIX, SPACK_LIB_PATH | 
					
						
							| 
									
										
										
										
											2014-03-12 22:24:47 -04:00
										 |  |  | import llnl.util.tty as tty | 
					
						
							| 
									
										
										
										
											2015-05-17 22:29:08 -07:00
										 |  |  | from llnl.util.tty.color import * | 
					
						
							| 
									
										
										
										
											2013-02-13 17:50:44 -08:00
										 |  |  | import spack | 
					
						
							| 
									
										
										
										
											2013-10-07 17:57:27 -07:00
										 |  |  | from spack.error import SpackError | 
					
						
							| 
									
										
										
										
											2014-08-10 11:48:07 -07:00
										 |  |  | from external import argparse | 
					
						
							| 
									
										
										
										
											2013-02-13 17:50:44 -08:00
										 |  |  | 
 | 
					
						
							|  |  |  | # Command parsing | 
					
						
							|  |  |  | parser = argparse.ArgumentParser( | 
					
						
							| 
									
										
										
										
											2015-05-17 22:29:08 -07: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 01:44:38 -08:00
										 |  |  | parser.add_argument('-d', '--debug', action='store_true', | 
					
						
							| 
									
										
										
										
											2014-03-13 14:24:47 -07:00
										 |  |  |                     help="Write out debug logs during compile") | 
					
						
							| 
									
										
										
										
											2015-12-16 15:54:15 -08:00
										 |  |  | parser.add_argument('-D', '--pdb', action='store_true', | 
					
						
							|  |  |  |                     help="Run spack under the pdb debugger") | 
					
						
							| 
									
										
										
										
											2015-02-15 01:44:38 -08:00
										 |  |  | parser.add_argument('-k', '--insecure', action='store_true', | 
					
						
							| 
									
										
										
										
											2015-04-07 10:29:07 -07:00
										 |  |  |                     help="Do not check ssl certificates when downloading.") | 
					
						
							| 
									
										
										
										
											2015-02-15 01:44:38 -08:00
										 |  |  | parser.add_argument('-m', '--mock', action='store_true', | 
					
						
							| 
									
										
										
										
											2013-11-23 13:04:36 -08:00
										 |  |  |                     help="Use mock packages instead of real ones.") | 
					
						
							| 
									
										
										
										
											2015-02-15 01:44:38 -08:00
										 |  |  | parser.add_argument('-p', '--profile', action='store_true', | 
					
						
							|  |  |  |                     help="Profile execution using cProfile.") | 
					
						
							| 
									
										
										
										
											2015-04-07 10:29:07 -07: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-13 17:50:44 -08:00
										 |  |  | 
 | 
					
						
							|  |  |  | # each command module implements a parser() function, to which we pass its | 
					
						
							|  |  |  | # subparser for setup. | 
					
						
							| 
									
										
										
										
											2013-12-12 04:25:31 -08:00
										 |  |  | subparsers = parser.add_subparsers(metavar='SUBCOMMAND', dest="command") | 
					
						
							| 
									
										
										
										
											2013-02-13 17:50:44 -08:00
										 |  |  | 
 | 
					
						
							|  |  |  | import spack.cmd | 
					
						
							|  |  |  | for cmd in spack.cmd.commands: | 
					
						
							|  |  |  |     module = spack.cmd.get_module(cmd) | 
					
						
							| 
									
										
										
										
											2013-02-22 00:20:24 -08:00
										 |  |  |     subparser = subparsers.add_parser(cmd, help=module.description) | 
					
						
							| 
									
										
										
										
											2013-02-13 17:50:44 -08:00
										 |  |  |     module.setup_parser(subparser) | 
					
						
							| 
									
										
										
										
											2014-08-16 14:53:57 -07: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-13 17:50:44 -08:00
										 |  |  | args = parser.parse_args() | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-02-15 01: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-12 14:52:41 -07:00
										 |  |  |     if spack.debug: | 
					
						
							|  |  |  |         import spack.util.debug as debug | 
					
						
							|  |  |  |         debug.register_interrupt_handler() | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-02-15 01:44:38 -08:00
										 |  |  |     spack.spack_working_dir = working_dir | 
					
						
							|  |  |  |     if args.mock: | 
					
						
							| 
									
										
										
										
											2015-11-28 16:21:31 -08:00
										 |  |  |         from spack.repository import RepoPath | 
					
						
							|  |  |  |         spack.repo.swap(RepoPath(spack.mock_packages_path)) | 
					
						
							| 
									
										
										
										
											2015-02-15 01:44:38 -08:00
										 |  |  | 
 | 
					
						
							|  |  |  |     # If the user asked for it, don't check ssl certs. | 
					
						
							|  |  |  |     if args.insecure: | 
					
						
							| 
									
										
										
										
											2015-10-08 00:14:44 -07:00
										 |  |  |         tty.warn("You asked for --insecure, which does not check SSL certificates.") | 
					
						
							| 
									
										
										
										
											2015-02-15 01: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 16:54:51 +02:00
										 |  |  |     except SpackError as e: | 
					
						
							| 
									
										
										
										
											2015-06-06 15:50:01 -07:00
										 |  |  |         e.die() | 
					
						
							| 
									
										
										
										
											2015-02-15 01:44:38 -08:00
										 |  |  |     except KeyboardInterrupt: | 
					
						
							|  |  |  |         sys.stderr.write('\n') | 
					
						
							|  |  |  |         tty.die("Keyboard interrupt.") | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-12-20 20:15:02 -05:00
										 |  |  |     # Allow commands to return values if they want to exit with some other code. | 
					
						
							| 
									
										
										
										
											2015-02-15 01:44:38 -08:00
										 |  |  |     if return_val is None: | 
					
						
							|  |  |  |         sys.exit(0) | 
					
						
							|  |  |  |     elif isinstance(return_val, int): | 
					
						
							|  |  |  |         sys.exit(return_val) | 
					
						
							| 
									
										
										
										
											2013-10-07 17:57:27 -07:00
										 |  |  |     else: | 
					
						
							| 
									
										
										
										
											2015-02-15 01:44:38 -08:00
										 |  |  |         tty.die("Bad return value from command %s: %s" % (args.command, return_val)) | 
					
						
							| 
									
										
										
										
											2015-01-05 02:33:15 -05:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-02-15 01:44:38 -08:00
										 |  |  | if args.profile: | 
					
						
							|  |  |  |     import cProfile | 
					
						
							|  |  |  |     cProfile.run('main()', sort='tottime') | 
					
						
							| 
									
										
										
										
											2015-12-16 15:54:15 -08:00
										 |  |  | elif args.pdb: | 
					
						
							|  |  |  |     import pdb | 
					
						
							|  |  |  |     pdb.run('main()') | 
					
						
							| 
									
										
										
										
											2015-01-05 02:33:15 -05:00
										 |  |  | else: | 
					
						
							| 
									
										
										
										
											2015-02-15 01:44:38 -08:00
										 |  |  |     main() |