Skip to content
Snippets Groups Projects
Unverified Commit ae878285 authored by Patrick Gartung's avatar Patrick Gartung Committed by GitHub
Browse files

buildcache cmd: add explicit message with default output dir for buildcaches. (#15090)

* Make -d directory a required option. Print messages about where buildcaches will be written.

* Add mutually exclusive required options

* spack commands --update-completion

* Apply @opadron's patch

* Update share/spack/spack-completion.bash

* Incorporate @opadron's suggestions
parent 00090f8f
No related branches found
No related tags found
No related merge requests found
...@@ -433,6 +433,9 @@ def build_tarball(spec, outdir, force=False, rel=False, unsigned=False, ...@@ -433,6 +433,9 @@ def build_tarball(spec, outdir, force=False, rel=False, unsigned=False,
web_util.push_to_url( web_util.push_to_url(
specfile_path, remote_specfile_path, keep_original=False) specfile_path, remote_specfile_path, keep_original=False)
tty.msg('Buildache for "%s" written to \n %s' %
(spec, remote_spackfile_path))
try: try:
# create an index.html for the build_cache directory so specs can be # create an index.html for the build_cache directory so specs can be
# found # found
......
...@@ -52,9 +52,22 @@ def setup_parser(subparser): ...@@ -52,9 +52,22 @@ def setup_parser(subparser):
create.add_argument('-k', '--key', metavar='key', create.add_argument('-k', '--key', metavar='key',
type=str, default=None, type=str, default=None,
help="Key for signing.") help="Key for signing.")
create.add_argument('-d', '--directory', metavar='directory', output = create.add_mutually_exclusive_group(required=True)
type=str, default='.', output.add_argument('-d', '--directory',
help="directory in which to save the tarballs.") metavar='directory',
type=str,
help="local directory where " +
"buildcaches will be written.")
output.add_argument('-m', '--mirror-name',
metavar='mirror-name',
type=str,
help="name of the mirror where " +
"buildcaches will be written.")
output.add_argument('--mirror-url',
metavar='mirror-url',
type=str,
help="URL of the mirror where " +
"buildcaches will be written.")
create.add_argument('--no-rebuild-index', action='store_true', create.add_argument('--no-rebuild-index', action='store_true',
default=False, help="skip rebuilding index after " + default=False, help="skip rebuilding index after " +
"building package(s)") "building package(s)")
...@@ -310,8 +323,9 @@ def match_downloaded_specs(pkgs, allow_multiple_matches=False, force=False, ...@@ -310,8 +323,9 @@ def match_downloaded_specs(pkgs, allow_multiple_matches=False, force=False,
return specs_from_cli return specs_from_cli
def _createtarball(env, spec_yaml, packages, add_spec, add_deps, directory, def _createtarball(env, spec_yaml, packages, add_spec, add_deps,
key, force, rel, unsigned, allow_root, no_rebuild_index): output_location, key, force, rel, unsigned, allow_root,
no_rebuild_index):
if spec_yaml: if spec_yaml:
packages = set() packages = set()
with open(spec_yaml, 'r') as fd: with open(spec_yaml, 'r') as fd:
...@@ -331,13 +345,12 @@ def _createtarball(env, spec_yaml, packages, add_spec, add_deps, directory, ...@@ -331,13 +345,12 @@ def _createtarball(env, spec_yaml, packages, add_spec, add_deps, directory,
pkgs = set(packages) pkgs = set(packages)
specs = set() specs = set()
outdir = '.' mirror = spack.mirror.MirrorCollection().lookup(output_location)
if directory:
outdir = directory
mirror = spack.mirror.MirrorCollection().lookup(outdir)
outdir = url_util.format(mirror.push_url) outdir = url_util.format(mirror.push_url)
msg = 'Buildcache files will be output to %s/build_cache' % outdir
tty.msg(msg)
signkey = None signkey = None
if key: if key:
signkey = key signkey = key
...@@ -380,7 +393,7 @@ def _createtarball(env, spec_yaml, packages, add_spec, add_deps, directory, ...@@ -380,7 +393,7 @@ def _createtarball(env, spec_yaml, packages, add_spec, add_deps, directory,
tty.debug('writing tarballs to %s/build_cache' % outdir) tty.debug('writing tarballs to %s/build_cache' % outdir)
for spec in specs: for spec in specs:
tty.msg('creating binary cache file for package %s ' % spec.format()) tty.debug('creating binary cache file for package %s ' % spec.format())
bindist.build_tarball(spec, outdir, force, rel, bindist.build_tarball(spec, outdir, force, rel,
unsigned, allow_root, signkey, unsigned, allow_root, signkey,
not no_rebuild_index) not no_rebuild_index)
...@@ -392,11 +405,46 @@ def createtarball(args): ...@@ -392,11 +405,46 @@ def createtarball(args):
# restrict matching to current environment if one is active # restrict matching to current environment if one is active
env = ev.get_env(args, 'buildcache create') env = ev.get_env(args, 'buildcache create')
output_location = None
if args.directory:
output_location = args.directory
# User meant to provide a path to a local directory.
# Ensure that they did not accidentally pass a URL.
scheme = url_util.parse(output_location, scheme='<missing>').scheme
if scheme != '<missing>':
raise ValueError(
'"--directory" expected a local path; got a URL, instead')
# User meant to provide a path to a local directory.
# Ensure that the mirror lookup does not mistake it for a named mirror.
output_location = 'file://' + output_location
elif args.mirror_name:
output_location = args.mirror_name
# User meant to provide the name of a preconfigured mirror.
# Ensure that the mirror lookup actually returns a named mirror.
result = spack.mirror.MirrorCollection().lookup(output_location)
if result.name == "<unnamed>":
raise ValueError(
'no configured mirror named "{name}"'.format(
name=output_location))
elif args.mirror_url:
output_location = args.mirror_url
# User meant to provide a URL for an anonymous mirror.
# Ensure that they actually provided a URL.
scheme = url_util.parse(output_location, scheme='<missing>').scheme
if scheme == '<missing>':
raise ValueError(
'"{url}" is not a valid URL'.format(url=output_location))
add_spec = ('package' in args.things_to_install) add_spec = ('package' in args.things_to_install)
add_deps = ('dependencies' in args.things_to_install) add_deps = ('dependencies' in args.things_to_install)
_createtarball(env, args.spec_yaml, args.specs, add_spec, add_deps, _createtarball(env, args.spec_yaml, args.specs, add_spec, add_deps,
args.directory, args.key, args.force, args.rel, output_location, args.key, args.force, args.rel,
args.unsigned, args.allow_root, args.no_rebuild_index) args.unsigned, args.allow_root, args.no_rebuild_index)
......
...@@ -382,7 +382,7 @@ _spack_buildcache() { ...@@ -382,7 +382,7 @@ _spack_buildcache() {
_spack_buildcache_create() { _spack_buildcache_create() {
if $list_options if $list_options
then then
SPACK_COMPREPLY="-h --help -r --rel -f --force -u --unsigned -a --allow-root -k --key -d --directory --no-rebuild-index -y --spec-yaml --only" SPACK_COMPREPLY="-h --help -r --rel -f --force -u --unsigned -a --allow-root -k --key -d --directory -m --mirror-name --mirror-url --no-rebuild-index -y --spec-yaml --only"
else else
_all_packages _all_packages
fi fi
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment