summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--lib/spack/spack/cmd/buildcache.py8
-rw-r--r--lib/spack/spack/test/cmd/buildcache.py51
2 files changed, 57 insertions, 2 deletions
diff --git a/lib/spack/spack/cmd/buildcache.py b/lib/spack/spack/cmd/buildcache.py
index ee00f6259f..29048d5787 100644
--- a/lib/spack/spack/cmd/buildcache.py
+++ b/lib/spack/spack/cmd/buildcache.py
@@ -338,10 +338,14 @@ def _createtarball(env, spec_yaml, packages, add_spec, add_deps,
elif packages:
packages = packages
+ elif env:
+ packages = env.concretized_user_specs
+
else:
tty.die("build cache file creation requires at least one" +
- " installed package argument or else path to a" +
- " yaml file containing a spec to install")
+ " installed package spec, an activate environment," +
+ " or else a path to a yaml file containing a spec" +
+ " to install")
pkgs = set(packages)
specs = set()
diff --git a/lib/spack/spack/test/cmd/buildcache.py b/lib/spack/spack/test/cmd/buildcache.py
index 03d09b9771..af02d2d097 100644
--- a/lib/spack/spack/test/cmd/buildcache.py
+++ b/lib/spack/spack/test/cmd/buildcache.py
@@ -5,14 +5,19 @@
import errno
import platform
+import os
import pytest
import spack.main
import spack.binary_distribution
+import spack.environment as ev
+from spack.spec import Spec
buildcache = spack.main.SpackCommand('buildcache')
install = spack.main.SpackCommand('install')
+env = spack.main.SpackCommand('env')
+add = spack.main.SpackCommand('add')
@pytest.fixture()
@@ -45,6 +50,52 @@ def test_buildcache_list_duplicates(mock_get_specs, capsys):
assert output.count('mpileaks') == 3
+def tests_buildcache_create(
+ install_mockery, mock_fetch, monkeypatch, tmpdir):
+ """"Ensure that buildcache create creates output files"""
+ pkg = 'trivial-install-test-package'
+ install(pkg)
+
+ buildcache('create', '-d', str(tmpdir), '--unsigned', pkg)
+
+ spec = Spec(pkg).concretized()
+ tarball_path = spack.binary_distribution.tarball_path_name(spec, '.spack')
+ tarball = spack.binary_distribution.tarball_name(spec, '.spec.yaml')
+ assert os.path.exists(
+ os.path.join(str(tmpdir), 'build_cache', tarball_path))
+ assert os.path.exists(
+ os.path.join(str(tmpdir), 'build_cache', tarball))
+
+
+def tests_buildcache_create_env(
+ install_mockery, mock_fetch, monkeypatch,
+ tmpdir, mutable_mock_env_path):
+ """"Ensure that buildcache create creates output files from env"""
+ pkg = 'trivial-install-test-package'
+
+ env('create', 'test')
+ with ev.read('test'):
+ add(pkg)
+ install()
+
+ buildcache('create', '-d', str(tmpdir), '--unsigned')
+
+ spec = Spec(pkg).concretized()
+ tarball_path = spack.binary_distribution.tarball_path_name(spec, '.spack')
+ tarball = spack.binary_distribution.tarball_name(spec, '.spec.yaml')
+ assert os.path.exists(
+ os.path.join(str(tmpdir), 'build_cache', tarball_path))
+ assert os.path.exists(
+ os.path.join(str(tmpdir), 'build_cache', tarball))
+
+
+def test_buildcache_create_fails_on_noargs(tmpdir):
+ """Ensure that buildcache create fails when given no args or
+ environment."""
+ with pytest.raises(spack.main.SpackCommandError):
+ buildcache('create', '-d', str(tmpdir), '--unsigned')
+
+
def test_buildcache_create_fail_on_perm_denied(
install_mockery, mock_fetch, monkeypatch, tmpdir):
"""Ensure that buildcache create fails on permission denied error."""