Skip to content

Commit

Permalink
create env: warn if upstream environment's config doesn't match (#1137)
Browse files Browse the repository at this point in the history
* create env: warn if upstream environment's config doesn't match

* add testing

* ubuntu-ci-x86_64-gnu.yaml: debug env chaining warnings

* debug ubuntu-ci-x86_64-gnu.yaml

* more debug ubuntu-ci-x86_64-gnu.yaml

* even more debug ubuntu-ci-x86_64-gnu.yaml

* for upstream config check, use filecmp instead of system diff

* debug

* warn if upstream site or common dir does not exist at all

---------

Co-authored-by: Dom Heinzeller <[email protected]>
  • Loading branch information
AlexanderRichert-NOAA and climbfuji authored Jul 29, 2024
1 parent 1774993 commit 2c9cb91
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 1 deletion.
8 changes: 7 additions & 1 deletion .github/workflows/ubuntu-ci-x86_64-gnu.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -177,7 +177,7 @@ jobs:
# Test environment chaining
echo "Test environment chaining"
spack stack create env --name chaintest --template empty --site linux.default --upstream ${ENVDIR}/install --compiler gcc
spack stack create env --name chaintest --template empty --site linux.default --compiler gcc --upstream ${ENVDIR}/install
# Retain config from upstream so we don't have to rebuild:
cp -r ${ENVDIR}/{site,common} $PWD/envs/chaintest/.
spack env activate ${PWD}/envs/chaintest
Expand All @@ -186,6 +186,12 @@ jobs:
unwanted_duplicates=$(( cat envs/chaintest/log.concretize | grep -E '^ - ' | grep -Fv '[email protected]' || true ) | wc -l)
if [ ${unwanted_duplicates} -gt 0 ]; then echo "Environment chaining test failed"; exit 1; fi
spack env deactivate
echo "Verify 'create env' warnings"
echo "# nothing" >> ${SPACK_STACK_DIR}/envs/chaintest/site/packages.yaml
echo "# nothing" >> ${SPACK_STACK_DIR}/envs/chaintest/common/packages.yaml
spack stack create env --name chaintest3 --site linux.default --compiler gcc --upstream ${SPACK_STACK_DIR}/envs/chaintest/install 2>&1 | tee stderr.txt
cnt=$(grep -c "WARNING.*do not match" stderr.txt || true)
if [ $cnt -ne 2 ]; then echo "Missing 'create env' warnings"; exit 1; fi
- name: test-env
run: |
Expand Down
23 changes: 23 additions & 0 deletions spack-ext/lib/jcsda-emc/spack-stack/stack/stack_env.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
from collections import OrderedDict
import copy
import filecmp
import io
import logging
import os
Expand Down Expand Up @@ -279,6 +280,10 @@ def write(self):
spack.config.add(lmod_prefix, scope=env_scope)
spack.config.add(tcl_prefix, scope=env_scope)
if self.upstreams:
env_config_dirs = {
"common": os.path.join(self.env_dir(), "common"),
"site": os.path.join(self.env_dir(), "site"),
}
for upstream_path in self.upstreams:
upstream_path = upstream_path[0]
# spack doesn't handle "~/" correctly, this fixes it:
Expand All @@ -301,6 +306,24 @@ def write(self):
upstream = "upstreams:%s:install_tree:'%s'" % (name, upstream_path)
logging.info("Adding upstream path '%s'" % upstream_path)
spack.config.add(upstream, scope=env_scope)
# Verify that config files match
upstream_config_dirs = {
"common": os.path.normpath(os.path.join(upstream_path, "../common/")),
"site": os.path.normpath(os.path.join(upstream_path, "../site/")),
}
for n in ("common", "site"):
if not os.path.isdir(upstream_config_dirs[n]):
does_not_match = True
else:
comparison = filecmp.dircmp(upstream_config_dirs[n], env_config_dirs[n])
does_not_match = comparison.diff_files or comparison.left_only or comparison.right_only
if does_not_match:
logging.warning(
(f"WARNING: {n} config directories for this environment and upstream "
f"'{upstream_path}' do not match! Verify that you are using the same "
"version of spack-stack, or really, really know what you are doing.")
)

if self.modifypkg:
logging.info("Creating custom repo with packages %s" % ", ".join(self.modifypkg))
env_repo_path = os.path.join(env_dir, "envrepo")
Expand Down

0 comments on commit 2c9cb91

Please sign in to comment.