summaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
authorTodd Gamblin <tgamblin@llnl.gov>2014-12-25 18:01:51 -0800
committerTodd Gamblin <tgamblin@llnl.gov>2014-12-25 18:01:51 -0800
commitb80a0e1da5a03cae3e4d01b77534f70cd2b0ef77 (patch)
tree4bd5a96a9010feb98aa6eee44d673a3b5f754815 /lib
parent37bdbdd9906bb4d89f917732325a346c5cdbb31f (diff)
parent0bc861db6e8edf470c91be81e60546b0619216de (diff)
downloadspack-b80a0e1da5a03cae3e4d01b77534f70cd2b0ef77.tar.gz
spack-b80a0e1da5a03cae3e4d01b77534f70cd2b0ef77.tar.bz2
spack-b80a0e1da5a03cae3e4d01b77534f70cd2b0ef77.tar.xz
spack-b80a0e1da5a03cae3e4d01b77534f70cd2b0ef77.zip
Merge branch 'features/qt' into develop
Diffstat (limited to 'lib')
-rw-r--r--lib/spack/llnl/util/filesystem.py15
-rw-r--r--lib/spack/spack/build_environment.py8
-rw-r--r--lib/spack/spack/cmd/env.py69
-rw-r--r--lib/spack/spack/package.py32
4 files changed, 116 insertions, 8 deletions
diff --git a/lib/spack/llnl/util/filesystem.py b/lib/spack/llnl/util/filesystem.py
index 6a04d98a18..9f08832598 100644
--- a/lib/spack/llnl/util/filesystem.py
+++ b/lib/spack/llnl/util/filesystem.py
@@ -30,6 +30,7 @@ import os
import sys
import re
import shutil
+import stat
import errno
import getpass
from contextlib import contextmanager, closing
@@ -63,8 +64,11 @@ def filter_file(regex, repl, *filenames, **kwargs):
# Allow strings to use \1, \2, etc. for replacement, like sed
if not callable(repl):
unescaped = repl.replace(r'\\', '\\')
- repl = lambda m: re.sub(
- r'\\([0-9])', lambda x: m.group(int(x.group(1))), unescaped)
+ def replace_groups_with_groupid(m):
+ def groupid_to_group(x):
+ return m.group(int(x.group(1)))
+ return re.sub(r'\\([1-9])', groupid_to_group, unescaped)
+ repl = replace_groups_with_groupid
if string:
regex = re.escape(regex)
@@ -142,6 +146,13 @@ def install(src, dest):
shutil.copy(src, dest)
set_install_permissions(dest)
+ src_mode = os.stat(src).st_mode
+ dest_mode = os.stat(dest).st_mode
+ if src_mode | stat.S_IXUSR: dest_mode |= stat.S_IXUSR
+ if src_mode | stat.S_IXGRP: dest_mode |= stat.S_IXGRP
+ if src_mode | stat.S_IXOTH: dest_mode |= stat.S_IXOTH
+ os.chmod(dest, dest_mode)
+
def expand_user(path):
"""Find instances of '%u' in a path and replace with the current user's
diff --git a/lib/spack/spack/build_environment.py b/lib/spack/spack/build_environment.py
index a2fcff1f10..45353ec640 100644
--- a/lib/spack/spack/build_environment.py
+++ b/lib/spack/spack/build_environment.py
@@ -190,6 +190,7 @@ def set_module_variables_for_package(pkg):
m.makedirs = os.makedirs
m.remove = os.remove
m.removedirs = os.removedirs
+ m.symlink = os.symlink
m.mkdirp = mkdirp
m.install = install
@@ -199,3 +200,10 @@ def set_module_variables_for_package(pkg):
# Useful directories within the prefix are encapsulated in
# a Prefix object.
m.prefix = pkg.prefix
+
+
+def setup_package(pkg):
+ """Execute all environment setup routines."""
+ set_compiler_environment_variables(pkg)
+ set_build_environment_variables(pkg)
+ set_module_variables_for_package(pkg)
diff --git a/lib/spack/spack/cmd/env.py b/lib/spack/spack/cmd/env.py
new file mode 100644
index 0000000000..bde76b5daf
--- /dev/null
+++ b/lib/spack/spack/cmd/env.py
@@ -0,0 +1,69 @@
+##############################################################################
+# Copyright (c) 2013, Lawrence Livermore National Security, LLC.
+# Produced at the Lawrence Livermore National Laboratory.
+#
+# This file is part of Spack.
+# Written by Todd Gamblin, tgamblin@llnl.gov, All rights reserved.
+# LLNL-CODE-647188
+#
+# For details, see https://scalability-llnl.github.io/spack
+# Please also see the LICENSE file for our notice and the LGPL.
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License (as published by
+# the Free Software Foundation) version 2.1 dated February 1999.
+#
+# 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
+# conditions of the GNU General Public License for more details.
+#
+# 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
+##############################################################################
+import os
+from external import argparse
+import llnl.util.tty as tty
+import spack.cmd
+import spack.build_environment as build_env
+
+description = "Run a command with the environment for a particular spec's install."
+
+def setup_parser(subparser):
+ subparser.add_argument(
+ 'spec', nargs=argparse.REMAINDER, help="specs of package environment to emulate.")
+
+
+def env(parser, args):
+ if not args.spec:
+ tty.die("spack env requires a spec.")
+
+ # Specs may have spaces in them, so if they do, require that the
+ # caller put a '--' between the spec and the command to be
+ # executed. If there is no '--', assume that the spec is the
+ # first argument.
+ sep = '--'
+ if sep in args.spec:
+ s = args.spec.index(sep)
+ spec = args.spec[:s]
+ cmd = args.spec[s+1:]
+ else:
+ spec = args.spec[0]
+ cmd = args.spec[1:]
+
+ specs = spack.cmd.parse_specs(spec, concretize=True)
+ if len(specs) > 1:
+ tty.die("spack env only takes one spec.")
+ spec = specs[0]
+
+ build_env.setup_package(spec.package)
+
+ if not cmd:
+ # If no command act like the "env" command and print out env vars.
+ for key, val in os.environ.items():
+ print "%s=%s" % (key, val)
+
+ else:
+ # Otherwise execute the command with the new environment
+ os.execvp(cmd[0], cmd)
diff --git a/lib/spack/spack/package.py b/lib/spack/spack/package.py
index fa91dbbbea..1a797e88b1 100644
--- a/lib/spack/spack/package.py
+++ b/lib/spack/spack/package.py
@@ -35,6 +35,7 @@ README.
"""
import os
import re
+import time
import inspect
import subprocess
import platform as py_platform
@@ -390,6 +391,10 @@ class Package(object):
if not hasattr(self, 'list_depth'):
self.list_depth = 1
+ # Set up some internal variables for timing.
+ self._fetch_time = 0.0
+ self._total_time = 0.0
+
@property
def version(self):
@@ -606,6 +611,7 @@ class Package(object):
if not self.spec.concrete:
raise ValueError("Can only fetch concrete packages.")
+ start_time = time.time()
if spack.do_checksum and not self.version in self.versions:
tty.warn("There is no checksum on file to fetch %s safely."
% self.spec.format('$_$@'))
@@ -624,6 +630,7 @@ class Package(object):
"Will not fetch %s." % self.spec.format('$_$@'), checksum_msg)
self.stage.fetch()
+ self._fetch_time = time.time() - start_time
if spack.do_checksum and self.version in self.versions:
self.stage.check()
@@ -655,8 +662,11 @@ class Package(object):
# Kick off the stage first.
self.do_stage()
+ # Package can add its own patch function.
+ has_patch_fun = hasattr(self, 'patch') and callable(self.patch)
+
# If there are no patches, note it.
- if not self.patches:
+ if not self.patches and not has_patch_fun:
tty.msg("No patches needed for %s." % self.name)
return
@@ -679,7 +689,7 @@ class Package(object):
tty.msg("Already patched %s" % self.name)
return
- # Apply all the patches for specs that match this on
+ # Apply all the patches for specs that match this one
for spec, patch_list in self.patches.items():
if self.spec.satisfies(spec):
for patch in patch_list:
@@ -697,6 +707,11 @@ class Package(object):
os.remove(bad_file)
touch(good_file)
+ if has_patch_fun:
+ self.patch()
+
+ tty.msg("Patched %s" % self.name)
+
def do_install(self, **kwargs):
"""This class should call this version of the install method.
@@ -720,6 +735,7 @@ class Package(object):
if not ignore_deps:
self.do_install_dependencies()
+ start_time = time.time()
if not fake_install:
self.do_patch()
@@ -742,9 +758,7 @@ class Package(object):
spack.install_layout.make_path_for_spec(self.spec)
# Set up process's build environment before running install.
- build_env.set_compiler_environment_variables(self)
- build_env.set_build_environment_variables(self)
- build_env.set_module_variables_for_package(self)
+ build_env.setup_package(self)
if fake_install:
mkdirp(self.prefix.bin)
@@ -765,7 +779,13 @@ class Package(object):
if not keep_stage:
self.stage.destroy()
- tty.msg("Successfully installed %s" % self.name)
+ # Stop timer.
+ self._total_time = time.time() - start_time
+ build_time = self._total_time - self._fetch_time
+
+ tty.msg("Successfully installed %s." % self.name,
+ "Fetch: %.2f sec. Build: %.2f sec. Total: %.2f sec."
+ % (self._fetch_time, build_time, self._total_time))
print_pkg(self.prefix)
# Use os._exit here to avoid raising a SystemExit exception,