def build_tarball(spec, outdir, force=False, rel=False, unsigned=False, allow_root=False, key=None, regenerate_index=False):
    '\n    Build a tarball from given spec and put it into the directory structure\n    used at the mirror (following <tarball_directory_name>).\n    '
    if (not spec.concrete):
        raise ValueError('spec must be concrete to build tarball')
    tmpdir = tempfile.mkdtemp()
    cache_prefix = build_cache_prefix(tmpdir)
    tarfile_name = tarball_name(spec, '.tar.gz')
    tarfile_dir = os.path.join(cache_prefix, tarball_directory_name(spec))
    tarfile_path = os.path.join(tarfile_dir, tarfile_name)
    spackfile_path = os.path.join(cache_prefix, tarball_path_name(spec, '.spack'))
    remote_spackfile_path = url_util.join(outdir, os.path.relpath(spackfile_path, tmpdir))
    mkdirp(tarfile_dir)
    if web_util.url_exists(remote_spackfile_path):
        if force:
            web_util.remove_url(remote_spackfile_path)
        else:
            raise NoOverwriteException(url_util.format(remote_spackfile_path))
    spec_file = os.path.join(spec.prefix, '.spack', 'spec.yaml')
    specfile_name = tarball_name(spec, '.spec.yaml')
    specfile_path = os.path.realpath(os.path.join(cache_prefix, specfile_name))
    remote_specfile_path = url_util.join(outdir, os.path.relpath(specfile_path, os.path.realpath(tmpdir)))
    if web_util.url_exists(remote_specfile_path):
        if force:
            web_util.remove_url(remote_specfile_path)
        else:
            raise NoOverwriteException(url_util.format(remote_specfile_path))
    workdir = os.path.join(tmpdir, os.path.basename(spec.prefix))
    temp_tarfile_name = tarball_name(spec, '.tar')
    temp_tarfile_path = os.path.join(tarfile_dir, temp_tarfile_name)
    with closing(tarfile.open(temp_tarfile_path, 'w')) as tar:
        tar.add(name=('%s' % spec.prefix), arcname='.')
    with closing(tarfile.open(temp_tarfile_path, 'r')) as tar:
        tar.extractall(workdir)
    os.remove(temp_tarfile_path)
    write_buildinfo_file(spec, workdir, rel)
    if rel:
        try:
            make_package_relative(workdir, spec, allow_root)
        except Exception as e:
            shutil.rmtree(workdir)
            shutil.rmtree(tarfile_dir)
            shutil.rmtree(tmpdir)
            tty.die(e)
    else:
        try:
            check_package_relocatable(workdir, spec, allow_root)
        except Exception as e:
            shutil.rmtree(workdir)
            shutil.rmtree(tarfile_dir)
            shutil.rmtree(tmpdir)
            tty.die(e)
    with closing(tarfile.open(tarfile_path, 'w:gz')) as tar:
        tar.add(name=('%s' % workdir), arcname=('%s' % os.path.basename(spec.prefix)))
    shutil.rmtree(workdir)
    checksum = checksum_tarball(tarfile_path)
    with open(spec_file, 'r') as inputfile:
        content = inputfile.read()
        spec_dict = yaml.load(content)
    bchecksum = {}
    bchecksum['hash_algorithm'] = 'sha256'
    bchecksum['hash'] = checksum
    spec_dict['binary_cache_checksum'] = bchecksum
    buildinfo = {}
    buildinfo['relative_prefix'] = os.path.relpath(spec.prefix, spack.store.layout.root)
    buildinfo['relative_rpaths'] = rel
    spec_dict['buildinfo'] = buildinfo
    spec_dict['full_hash'] = spec.full_hash()
    tty.debug('The full_hash ({0}) of {1} will be written into {2}'.format(spec_dict['full_hash'], spec.name, url_util.format(remote_specfile_path)))
    tty.debug(spec.tree())
    with open(specfile_path, 'w') as outfile:
        outfile.write(syaml.dump(spec_dict))
    if (not unsigned):
        sign_tarball(key, force, specfile_path)
    with closing(tarfile.open(spackfile_path, 'w')) as tar:
        tar.add(name=tarfile_path, arcname=('%s' % tarfile_name))
        tar.add(name=specfile_path, arcname=('%s' % specfile_name))
        if (not unsigned):
            tar.add(name=('%s.asc' % specfile_path), arcname=('%s.asc' % specfile_name))
    os.remove(tarfile_path)
    if (not unsigned):
        os.remove(('%s.asc' % specfile_path))
    web_util.push_to_url(spackfile_path, remote_spackfile_path, keep_original=False)
    web_util.push_to_url(specfile_path, remote_specfile_path, keep_original=False)
    tty.msg(('Buildache for "%s" written to \n %s' % (spec, remote_spackfile_path)))
    try:
        if regenerate_index:
            generate_package_index(url_util.join(outdir, os.path.relpath(cache_prefix, tmpdir)))
    finally:
        shutil.rmtree(tmpdir)
    return None
