From 299ecd6f831c4eca28f47276ea1e9eae8c1d1d5c Mon Sep 17 00:00:00 2001 From: Patrick Gartung Date: Thu, 2 Nov 2023 08:00:43 -0500 Subject: [PATCH 1/5] Check for .spack/binary_distribution and skip buildcache creation if it exists --- bin/build-spack-env.sh | 26 +++++++++++++++++--------- 1 file changed, 17 insertions(+), 9 deletions(-) diff --git a/bin/build-spack-env.sh b/bin/build-spack-env.sh index 6a117c7..f3ee63e 100755 --- a/bin/build-spack-env.sh +++ b/bin/build-spack-env.sh @@ -717,22 +717,26 @@ _maybe_cache_binaries() { for cache in "$working_dir/copyBack/spack-$binary_mirror-cache" \ ${extra_sources_write_cache[*]:+"${extra_sources_write_cache[@]}"}; do _report $PROGRESS "caching$msg_extra binary packages for environment $env_name to $cache" - _cmd $DEBUG_1 $PROGRESS \ + for hash in "${hashes_to_cache[@]}";do + if [ ! -f $(spack location -i $hash)/.spack/binary_distribution ]; then + _cmd $DEBUG_1 $PROGRESS \ spack \ ${__debug_spack_buildcache:+-d} \ ${__verbose_spack_buildcache:+-v} \ ${common_spack_opts[*]:+"${common_spack_opts[@]}"} \ - buildcache create -a --deptype=all \ + buildcache create --deptype=all \ ${buildcache_package_opts[*]:+"${buildcache_package_opts[@]}"} \ ${buildcache_key_opts[*]:+"${buildcache_key_opts[@]}"} \ ${buildcache_rel_arg} "$cache" \ - ${hashes_to_cache[*]:+"${hashes_to_cache[@]}"} - _report $PROGRESS "updating build cache index" - _cmd $DEBUG_1 $PROGRESS \ + $hash + fi + done + _report $PROGRESS "updating build cache index" + _cmd $DEBUG_1 $PROGRESS \ spack \ ${common_spack_opts[*]:+"${common_spack_opts[@]}"} \ buildcache update-index -k "$cache" - done + done fi } @@ -1335,13 +1339,17 @@ trap "trap - EXIT; \ _copy_back_logs; \ if (( failed )) && (( want_emergency_buildcache )); then \ tag_text=ALERT _report $ERROR \"emergency buildcache dump...\"; \ - _cmd $ERROR $PIPE spack \ + for spec in \$(spack find -L | sed -Ene 's&^([[:alnum:]]+).*\$&/\\1&p');do \ + if [ ! -f \$(spack location -i \$spec)/.spack/binary_distribution ]; then + _cmd $ERROR $PIPE spack \ \${common_spack_opts[*]:+\"\${common_spack_opts[@]}\"} \ - buildcache create -a --deptype=all \ + buildcache create --deptype=all --only=package \ \${buildcache_key_opts[*]:+\"\${buildcache_key_opts[@]}\"} \ \$buildcache_rel_arg --rebuild-index \ \"$working_dir/copyBack/spack-emergency-cache\" \ - \$(spack find -L | sed -Ene 's&^([[:alnum:]]+).*\$&/\\1&p'); \ + \$spec; \ + fi \ + done;\ tag_text=ALERT _report $ERROR \"emergency buildcache dump COMPLETE\"; \ fi; \ exec $STDOUT>&- $STDERR>&-\ From 2258f025089556488ba1f28dc5f12d5edf2e5cc2 Mon Sep 17 00:00:00 2001 From: Patrick Gartung Date: Thu, 2 Nov 2023 12:09:32 -0500 Subject: [PATCH 2/5] Put quotes around path to binary_distribution --- bin/build-spack-env.sh | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/bin/build-spack-env.sh b/bin/build-spack-env.sh index f3ee63e..6760252 100755 --- a/bin/build-spack-env.sh +++ b/bin/build-spack-env.sh @@ -718,7 +718,7 @@ _maybe_cache_binaries() { ${extra_sources_write_cache[*]:+"${extra_sources_write_cache[@]}"}; do _report $PROGRESS "caching$msg_extra binary packages for environment $env_name to $cache" for hash in "${hashes_to_cache[@]}";do - if [ ! -f $(spack location -i $hash)/.spack/binary_distribution ]; then + if [ ! -f "$(spack location -i $hash)/.spack/binary_distribution" ]; then _cmd $DEBUG_1 $PROGRESS \ spack \ ${__debug_spack_buildcache:+-d} \ @@ -1340,7 +1340,7 @@ _copy_back_logs; \ if (( failed )) && (( want_emergency_buildcache )); then \ tag_text=ALERT _report $ERROR \"emergency buildcache dump...\"; \ for spec in \$(spack find -L | sed -Ene 's&^([[:alnum:]]+).*\$&/\\1&p');do \ - if [ ! -f \$(spack location -i \$spec)/.spack/binary_distribution ]; then + if [ ! -f \"\$(spack location -i \$spec)/.spack/binary_distribution\" ]; then _cmd $ERROR $PIPE spack \ \${common_spack_opts[*]:+\"\${common_spack_opts[@]}\"} \ buildcache create --deptype=all --only=package \ From a745fa8ddcc5289c6dd6bdd267fe87913f08067c Mon Sep 17 00:00:00 2001 From: Patrick Gartung Date: Thu, 2 Nov 2023 12:39:00 -0500 Subject: [PATCH 3/5] Drop duplicate --only=package --- bin/build-spack-env.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/bin/build-spack-env.sh b/bin/build-spack-env.sh index 6760252..aca2513 100755 --- a/bin/build-spack-env.sh +++ b/bin/build-spack-env.sh @@ -1343,7 +1343,7 @@ if (( failed )) && (( want_emergency_buildcache )); then \ if [ ! -f \"\$(spack location -i \$spec)/.spack/binary_distribution\" ]; then _cmd $ERROR $PIPE spack \ \${common_spack_opts[*]:+\"\${common_spack_opts[@]}\"} \ - buildcache create --deptype=all --only=package \ + buildcache create --deptype=all \ \${buildcache_key_opts[*]:+\"\${buildcache_key_opts[@]}\"} \ \$buildcache_rel_arg --rebuild-index \ \"$working_dir/copyBack/spack-emergency-cache\" \ From 9e566862f6a353a3ed2be79184ea45dd4d272a6f Mon Sep 17 00:00:00 2001 From: Patrick Gartung Date: Thu, 2 Nov 2023 13:28:30 -0500 Subject: [PATCH 4/5] Reverse the logic and output message when skipping --- bin/build-spack-env.sh | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/bin/build-spack-env.sh b/bin/build-spack-env.sh index aca2513..40f1483 100755 --- a/bin/build-spack-env.sh +++ b/bin/build-spack-env.sh @@ -718,7 +718,9 @@ _maybe_cache_binaries() { ${extra_sources_write_cache[*]:+"${extra_sources_write_cache[@]}"}; do _report $PROGRESS "caching$msg_extra binary packages for environment $env_name to $cache" for hash in "${hashes_to_cache[@]}";do - if [ ! -f "$(spack location -i $hash)/.spack/binary_distribution" ]; then + if [ -f "$(spack location -i $hash)/.spack/binary_distribution" ]; then + _report $DEBUG_1 "Skipping package installed from buildcache $hash" + else _cmd $DEBUG_1 $PROGRESS \ spack \ ${__debug_spack_buildcache:+-d} \ @@ -1340,7 +1342,9 @@ _copy_back_logs; \ if (( failed )) && (( want_emergency_buildcache )); then \ tag_text=ALERT _report $ERROR \"emergency buildcache dump...\"; \ for spec in \$(spack find -L | sed -Ene 's&^([[:alnum:]]+).*\$&/\\1&p');do \ - if [ ! -f \"\$(spack location -i \$spec)/.spack/binary_distribution\" ]; then + if [ -f \"\$(spack location -i \$spec)/.spack/binary_distribution\" ]; then + _report $ERROR skipping package installed from buildcache \$spec;\ + else \ _cmd $ERROR $PIPE spack \ \${common_spack_opts[*]:+\"\${common_spack_opts[@]}\"} \ buildcache create --deptype=all \ From 14e8d65c854e5f17091bdb312925dbe7e5c95903 Mon Sep 17 00:00:00 2001 From: Patrick Gartung Date: Thu, 2 Nov 2023 14:40:20 -0500 Subject: [PATCH 5/5] add var to environments relative path --- bin/build-spack-env.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/bin/build-spack-env.sh b/bin/build-spack-env.sh index 40f1483..693590f 100755 --- a/bin/build-spack-env.sh +++ b/bin/build-spack-env.sh @@ -561,7 +561,7 @@ _copy_back_logs() { mkdir -p "$tar_tmp/"{spack_env,spack-stage} cd "$spack_env_top_dir" _cmd $DEBUG_3 spack clean -dmp - _cmd $DEBUG_3 $PIPE tar -c $spack_source_dir/*.log $spack_source_dir/*-out.txt $spack_source_dir/*.yaml $spack_source_dir/etc $spack_source_dir/spack/environments \ + _cmd $DEBUG_3 $PIPE tar -c $spack_source_dir/*.log $spack_source_dir/*-out.txt $spack_source_dir/*.yaml $spack_source_dir/etc $spack_source_dir/var/spack/environments \ | _cmd $DEBUG_3 tar -C "$tar_tmp/spack_env" -x _cmd $DEBUG_3 $PIPE tar -C "$(spack location -S)" -c . \ | _cmd $DEBUG_3 tar -C "$tar_tmp/spack-stage" -x