summaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
authorHarmen Stoppels <harmenstoppels@gmail.com>2022-11-15 18:03:17 +0100
committerGitHub <noreply@github.com>2022-11-15 18:03:17 +0100
commitaf74680405c931dab16c6674f9b97a32bf3f1122 (patch)
tree0c6081df5241a6db996f228ff7cf9aaa40d71f99 /lib
parentd1715c5fdf6eaf21e79e3046f331374e21100503 (diff)
downloadspack-af74680405c931dab16c6674f9b97a32bf3f1122.tar.gz
spack-af74680405c931dab16c6674f9b97a32bf3f1122.tar.bz2
spack-af74680405c931dab16c6674f9b97a32bf3f1122.tar.xz
spack-af74680405c931dab16c6674f9b97a32bf3f1122.zip
depfile: improve tab completion (#33773)
This PR allows you to do: ``` spack env create -d . spack -e . add python spack -e . concretize spack -e . env depfile -o Makefile make in<tab> # -> install make install-<tab> # -> install-deps/ make install-deps/py<tab> # -> install-deps/python-x.y.z-hash make install/zl<tab> # -> install/zlib-x.y.z-hash make SP<tab> # -> make SPACK make SPACK_<tab> # -> make SPACK_INSTALL_FLAGS= ```
Diffstat (limited to 'lib')
-rw-r--r--lib/spack/spack/cmd/env.py44
1 files changed, 30 insertions, 14 deletions
diff --git a/lib/spack/spack/cmd/env.py b/lib/spack/spack/cmd/env.py
index 5510c7443a..e4c62758c4 100644
--- a/lib/spack/spack/cmd/env.py
+++ b/lib/spack/spack/cmd/env.py
@@ -673,13 +673,16 @@ class MakeTargetVisitor(object):
return ""
def accept(self, node):
- dag_hash = node.edge.spec.dag_hash()
+ fmt = "{name}-{version}-{hash}"
+ tgt = node.edge.spec.format(fmt)
spec_str = node.edge.spec.format(
"{name}{@version}{%compiler}{variants}{arch=architecture}"
)
buildcache_flag = self.build_cache_flag(node.depth)
- prereqs = " ".join([self.target(dep.spec.dag_hash()) for dep in self.neighbors(node)])
- self.adjacency_list.append((dag_hash, spec_str, buildcache_flag, prereqs))
+ prereqs = " ".join([self.target(dep.spec.format(fmt)) for dep in self.neighbors(node)])
+ self.adjacency_list.append(
+ (tgt, prereqs, node.edge.spec.dag_hash(), spec_str, buildcache_flag)
+ )
# We already accepted this
return True
@@ -690,6 +693,8 @@ def env_depfile(args):
spack.cmd.require_active_env(cmd_name="env depfile")
env = ev.active_environment()
+ # Special make targets are useful when including a makefile in another, and you
+ # need to "namespace" the targets to avoid conflicts.
if args.make_target_prefix is None:
target_prefix = os.path.join(env.env_subdir_path, "makedeps")
else:
@@ -706,10 +711,10 @@ def env_depfile(args):
return os.path.join(target_prefix, name)
def get_install_target(name):
- return os.path.join(target_prefix, ".install", name)
+ return os.path.join(target_prefix, "install", name)
def get_install_deps_target(name):
- return os.path.join(target_prefix, ".install-deps", name)
+ return os.path.join(target_prefix, "install-deps", name)
# What things do we build when running make? By default, we build the
# root specs. If specific specs are provided as input, we build those.
@@ -728,13 +733,22 @@ def env_depfile(args):
)
# Root specs without deps are the prereqs for the environment target
- root_install_targets = [get_install_target(h.dag_hash()) for h in roots]
+ root_install_targets = [get_install_target(h.format("{name}-{version}-{hash}")) for h in roots]
- # Cleanable targets...
- cleanable_targets = [get_install_target(h) for h, _, _, _ in make_targets.adjacency_list]
- cleanable_targets.extend(
- [get_install_deps_target(h) for h, _, _, _ in make_targets.adjacency_list]
- )
+ # All install and install-deps targets
+ all_install_related_targets = []
+
+ # Convenience shortcuts: ensure that `make install/pkg-version-hash` triggers
+ # <absolute path to env>/.spack-env/makedeps/install/pkg-version-hash in case
+ # we don't have a custom make target prefix.
+ phony_convenience_targets = []
+
+ for tgt, _, _, _, _ in make_targets.adjacency_list:
+ all_install_related_targets.append(get_install_target(tgt))
+ all_install_related_targets.append(get_install_deps_target(tgt))
+ if args.make_target_prefix is None:
+ phony_convenience_targets.append(os.path.join("install", tgt))
+ phony_convenience_targets.append(os.path.join("install-deps", tgt))
buf = io.StringIO()
@@ -745,15 +759,17 @@ def env_depfile(args):
"all_target": get_target("all"),
"env_target": get_target("env"),
"clean_target": get_target("clean"),
- "cleanable_targets": " ".join(cleanable_targets),
+ "all_install_related_targets": " ".join(all_install_related_targets),
"root_install_targets": " ".join(root_install_targets),
"dirs_target": get_target("dirs"),
"environment": env.path,
- "install_target": get_target(".install"),
- "install_deps_target": get_target(".install-deps"),
+ "install_target": get_target("install"),
+ "install_deps_target": get_target("install-deps"),
"any_hash_target": get_target("%"),
"jobserver_support": "+" if args.jobserver else "",
"adjacency_list": make_targets.adjacency_list,
+ "phony_convenience_targets": " ".join(phony_convenience_targets),
+ "target_prefix": target_prefix,
}
)