From 988d37757f70f8e580db9091f5c9cc2e32ba33d5 Mon Sep 17 00:00:00 2001
From: Greg Becker <becker33@llnl.gov>
Date: Fri, 9 Nov 2018 00:59:28 -0800
Subject: buildcache: update `spack install` to use build cache by default
 (#9772)

---
 lib/spack/spack/binary_distribution.py | 11 ++++++-----
 lib/spack/spack/cmd/install.py         |  2 +-
 lib/spack/spack/package.py             |  2 +-
 lib/spack/spack/test/packaging.py      |  3 +++
 4 files changed, 11 insertions(+), 7 deletions(-)

(limited to 'lib')

diff --git a/lib/spack/spack/binary_distribution.py b/lib/spack/spack/binary_distribution.py
index 71e426346b..5f36677980 100644
--- a/lib/spack/spack/binary_distribution.py
+++ b/lib/spack/spack/binary_distribution.py
@@ -538,11 +538,12 @@ def get_specs(force=False):
         if url.startswith('file'):
             mirror = url.replace('file://', '') + '/build_cache'
             tty.msg("Finding buildcaches in %s" % mirror)
-            files = os.listdir(mirror)
-            for file in files:
-                if re.search('spec.yaml', file):
-                    link = 'file://' + mirror + '/' + file
-                    urls.add(link)
+            if os.path.exists(mirror):
+                files = os.listdir(mirror)
+                for file in files:
+                    if re.search('spec.yaml', file):
+                        link = 'file://' + mirror + '/' + file
+                        urls.add(link)
         else:
             tty.msg("Finding buildcaches on %s" % url)
             p, links = spider(url + "/build_cache")
diff --git a/lib/spack/spack/cmd/install.py b/lib/spack/spack/cmd/install.py
index d1aaf20f1b..26e77b474a 100644
--- a/lib/spack/spack/cmd/install.py
+++ b/lib/spack/spack/cmd/install.py
@@ -75,7 +75,7 @@ the dependencies"""
         '--dont-restage', action='store_true',
         help="if a partial install is detected, don't delete prior state")
     subparser.add_argument(
-        '--use-cache', action='store_true', dest='use_cache',
+        '--no-cache', action='store_false', dest='use_cache',
         help="check for pre-built Spack packages in mirrors")
     subparser.add_argument(
         '--show-log-on-error', action='store_true',
diff --git a/lib/spack/spack/package.py b/lib/spack/spack/package.py
index d164f9e010..279ed89d04 100644
--- a/lib/spack/spack/package.py
+++ b/lib/spack/spack/package.py
@@ -1403,7 +1403,7 @@ class PackageBase(with_metaclass(PackageMeta, PackageViewMixin, object)):
 
         tty.msg(colorize('@*{Installing} @*g{%s}' % self.name))
 
-        if kwargs.get('use_cache', False):
+        if kwargs.get('use_cache', True):
             if self.try_install_from_binary_cache(explicit):
                 tty.msg('Successfully installed %s from binary cache'
                         % self.name)
diff --git a/lib/spack/spack/test/packaging.py b/lib/spack/spack/test/packaging.py
index 2b673f217e..ae7d7678ae 100644
--- a/lib/spack/spack/test/packaging.py
+++ b/lib/spack/spack/test/packaging.py
@@ -198,6 +198,9 @@ echo $PATH"""
     shutil.rmtree(mirror_path)
     stage.destroy()
 
+    # Remove cached binary specs since we deleted the mirror
+    bindist._cached_specs = None
+
 
 def test_relocate_text(tmpdir):
     with tmpdir.as_cwd():
-- 
cgit v1.2.3-70-g09d2