def test_buildcache(mock_archive, tmpdir): # tweak patchelf to only do a download spec = Spec("patchelf") spec.concretize() pkg = spack.repo.get(spec) fake_fetchify(pkg.fetcher, pkg) mkdirp(os.path.join(pkg.prefix, "bin")) patchelfscr = os.path.join(pkg.prefix, "bin", "patchelf") f = open(patchelfscr, 'w') body = """#!/bin/bash echo $PATH""" f.write(body) f.close() st = os.stat(patchelfscr) os.chmod(patchelfscr, st.st_mode | stat.S_IEXEC) # Install the test package spec = Spec('trivial-install-test-package') spec.concretize() assert spec.concrete pkg = spec.package fake_fetchify(mock_archive.url, pkg) pkg.do_install() pkghash = '/' + spec.dag_hash(7) # Put some non-relocatable file in there filename = os.path.join(spec.prefix, "dummy.txt") with open(filename, "w") as script: script.write(spec.prefix) # Create an absolute symlink linkname = os.path.join(spec.prefix, "link_to_dummy.txt") os.symlink(filename, linkname) # Create the build cache and # put it directly into the mirror mirror_path = os.path.join(str(tmpdir), 'test-mirror') spack.mirror.create(mirror_path, specs=[], no_checksum=True) # register mirror with spack config mirrors = {'spack-mirror-test': 'file://' + mirror_path} spack.config.set('mirrors', mirrors) stage = spack.stage.Stage(mirrors['spack-mirror-test'], name="build_cache", keep=True) stage.create() # setup argument parser parser = argparse.ArgumentParser() buildcache.setup_parser(parser) # Create a private key to sign package with if gpg2 available if has_gnupg2(): spack.util.gpg.Gpg.create(name='test key 1', expires='0', email='*****@*****.**', comment='Spack test key') # Create build cache with signing args = parser.parse_args(['create', '-d', mirror_path, str(spec)]) buildcache.buildcache(parser, args) # Uninstall the package pkg.do_uninstall(force=True) # test overwrite install args = parser.parse_args(['install', '-f', str(pkghash)]) buildcache.buildcache(parser, args) files = os.listdir(spec.prefix) assert 'link_to_dummy.txt' in files assert 'dummy.txt' in files assert os.path.realpath(os.path.join( spec.prefix, 'link_to_dummy.txt')) == os.path.realpath( os.path.join(spec.prefix, 'dummy.txt')) # create build cache with relative path and signing args = parser.parse_args( ['create', '-d', mirror_path, '-f', '-r', str(spec)]) buildcache.buildcache(parser, args) # Uninstall the package pkg.do_uninstall(force=True) # install build cache with verification args = parser.parse_args(['install', str(spec)]) buildcache.install_tarball(spec, args) # test overwrite install args = parser.parse_args(['install', '-f', str(pkghash)]) buildcache.buildcache(parser, args) files = os.listdir(spec.prefix) assert 'link_to_dummy.txt' in files assert 'dummy.txt' in files assert os.path.realpath(os.path.join( spec.prefix, 'link_to_dummy.txt')) == os.path.realpath( os.path.join(spec.prefix, 'dummy.txt')) else: # create build cache without signing args = parser.parse_args( ['create', '-d', mirror_path, '-f', '-u', str(spec)]) buildcache.buildcache(parser, args) # Uninstall the package pkg.do_uninstall(force=True) # install build cache without verification args = parser.parse_args(['install', '-u', str(spec)]) buildcache.install_tarball(spec, args) files = os.listdir(spec.prefix) assert 'link_to_dummy.txt' in files assert 'dummy.txt' in files assert os.path.realpath(os.path.join( spec.prefix, 'link_to_dummy.txt')) == os.path.realpath( os.path.join(spec.prefix, 'dummy.txt')) # test overwrite install without verification args = parser.parse_args(['install', '-f', '-u', str(pkghash)]) buildcache.buildcache(parser, args) # create build cache with relative path args = parser.parse_args( ['create', '-d', mirror_path, '-f', '-r', '-u', str(pkghash)]) buildcache.buildcache(parser, args) # Uninstall the package pkg.do_uninstall(force=True) # install build cache args = parser.parse_args(['install', '-u', str(spec)]) buildcache.install_tarball(spec, args) # test overwrite install args = parser.parse_args(['install', '-f', '-u', str(pkghash)]) buildcache.buildcache(parser, args) files = os.listdir(spec.prefix) assert 'link_to_dummy.txt' in files assert 'dummy.txt' in files assert os.path.realpath(os.path.join( spec.prefix, 'link_to_dummy.txt')) == os.path.realpath( os.path.join(spec.prefix, 'dummy.txt')) # Validate the relocation information buildinfo = bindist.read_buildinfo_file(spec.prefix) assert (buildinfo['relocate_textfiles'] == ['dummy.txt']) assert (buildinfo['relocate_links'] == ['link_to_dummy.txt']) args = parser.parse_args(['list']) buildcache.buildcache(parser, args) args = parser.parse_args(['list', '-f']) buildcache.buildcache(parser, args) args = parser.parse_args(['list', 'trivial']) buildcache.buildcache(parser, args) # Copy a key to the mirror to have something to download shutil.copyfile(mock_gpg_keys_path + '/external.key', mirror_path + '/external.key') args = parser.parse_args(['keys']) buildcache.buildcache(parser, args) args = parser.parse_args(['keys', '-f']) buildcache.buildcache(parser, args) # unregister mirror with spack config mirrors = {} spack.config.set('mirrors', mirrors) shutil.rmtree(mirror_path) stage.destroy() # Remove cached binary specs since we deleted the mirror bindist._cached_specs = None
def test_buildcache(mock_archive, tmpdir): # tweak patchelf to only do a download spec = Spec("patchelf") spec.concretize() pkg = spack.repo.get(spec) fake_fetchify(pkg.fetcher, pkg) mkdirp(os.path.join(pkg.prefix, "bin")) patchelfscr = os.path.join(pkg.prefix, "bin", "patchelf") f = open(patchelfscr, 'w') body = """#!/bin/bash echo $PATH""" f.write(body) f.close() st = os.stat(patchelfscr) os.chmod(patchelfscr, st.st_mode | stat.S_IEXEC) # Install the test package spec = Spec('trivial-install-test-package') spec.concretize() assert spec.concrete pkg = spec.package fake_fetchify(mock_archive.url, pkg) pkg.do_install() pkghash = '/' + spec.dag_hash(7) # Put some non-relocatable file in there filename = os.path.join(spec.prefix, "dummy.txt") with open(filename, "w") as script: script.write(spec.prefix) # Create the build cache and # put it directly into the mirror mirror_path = os.path.join(str(tmpdir), 'test-mirror') spack.mirror.create( mirror_path, specs=[], no_checksum=True ) # register mirror with spack config mirrors = {'spack-mirror-test': 'file://' + mirror_path} spack.config.set('mirrors', mirrors) stage = spack.stage.Stage( mirrors['spack-mirror-test'], name="build_cache", keep=True) stage.create() # setup argument parser parser = argparse.ArgumentParser() buildcache.setup_parser(parser) # Create a private key to sign package with if gpg2 available if has_gnupg2(): spack.util.gpg.Gpg.create(name='test key 1', expires='0', email='*****@*****.**', comment='Spack test key') # Create build cache with signing args = parser.parse_args(['create', '-d', mirror_path, str(spec)]) buildcache.buildcache(parser, args) # Uninstall the package pkg.do_uninstall(force=True) # test overwrite install args = parser.parse_args(['install', '-f', str(pkghash)]) buildcache.buildcache(parser, args) # create build cache with relative path and signing args = parser.parse_args( ['create', '-d', mirror_path, '-f', '-r', str(spec)]) buildcache.buildcache(parser, args) # Uninstall the package pkg.do_uninstall(force=True) # install build cache with verification args = parser.parse_args(['install', str(spec)]) buildcache.install_tarball(spec, args) # test overwrite install args = parser.parse_args(['install', '-f', str(pkghash)]) buildcache.buildcache(parser, args) else: # create build cache without signing args = parser.parse_args( ['create', '-d', mirror_path, '-u', str(spec)]) buildcache.buildcache(parser, args) # Uninstall the package pkg.do_uninstall(force=True) # install build cache without verification args = parser.parse_args(['install', '-u', str(spec)]) buildcache.install_tarball(spec, args) # test overwrite install without verification args = parser.parse_args(['install', '-f', '-u', str(pkghash)]) buildcache.buildcache(parser, args) # create build cache with relative path args = parser.parse_args( ['create', '-d', mirror_path, '-f', '-r', '-u', str(pkghash)]) buildcache.buildcache(parser, args) # Uninstall the package pkg.do_uninstall(force=True) # install build cache args = parser.parse_args(['install', '-u', str(spec)]) buildcache.install_tarball(spec, args) # test overwrite install args = parser.parse_args(['install', '-f', '-u', str(pkghash)]) buildcache.buildcache(parser, args) # Validate the relocation information buildinfo = bindist.read_buildinfo_file(spec.prefix) assert(buildinfo['relocate_textfiles'] == ['dummy.txt']) args = parser.parse_args(['list']) buildcache.buildcache(parser, args) args = parser.parse_args(['list', '-f']) buildcache.buildcache(parser, args) args = parser.parse_args(['list', 'trivial']) buildcache.buildcache(parser, args) # Copy a key to the mirror to have something to download shutil.copyfile(mock_gpg_keys_path + '/external.key', mirror_path + '/external.key') args = parser.parse_args(['keys']) buildcache.buildcache(parser, args) args = parser.parse_args(['keys', '-f']) buildcache.buildcache(parser, args) # unregister mirror with spack config mirrors = {} spack.config.set('mirrors', mirrors) shutil.rmtree(mirror_path) stage.destroy()