Build a tarball from given spec and put it into the directory structure
used at the mirror (following <tarball_directory_name>).
def build_tarball(spec, outdir, force=False, rel=False, unsigned=False, allow_root=False, key=None, regenerate_index=False):
    '\n    Build a tarball from given spec and put it into the directory structure\n    used at the mirror (following <tarball_directory_name>).\n    '
    if (not spec.concrete):
        raise ValueError('spec must be concrete to build tarball')
    tmpdir = tempfile.mkdtemp()
    cache_prefix = build_cache_prefix(tmpdir)
    tarfile_name = tarball_name(spec, '.tar.gz')
    tarfile_dir = os.path.join(cache_prefix, tarball_directory_name(spec))
    tarfile_path = os.path.join(tarfile_dir, tarfile_name)
    spackfile_path = os.path.join(cache_prefix, tarball_path_name(spec, '.spack'))
    remote_spackfile_path = url_util.join(outdir, os.path.relpath(spackfile_path, tmpdir))
    mkdirp(tarfile_dir)
    if web_util.url_exists(remote_spackfile_path):
        if force:
            web_util.remove_url(remote_spackfile_path)
        else:
            raise NoOverwriteException(url_util.format(remote_spackfile_path))
    spec_file = os.path.join(spec.prefix, '.spack', 'spec.yaml')
    specfile_name = tarball_name(spec, '.spec.yaml')
    specfile_path = os.path.realpath(os.path.join(cache_prefix, specfile_name))
    remote_specfile_path = url_util.join(outdir, os.path.relpath(specfile_path, os.path.realpath(tmpdir)))
    if web_util.url_exists(remote_specfile_path):
        if force:
            web_util.remove_url(remote_specfile_path)
        else:
            raise NoOverwriteException(url_util.format(remote_specfile_path))
    workdir = os.path.join(tmpdir, os.path.basename(spec.prefix))
    temp_tarfile_name = tarball_name(spec, '.tar')
    temp_tarfile_path = os.path.join(tarfile_dir, temp_tarfile_name)
    with closing(tarfile.open(temp_tarfile_path, 'w')) as tar:
        tar.add(name=('%s' % spec.prefix), arcname='.')
    with closing(tarfile.open(temp_tarfile_path, 'r')) as tar:
        tar.extractall(workdir)
    os.remove(temp_tarfile_path)
    write_buildinfo_file(spec, workdir, rel)
    if rel:
        try:
            make_package_relative(workdir, spec, allow_root)
        except Exception as e:
            shutil.rmtree(workdir)
            shutil.rmtree(tarfile_dir)
            shutil.rmtree(tmpdir)
            tty.die(e)
    else:
        try:
            check_package_relocatable(workdir, spec, allow_root)
        except Exception as e:
            shutil.rmtree(workdir)
            shutil.rmtree(tarfile_dir)
            shutil.rmtree(tmpdir)
            tty.die(e)
    with closing(tarfile.open(tarfile_path, 'w:gz')) as tar:
        tar.add(name=('%s' % workdir), arcname=('%s' % os.path.basename(spec.prefix)))
    shutil.rmtree(workdir)
    checksum = checksum_tarball(tarfile_path)
    with open(spec_file, 'r') as inputfile:
        content = inputfile.read()
        spec_dict = yaml.load(content)
    bchecksum = {}
    bchecksum['hash_algorithm'] = 'sha256'
    bchecksum['hash'] = checksum
    spec_dict['binary_cache_checksum'] = bchecksum
    buildinfo = {}
    buildinfo['relative_prefix'] = os.path.relpath(spec.prefix, spack.store.layout.root)
    buildinfo['relative_rpaths'] = rel
    spec_dict['buildinfo'] = buildinfo
    spec_dict['full_hash'] = spec.full_hash()
    tty.debug('The full_hash ({0}) of {1} will be written into {2}'.format(spec_dict['full_hash'], spec.name, url_util.format(remote_specfile_path)))
    tty.debug(spec.tree())
    with open(specfile_path, 'w') as outfile:
        outfile.write(syaml.dump(spec_dict))
    if (not unsigned):
        sign_tarball(key, force, specfile_path)
    with closing(tarfile.open(spackfile_path, 'w')) as tar:
        tar.add(name=tarfile_path, arcname=('%s' % tarfile_name))
        tar.add(name=specfile_path, arcname=('%s' % specfile_name))
        if (not unsigned):
            tar.add(name=('%s.asc' % specfile_path), arcname=('%s.asc' % specfile_name))
    os.remove(tarfile_path)
    if (not unsigned):
        os.remove(('%s.asc' % specfile_path))
    web_util.push_to_url(spackfile_path, remote_spackfile_path, keep_original=False)
    web_util.push_to_url(specfile_path, remote_specfile_path, keep_original=False)
    tty.msg(('Buildache for "%s" written to \n %s' % (spec, remote_spackfile_path)))
    try:
        if regenerate_index:
            generate_package_index(url_util.join(outdir, os.path.relpath(cache_prefix, tmpdir)))
    finally:
        shutil.rmtree(tmpdir)
    return None