forked from dashpay/dash
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge bitcoin#21304: guix: Add guix-clean script + establish gc-root …
…for container profiles 867a5e1 guix: Register garbage collector root for containers (Carl Dong) 8f8b96f guix: Update hint messages to mention guix-clean (Carl Dong) 44f6d4f guix: Record precious directories and add guix-clean (Carl Dong) 84912d4 build: Remove spaces from variable-printing rules (Carl Dong) Pull request description: ``` guix: Record precious directories and add guix-clean Many users have reported problems that stem from having an unclean working tree. To that end, I've written a guix-clean script which should help reset the working tree while respecting user-specified precious directories. Precious directories, such as: - SOURCES_PATH - BASE_CACHE - SDK_PATH - OUTDIR Should be preserved when cleaning the working tree, and are thus recorded in ./contrib/guix/var/precious_dirs. The ./contrib/guix/guix-clean script is able to parse that file and make sure to avoid them when cleaning out the working tree. ``` ACKs for top commit: laanwj: ACK 867a5e1 Tree-SHA512: c498fad781ff5e6406639df2b91b687fc528273fdf266bcdba8f6eec3b3b37ecce544b6da0252f0b9c6717f9d88e844e4c7b72d1877bdbabfc6871ddd0172af5
- Loading branch information
Showing
6 changed files
with
175 additions
and
20 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,83 @@ | ||
#!/usr/bin/env bash | ||
export LC_ALL=C | ||
set -e -o pipefail | ||
|
||
# Source the common prelude, which: | ||
# 1. Checks if we're at the top directory of the Bitcoin Core repository | ||
# 2. Defines a few common functions and variables | ||
# | ||
# shellcheck source=libexec/prelude.bash | ||
source "$(dirname "${BASH_SOURCE[0]}")/libexec/prelude.bash" | ||
|
||
|
||
################### | ||
## Sanity Checks ## | ||
################### | ||
|
||
################ | ||
# Required non-builtin commands should be invokable | ||
################ | ||
|
||
check_tools cat mkdir make git guix | ||
|
||
|
||
############# | ||
## Clean ## | ||
############# | ||
|
||
# Usage: under_dir MAYBE_PARENT MAYBE_CHILD | ||
# | ||
# If MAYBE_CHILD is a subdirectory of MAYBE_PARENT, print the relative path | ||
# from MAYBE_PARENT to MAYBE_CHILD. Otherwise, return 1 as the error code. | ||
# | ||
# NOTE: This does not perform any symlink-resolving or path canonicalization. | ||
# | ||
under_dir() { | ||
local path_residue | ||
path_residue="${2##${1}}" | ||
if [ -z "$path_residue" ] || [ "$path_residue" = "$2" ]; then | ||
return 1 | ||
else | ||
echo "$path_residue" | ||
fi | ||
} | ||
|
||
# Usage: dir_under_git_root MAYBE_CHILD | ||
# | ||
# If MAYBE_CHILD is under the current git repository and exists, print the | ||
# relative path from the git repository's top-level directory to MAYBE_CHILD, | ||
# otherwise, exit with an error code. | ||
# | ||
dir_under_git_root() { | ||
local rv | ||
rv="$(under_dir "$(git_root)" "$1")" | ||
[ -n "$rv" ] && echo "$rv" | ||
} | ||
|
||
shopt -s nullglob | ||
found_precious_dirs_files=( "${version_base_prefix}"*/"${var_base_basename}/precious_dirs" ) # This expands to an array of directories... | ||
shopt -u nullglob | ||
|
||
exclude_flags=() | ||
|
||
for precious_dirs_file in "${found_precious_dirs_files[@]}"; do | ||
# Make sure the precious directories (e.g. SOURCES_PATH, BASE_CACHE, SDK_PATH) | ||
# are excluded from git-clean | ||
echo "Found precious_dirs file: '${precious_dirs_file}'" | ||
|
||
# Exclude the precious_dirs file itself | ||
if dirs_file_exclude_fragment=$(dir_under_git_root "$(dirname "$precious_dirs_file")"); then | ||
exclude_flags+=( --exclude="${dirs_file_exclude_fragment}/precious_dirs" ) | ||
fi | ||
|
||
# Read each 'name=dir' pair from the precious_dirs file | ||
while IFS='=' read -r name dir; do | ||
# Add an exclusion flag if the precious directory is under the git root. | ||
if under=$(dir_under_git_root "$dir"); then | ||
echo "Avoiding ${name}: ${under}" | ||
exclude_flags+=( --exclude="$under" ) | ||
fi | ||
done < "$precious_dirs_file" | ||
done | ||
|
||
git clean -xdff "${exclude_flags[@]}" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters