From 1808ba3c68c8a063157328883788eef4439785a9 Mon Sep 17 00:00:00 2001 From: Greg Becker Date: Sat, 12 Oct 2019 11:43:37 -0700 Subject: install: add --cache-only option (#12729) * add `--cache-only` option to install * testing for `--cache-only` * remove extraneous stage creation at stage destroy time --- lib/spack/spack/cmd/bootstrap.py | 6 +++++- lib/spack/spack/cmd/install.py | 6 +++++- lib/spack/spack/package.py | 4 +++- lib/spack/spack/test/cmd/install.py | 9 +++++++++ 4 files changed, 22 insertions(+), 3 deletions(-) (limited to 'lib') diff --git a/lib/spack/spack/cmd/bootstrap.py b/lib/spack/spack/cmd/bootstrap.py index 27ebb7320d..71db75c788 100644 --- a/lib/spack/spack/cmd/bootstrap.py +++ b/lib/spack/spack/cmd/bootstrap.py @@ -34,6 +34,9 @@ def setup_parser(subparser): cache_group.add_argument( '--no-cache', action='store_false', dest='use_cache', default=True, help="do not check for pre-built Spack packages in mirrors") + cache_group.add_argument( + '--cache-only', action='store_true', dest='cache_only', default=False, + help="only install package from binary mirrors") cd_group = subparser.add_mutually_exclusive_group() arguments.add_common_arguments(cd_group, ['clean', 'dirty']) @@ -46,7 +49,8 @@ def bootstrap(parser, args, **kwargs): 'install_deps': 'dependencies', 'verbose': args.verbose, 'dirty': args.dirty, - 'use_cache': args.use_cache + 'use_cache': args.use_cache, + 'cache_only': args.cache_only }) # Define requirement dictionary defining general specs which need diff --git a/lib/spack/spack/cmd/install.py b/lib/spack/spack/cmd/install.py index b9923c7e1b..b625078a0b 100644 --- a/lib/spack/spack/cmd/install.py +++ b/lib/spack/spack/cmd/install.py @@ -38,7 +38,8 @@ def update_kwargs_from_args(args, kwargs): 'verbose': args.verbose, 'fake': args.fake, 'dirty': args.dirty, - 'use_cache': args.use_cache + 'use_cache': args.use_cache, + 'cache_only': args.cache_only }) if hasattr(args, 'setup'): setups = set() @@ -81,6 +82,9 @@ the dependencies""" cache_group.add_argument( '--no-cache', action='store_false', dest='use_cache', default=True, help="do not check for pre-built Spack packages in mirrors") + cache_group.add_argument( + '--cache-only', action='store_true', dest='cache_only', default=False, + help="only install package from binary 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 e8d78a6ac7..686bbc2e1e 100644 --- a/lib/spack/spack/package.py +++ b/lib/spack/spack/package.py @@ -1499,6 +1499,7 @@ class PackageBase(with_metaclass(PackageMeta, PackageViewMixin, object)): restage (bool): Force spack to restage the package source. force (bool): Install again, even if already installed. use_cache (bool): Install from binary package, if available. + cache_only (bool): Fail if binary package unavailable. stop_at (InstallPhase): last installation phase to be executed (or None) """ @@ -1577,6 +1578,8 @@ class PackageBase(with_metaclass(PackageMeta, PackageViewMixin, object)): print_pkg(self.prefix) spack.hooks.post_install(self.spec) return + elif kwargs.get('cache_only', False): + tty.die('No binary for %s found and cache-only specified') tty.msg('No binary for %s found: installing from source' % self.name) @@ -1792,7 +1795,6 @@ class PackageBase(with_metaclass(PackageMeta, PackageViewMixin, object)): if restage and self.stage.managed_by_spack: self.stage.destroy() - self.stage.create() return partial diff --git a/lib/spack/spack/test/cmd/install.py b/lib/spack/spack/test/cmd/install.py index 5b5ee1bc49..3892a1da7b 100644 --- a/lib/spack/spack/test/cmd/install.py +++ b/lib/spack/spack/test/cmd/install.py @@ -591,3 +591,12 @@ def test_build_warning_output(tmpdir, mock_fetch, install_mockery, capfd): assert 'WARNING: ALL CAPITAL WARNING!' in msg assert 'foo.c:89: warning: some weird warning!' in msg + + +def test_cache_only_fails(tmpdir, mock_fetch, install_mockery, capfd): + with capfd.disabled(): + try: + install('--cache-only', 'libdwarf') + assert False + except spack.main.SpackCommandError: + pass -- cgit v1.2.3-60-g2f50