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
This commit is contained in:
Jeffrey Salmond 2020-06-26 16:01:12 +01:00 committed by GitHub
parent ec108dbebd
commit 1602b7a561
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 57 additions and 2 deletions

View File

@ -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()

View File

@ -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."""