diff options
author | Jeffrey Salmond <js947@users.noreply.github.com> | 2020-06-26 16:01:12 +0100 |
---|---|---|
committer | GitHub <noreply@github.com> | 2020-06-26 10:01:12 -0500 |
commit | 1602b7a56192c23fb7fc110a1c8a17ec0837bdd3 (patch) | |
tree | 24ae56b5c740822f2175943c9eddcfd65d583b4a | |
parent | ec108dbebdbb00ab517dd8f84dbb976d6078a93a (diff) | |
download | spack-1602b7a56192c23fb7fc110a1c8a17ec0837bdd3.tar.gz spack-1602b7a56192c23fb7fc110a1c8a17ec0837bdd3.tar.bz2 spack-1602b7a56192c23fb7fc110a1c8a17ec0837bdd3.tar.xz spack-1602b7a56192c23fb7fc110a1c8a17ec0837bdd3.zip |
add environment-awareness to `buildcache create` (#16580)
* add buildcache create test
* add functionality and test to create buildcache from environment
* use env.concretized_user_specs rather than env.roots to get concretized specs, as suggested in review from becker33
-rw-r--r-- | lib/spack/spack/cmd/buildcache.py | 8 | ||||
-rw-r--r-- | lib/spack/spack/test/cmd/buildcache.py | 51 |
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.""" |