| 1 | #!/usr/bin/envscip-shell filesystem . . `/usr/bin/env`. bash |
| 2 | export LC_ALL=C |
| 3 | set -e -o pipefail |
| 4 | |
| 5 | # Source the common prelude, which: |
| 6 | # 1. Checks if we're at the top directory of the Feather Wallet repository |
| 7 | # 2. Defines a few common functions and variables |
| 8 | # |
| 9 | # shellcheck source=libexec/prelude.bash |
| 10 | source "$(dirnamescip-shell system . . dirname. "${BASH_SOURCE[0]}")/libexec/prelude.bash" |
| 11 | |
| 12 | |
| 13 | ################### |
| 14 | ## Sanity Checks ## |
| 15 | ################### |
| 16 | |
| 17 | ################ |
| 18 | # Required non-builtin commands should be invokable |
| 19 | ################ |
| 20 | |
| 21 | check_tools cat mkdir make git guix |
| 22 | |
| 23 | |
| 24 | ############# |
| 25 | ## Clean ## |
| 26 | ############# |
| 27 | |
| 28 | # Usage: under_dir MAYBE_PARENT MAYBE_CHILD |
| 29 | # |
| 30 | # If MAYBE_CHILD is a subdirectory of MAYBE_PARENT, print the relative path |
| 31 | # from MAYBE_PARENT to MAYBE_CHILD. Otherwise, return 1 as the error code. |
| 32 | # |
| 33 | # NOTE: This does not perform any symlink-resolving or path canonicalization. |
| 34 | # |
| 35 | under_dirscip-shell shell feather-wallet 2.8.1+dfsg-6 under_dir().() { |
| 36 | local path_residue |
| 37 | path_residue="${2##"${1}"}" |
| 38 | if [scip-shell system . . `[`. -z "$path_residue" ] || [scip-shell system . . `[`. "$path_residue" = "$2" ]; then |
| 39 | return 1 |
| 40 | else |
| 41 | echoscip-shell system . . echo. "$path_residue" |
| 42 | fi |
| 43 | } |
| 44 | |
| 45 | # Usage: dir_under_git_root MAYBE_CHILD |
| 46 | # |
| 47 | # If MAYBE_CHILD is under the current git repository and exists, print the |
| 48 | # relative path from the git repository's top-level directory to MAYBE_CHILD, |
| 49 | # otherwise, exit with an error code. |
| 50 | # |
| 51 | dir_under_git_rootscip-shell shell feather-wallet 2.8.1+dfsg-6 dir_under_git_root().() { |
| 52 | local rv |
| 53 | rv="$(under_dirscip-shell shell feather-wallet 2.8.1+dfsg-6 under_dir(). "$(git_root)" "$1")" |
| 54 | [scip-shell system . . `[`. -n "$rv" ] && echoscip-shell system . . echo. "$rv" |
| 55 | } |
| 56 | |
| 57 | shopt -s nullglob |
| 58 | found_precious_dirs_files=( "${version_base_prefix}"*/"${var_base_basename}/precious_dirs" ) # This expands to an array of directories... |
| 59 | shopt -u nullglob |
| 60 | |
| 61 | exclude_flags=() |
| 62 | |
| 63 | for precious_dirs_file in "${found_precious_dirs_files[@]}"; do |
| 64 | # Make sure the precious directories (e.g. SOURCES_PATH, BASE_CACHE, SDK_PATH) |
| 65 | # are excluded from git-clean |
| 66 | echoscip-shell system . . echo. "Found precious_dirs file: '${precious_dirs_file}'" |
| 67 | |
| 68 | # Exclude the precious_dirs file itself |
| 69 | if dirs_file_exclude_fragment=$(dir_under_git_rootscip-shell shell feather-wallet 2.8.1+dfsg-6 dir_under_git_root(). "$(dirnamescip-shell system . . dirname. "$precious_dirs_file")"); then |
| 70 | exclude_flags+=( --exclude="${dirs_file_exclude_fragment}/precious_dirs" ) |
| 71 | fi |
| 72 | |
| 73 | # Read each 'name=dir' pair from the precious_dirs file |
| 74 | while IFS='=' read -r name dir; do |
| 75 | # Add an exclusion flag if the precious directory is under the git root. |
| 76 | if under=$(dir_under_git_rootscip-shell shell feather-wallet 2.8.1+dfsg-6 dir_under_git_root(). "$dir"); then |
| 77 | echoscip-shell system . . echo. "Avoiding ${name}: ${under}" |
| 78 | exclude_flags+=( --exclude="$under" ) |
| 79 | fi |
| 80 | done < "$precious_dirs_file" |
| 81 | done |
| 82 | |
| 83 | gitscip-shell system . . git. clean -xdff "${exclude_flags[@]}" |