From 0394adcf8d740db58a149fb59095cba59b925bb1 Mon Sep 17 00:00:00 2001 From: Todd Gamblin Date: Wed, 25 Feb 2015 10:41:12 -0800 Subject: Minor doc tweak. --- lib/spack/docs/site_configuration.rst | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) (limited to 'lib') diff --git a/lib/spack/docs/site_configuration.rst b/lib/spack/docs/site_configuration.rst index 44071bbfc6..b03df29573 100644 --- a/lib/spack/docs/site_configuration.rst +++ b/lib/spack/docs/site_configuration.rst @@ -8,8 +8,9 @@ Site configuration Temporary space ---------------------------- -.. warning:: Temporary space configuration will be moved to configuration files. - The instructions here are old and refer to ``__init__.py`` +.. warning:: Temporary space configuration will eventually be moved to + configuration files, but currently these settings are in + ``lib/spack/spack/__init__.py`` By default, Spack will try to do all of its building in temporary space. There are two main reasons for this. First, Spack is designed -- cgit v1.2.3-70-g09d2 From 560f2c299a384183d314a0c4968169a0f35cc9c1 Mon Sep 17 00:00:00 2001 From: Todd Gamblin Date: Thu, 12 Mar 2015 10:32:29 -0700 Subject: Add install_tree, force_symlink helper functions. --- lib/spack/llnl/util/filesystem.py | 121 ++++++++++++++++++++++++++++++++--- lib/spack/llnl/util/link_tree.py | 82 ------------------------ lib/spack/spack/build_environment.py | 25 ++++---- 3 files changed, 125 insertions(+), 103 deletions(-) (limited to 'lib') diff --git a/lib/spack/llnl/util/filesystem.py b/lib/spack/llnl/util/filesystem.py index 576aeb16bd..1fdd25f608 100644 --- a/lib/spack/llnl/util/filesystem.py +++ b/lib/spack/llnl/util/filesystem.py @@ -22,9 +22,10 @@ # along with this program; if not, write to the Free Software Foundation, # Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA ############################################################################## -__all__ = ['set_install_permissions', 'install', 'expand_user', 'working_dir', - 'touch', 'touchp', 'mkdirp', 'force_remove', 'join_path', 'ancestor', - 'can_access', 'filter_file', 'change_sed_delimiter', 'is_exe'] +__all__ = ['set_install_permissions', 'install', 'install_tree', 'traverse_tree', + 'expand_user', 'working_dir', 'touch', 'touchp', 'mkdirp', + 'force_remove', 'join_path', 'ancestor', 'can_access', 'filter_file', + 'change_sed_delimiter', 'is_exe', 'force_symlink'] import os import sys @@ -140,12 +141,7 @@ def set_install_permissions(path): os.chmod(path, 0644) -def install(src, dest): - """Manually install a file to a particular location.""" - tty.info("Installing %s to %s" % (src, dest)) - shutil.copy(src, dest) - set_install_permissions(dest) - +def copy_mode(src, 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 @@ -154,6 +150,24 @@ def install(src, dest): os.chmod(dest, dest_mode) +def install(src, dest): + """Manually install a file to a particular location.""" + tty.info("Installing %s to %s" % (src, dest)) + shutil.copy(src, dest) + set_install_permissions(dest) + copy_mode(src, dest) + + +def install_tree(src, dest, **kwargs): + """Manually install a file to a particular location.""" + tty.info("Installing %s to %s" % (src, dest)) + shutil.copytree(src, dest, **kwargs) + + for s, d in traverse_tree(src, dest, follow_nonexisting=False): + set_install_permissions(d) + copy_mode(s, d) + + def is_exe(path): """True if path is an executable file.""" return os.path.isfile(path) and os.access(path, os.X_OK) @@ -210,6 +224,14 @@ def touchp(path): touch(path) +def force_symlink(src, dest): + try: + os.symlink(src, dest) + except OSError, e: + os.remove(dest) + os.symlink(src, dest) + + def join_path(prefix, *args): path = str(prefix) for elt in args: @@ -228,3 +250,84 @@ def ancestor(dir, n=1): def can_access(file_name): """True if we have read/write access to the file.""" return os.access(file_name, os.R_OK|os.W_OK) + + +def traverse_tree(source_root, dest_root, rel_path='', **kwargs): + """Traverse two filesystem trees simultaneously. + + Walks the LinkTree directory in pre or post order. Yields each + file in the source directory with a matching path from the dest + directory, along with whether the file is a directory. + e.g., for this tree:: + + root/ + a/ + file1 + file2 + b/ + file3 + + When called on dest, this yields:: + + ('root', 'dest') + ('root/a', 'dest/a') + ('root/a/file1', 'dest/a/file1') + ('root/a/file2', 'dest/a/file2') + ('root/b', 'dest/b') + ('root/b/file3', 'dest/b/file3') + + Optional args: + + order=[pre|post] -- Whether to do pre- or post-order traveral. + + ignore= -- Predicate indicating which files to ignore. + + follow_nonexisting -- Whether to descend into directories in + src that do not exit in dest. Default True. + + follow_links -- Whether to descend into symlinks in src. + + """ + follow_nonexisting = kwargs.get('follow_nonexisting', True) + follow_links = kwargs.get('follow_link', False) + + # Yield in pre or post order? + order = kwargs.get('order', 'pre') + if order not in ('pre', 'post'): + raise ValueError("Order must be 'pre' or 'post'.") + + # List of relative paths to ignore under the src root. + ignore = kwargs.get('ignore', lambda filename: False) + + # Don't descend into ignored directories + if ignore(rel_path): + return + + source_path = os.path.join(source_root, rel_path) + dest_path = os.path.join(dest_root, rel_path) + + # preorder yields directories before children + if order == 'pre': + yield (source_path, dest_path) + + for f in os.listdir(source_path): + source_child = os.path.join(source_path, f) + dest_child = os.path.join(dest_path, f) + rel_child = os.path.join(rel_path, f) + + # Treat as a directory + if os.path.isdir(source_child) and ( + follow_links or not os.path.islink(source_child)): + + # When follow_nonexisting isn't set, don't descend into dirs + # in source that do not exist in dest + if follow_nonexisting or os.path.exists(dest_child): + tuples = traverse_tree(source_root, dest_root, rel_child, **kwargs) + for t in tuples: yield t + + # Treat as a file. + elif not ignore(os.path.join(rel_path, f)): + yield (source_child, dest_child) + + if order == 'post': + yield (source_path, dest_path) diff --git a/lib/spack/llnl/util/link_tree.py b/lib/spack/llnl/util/link_tree.py index 4d778eca1e..583f077b79 100644 --- a/lib/spack/llnl/util/link_tree.py +++ b/lib/spack/llnl/util/link_tree.py @@ -32,88 +32,6 @@ from llnl.util.filesystem import * empty_file_name = '.spack-empty' -def traverse_tree(source_root, dest_root, rel_path='', **kwargs): - """Traverse two filesystem trees simultaneously. - - Walks the LinkTree directory in pre or post order. Yields each - file in the source directory with a matching path from the dest - directory, along with whether the file is a directory. - e.g., for this tree:: - - root/ - a/ - file1 - file2 - b/ - file3 - - When called on dest, this yields:: - - ('root', 'dest') - ('root/a', 'dest/a') - ('root/a/file1', 'dest/a/file1') - ('root/a/file2', 'dest/a/file2') - ('root/b', 'dest/b') - ('root/b/file3', 'dest/b/file3') - - Optional args: - - order=[pre|post] -- Whether to do pre- or post-order traveral. - - ignore= -- Predicate indicating which files to ignore. - - follow_nonexisting -- Whether to descend into directories in - src that do not exit in dest. Default True. - - follow_links -- Whether to descend into symlinks in src. - - """ - follow_nonexisting = kwargs.get('follow_nonexisting', True) - follow_links = kwargs.get('follow_link', False) - - # Yield in pre or post order? - order = kwargs.get('order', 'pre') - if order not in ('pre', 'post'): - raise ValueError("Order must be 'pre' or 'post'.") - - # List of relative paths to ignore under the src root. - ignore = kwargs.get('ignore', lambda filename: False) - - # Don't descend into ignored directories - if ignore(rel_path): - return - - source_path = os.path.join(source_root, rel_path) - dest_path = os.path.join(dest_root, rel_path) - - # preorder yields directories before children - if order == 'pre': - yield (source_path, dest_path) - - for f in os.listdir(source_path): - source_child = os.path.join(source_path, f) - dest_child = os.path.join(dest_path, f) - rel_child = os.path.join(rel_path, f) - - # Treat as a directory - if os.path.isdir(source_child) and ( - follow_links or not os.path.islink(source_child)): - - # When follow_nonexisting isn't set, don't descend into dirs - # in source that do not exist in dest - if follow_nonexisting or os.path.exists(dest_child): - tuples = traverse_tree(source_root, dest_root, rel_child, **kwargs) - for t in tuples: yield t - - # Treat as a file. - elif not ignore(os.path.join(rel_path, f)): - yield (source_child, dest_child) - - if order == 'post': - yield (source_path, dest_path) - - - class LinkTree(object): """Class to create trees of symbolic links from a source directory. diff --git a/lib/spack/spack/build_environment.py b/lib/spack/spack/build_environment.py index 59b25d96e7..d11e2e270c 100644 --- a/lib/spack/spack/build_environment.py +++ b/lib/spack/spack/build_environment.py @@ -189,18 +189,19 @@ def set_module_variables_for_package(pkg): m.std_cmake_args.append('-DCMAKE_INSTALL_RPATH=%s' % ":".join(get_rpaths(pkg))) # Emulate some shell commands for convenience - m.pwd = os.getcwd - m.cd = os.chdir - m.mkdir = os.mkdir - m.makedirs = os.makedirs - m.remove = os.remove - m.removedirs = os.removedirs - m.symlink = os.symlink - - m.mkdirp = mkdirp - m.install = install - m.rmtree = shutil.rmtree - m.move = shutil.move + m.pwd = os.getcwd + m.cd = os.chdir + m.mkdir = os.mkdir + m.makedirs = os.makedirs + m.remove = os.remove + m.removedirs = os.removedirs + m.symlink = os.symlink + + m.mkdirp = mkdirp + m.install = install + m.install_tree = install_tree + m.rmtree = shutil.rmtree + m.move = shutil.move # Useful directories within the prefix are encapsulated in # a Prefix object. -- cgit v1.2.3-70-g09d2 From 132aa690d80731147c701446b3de099d4647f4e9 Mon Sep 17 00:00:00 2001 From: Todd Gamblin Date: Thu, 12 Mar 2015 10:39:26 -0700 Subject: Remove superfluous env scripts (avoid specifically named ones). --- lib/spack/env/clang | 1 - lib/spack/env/clang++ | 1 - lib/spack/env/g++ | 1 - lib/spack/env/gcc | 1 - 4 files changed, 4 deletions(-) delete mode 120000 lib/spack/env/clang delete mode 120000 lib/spack/env/clang++ delete mode 120000 lib/spack/env/g++ delete mode 120000 lib/spack/env/gcc (limited to 'lib') diff --git a/lib/spack/env/clang b/lib/spack/env/clang deleted file mode 120000 index 2652f5f42c..0000000000 --- a/lib/spack/env/clang +++ /dev/null @@ -1 +0,0 @@ -cc \ No newline at end of file diff --git a/lib/spack/env/clang++ b/lib/spack/env/clang++ deleted file mode 120000 index 2652f5f42c..0000000000 --- a/lib/spack/env/clang++ +++ /dev/null @@ -1 +0,0 @@ -cc \ No newline at end of file diff --git a/lib/spack/env/g++ b/lib/spack/env/g++ deleted file mode 120000 index 2652f5f42c..0000000000 --- a/lib/spack/env/g++ +++ /dev/null @@ -1 +0,0 @@ -cc \ No newline at end of file diff --git a/lib/spack/env/gcc b/lib/spack/env/gcc deleted file mode 120000 index 2652f5f42c..0000000000 --- a/lib/spack/env/gcc +++ /dev/null @@ -1 +0,0 @@ -cc \ No newline at end of file -- cgit v1.2.3-70-g09d2 From f97966d63a0b9d5dabe724c3dbfaaf8f3ebbfd59 Mon Sep 17 00:00:00 2001 From: Todd Gamblin Date: Thu, 12 Mar 2015 23:50:07 -0700 Subject: SPACK-18: simpler build error messages Suppress python stack trace on build error UNLESS in debug mode (spack -d). Now spack shows errors with a single red arrow, and it's easier to find the actual build output. --- lib/spack/spack/package.py | 32 ++++++++++++++++++++++++-------- 1 file changed, 24 insertions(+), 8 deletions(-) (limited to 'lib') diff --git a/lib/spack/spack/package.py b/lib/spack/spack/package.py index 75e6142a9d..36f1e8a777 100644 --- a/lib/spack/spack/package.py +++ b/lib/spack/spack/package.py @@ -62,6 +62,7 @@ from spack.version import * from spack.stage import Stage from spack.util.web import get_pages from spack.util.compression import allowed_archive, extension +from spack.util.executable import ProcessError """Allowed URL schemes for spack packages.""" _ALLOWED_URL_SCHEMES = ["http", "https", "ftp", "file", "git"] @@ -805,6 +806,16 @@ class Package(object): # package naming scheme it likes. spack.install_layout.make_path_for_spec(self.spec) + def cleanup(): + if not keep_prefix: + # If anything goes wrong, remove the install prefix + self.remove_prefix() + else: + tty.warn("Keeping install prefix in place despite error.", + "Spack will think this package is installed." + + "Manually remove this directory to fix:", + self.prefix) + def real_work(): try: tty.msg("Building %s." % self.name) @@ -837,15 +848,20 @@ class Package(object): % (_hms(self._fetch_time), _hms(build_time), _hms(self._total_time))) print_pkg(self.prefix) - except: - if not keep_prefix: - # If anything goes wrong, remove the install prefix - self.remove_prefix() + except ProcessError, e: + # One of the processes returned an error code. + # Suppress detailed stack trace here unless in debug mode + if spack.debug: + raise e else: - tty.warn("Keeping install prefix in place despite error.", - "Spack will think this package is installed." + - "Manually remove this directory to fix:", - self.prefix) + tty.error(e) + + # Still need to clean up b/c there was an error. + cleanup() + + except: + # other exceptions just clean up and raise. + cleanup() raise build_env.fork(self, real_work) -- cgit v1.2.3-70-g09d2