put cachedir in environmental variable

XBMK_CACHE is now used, instead of hardcoding cache/

this is exported initialised to cache/, if unset.
this means you can set your own directory, and it means
./update release will use the same directory.

this means bandwidth wastage is further avoided.

Signed-off-by: Leah Rowe <leah@libreboot.org>
audit2
Leah Rowe 2024-07-19 00:31:57 +01:00 committed by Leah Rowe
parent 6b2653f8cd
commit 16f9ad55ca
4 changed files with 26 additions and 15 deletions

2
build
View File

@ -95,7 +95,7 @@ build_release()
cd "$srcdir" || $err "$vdir: !cd \"$srcdir\"" cd "$srcdir" || $err "$vdir: !cd \"$srcdir\""
./update trees -f ./update trees -f
rmgit . rmgit .
x_ rm -Rf cache tmp x_ rm -Rf tmp
x_ mv src/docs docs x_ mv src/docs docs
) || $err "can't create release files" ) || $err "can't create release files"

View File

@ -37,7 +37,7 @@ fetch_project()
clone_project() clone_project()
{ {
loc="cache/repo/$project" && singletree "$project" && \ loc="$XBMK_CACHE/repo/$project" && singletree "$project" && \
loc="src/$project" loc="src/$project"
printf "Downloading project '%s' to '%s'\n" "$project" "$loc" printf "Downloading project '%s' to '%s'\n" "$project" "$loc"
@ -62,8 +62,9 @@ git_prep()
[ "$project" = "coreboot" ] && [ -n "$xtree" ] && [ $# -gt 2 ] && \ [ "$project" = "coreboot" ] && [ -n "$xtree" ] && [ $# -gt 2 ] && \
[ "$xtree" != "$tree" ] && link_crossgcc "$_loc" [ "$xtree" != "$tree" ] && link_crossgcc "$_loc"
[ "$XBMK_RELEASE" = "y" ] && [ "$_loc" != "cache/repo/$project" ] \ [ "$XBMK_RELEASE" = "y" ] && \
&& rmgit "$tmpgit" [ "$_loc" != "$XBMK_CACHE/repo/$project" ] && \
rmgit "$tmpgit"
move_repo "$_loc" move_repo "$_loc"
} }
@ -106,8 +107,8 @@ tmpclone()
repofail="n" repofail="n"
[ $# -lt 6 ] || rm -Rf "$3" || $err "git retry: !rm $3 ($1)" [ $# -lt 6 ] || rm -Rf "$3" || $err "git retry: !rm $3 ($1)"
repodir="cache/repo/${1##*/}" && [ $# -gt 5 ] && repodir="$3" repodir="$XBMK_CACHE/repo/${1##*/}" && [ $# -gt 5 ] && repodir="$3"
x_ mkdir -p "cache/repo" mkdir -p "$XBMK_CACHE/repo" || $err "!rmdir $XBMK_CACHE/repo"
if [ -d "$repodir" ] && [ $# -lt 6 ]; then if [ -d "$repodir" ] && [ $# -lt 6 ]; then
git -C "$repodir" pull || sleep 3 || git -C "$repodir" pull \ git -C "$repodir" pull || sleep 3 || git -C "$repodir" pull \
|| sleep 3 || git -C "$repodir" pull || : || sleep 3 || git -C "$repodir" pull || :

View File

@ -88,6 +88,14 @@ if [ -z "${TMPDIR+x}" ]; then
xbmk_parent="y" xbmk_parent="y"
fi fi
# XBMK_CACHE is a directory, for caching downloads and git repositories
[ -z "${XBMK_CACHE+x}" ] && export XBMK_CACHE="$PWD/cache"
[ -z "$XBMK_CACHE" ] && export XBMK_CACHE="$PWD/cache"
[ -L "$XBMK_CACHE" ] && [ "$XBMK_CACHE" = "$PWD/cache" ] && \
$err "cachedir is default, $PWD/cache, but it exists and is a symlink"
[ -L "$XBMK_CACHE" ] && export XBMK_CACHE="$PWD/cache"
[ -f "$XBMK_CACHE" ] && $err "cachedir '$XBMK_CACHE' exists but it's a file"
# if "y": a coreboot target won't be built if target.cfg says release="n" # if "y": a coreboot target won't be built if target.cfg says release="n"
# (this is used to exclude certain build targets from releases) # (this is used to exclude certain build targets from releases)
[ -z "${XBMK_RELEASE+x}" ] && export XBMK_RELEASE="n" [ -z "${XBMK_RELEASE+x}" ] && export XBMK_RELEASE="n"
@ -180,14 +188,16 @@ singletree()
download() download()
{ {
cached="cache/file/$4" cached="$XBMK_CACHE/file/$4"
dl_fail="n" # 1 url, 2 url backup, 3 destination, 4 checksum dl_fail="n" # 1 url, 2 url backup, 3 destination, 4 checksum
vendor_checksum "$4" "$cached" 2>/dev/null && dl_fail="y" vendor_checksum "$4" "$cached" 2>/dev/null && dl_fail="y"
[ "$dl_fail" = "n" ] && e "$3" f && return 0 [ "$dl_fail" = "n" ] && e "$3" f && return 0
x_ mkdir -p "${3%/*}" cache/file && for url in "$1" "$2"; do mkdir -p "${3%/*}" "$XBMK_CACHE/file" || \
$err "!mkdir '$3' '$XBMK_CACHE/file'"
for url in "$1" "$2"; do
[ "$dl_fail" = "n" ] && break [ "$dl_fail" = "n" ] && break
[ -z "$url" ] && continue [ -z "$url" ] && continue
x_ rm -f "$cached" rm -f "$cached" || $err "!rm -f '$cached'"
curl --location --retry 3 -A "$_ua" "$url" -o "$cached" || \ curl --location --retry 3 -A "$_ua" "$url" -o "$cached" || \
wget --tries 3 -U "$_ua" "$url" -O "$cached" || continue wget --tries 3 -U "$_ua" "$url" -O "$cached" || continue
vendor_checksum "$4" "$cached" || dl_fail="n" vendor_checksum "$4" "$cached" || dl_fail="n"

View File

@ -165,11 +165,11 @@ build_dependencies()
check_project_hashes() check_project_hashes()
{ {
x_ mkdir -p cache/hash mkdir -p "$XBMK_CACHE/hash" || $err "!mkdir '$XBMK_CACHE/hash'"
old_pjhash="" old_pjhash=""
[ ! -f "cache/hash/$project$tree" ] || \ [ ! -f "$XBMK_CACHE/hash/$project$tree" ] || \
read -r old_pjhash < "cache/hash/$project$tree" read -r old_pjhash < "$XBMK_CACHE/hash/$project$tree"
x_ rm -f "$TMPDIR/project.list" "$TMPDIR/project.hash" \ x_ rm -f "$TMPDIR/project.list" "$TMPDIR/project.hash" \
"$TMPDIR/project.tmp"; x_ touch "$TMPDIR/project.tmp" "$TMPDIR/project.tmp"; x_ touch "$TMPDIR/project.tmp"
@ -192,10 +192,10 @@ check_project_hashes()
pjhash="$(sha512sum "$TMPDIR/project.hash" | awk '{print $1}')" || : pjhash="$(sha512sum "$TMPDIR/project.hash" | awk '{print $1}')" || :
badhash="y" && [ "$pjhash" = "$old_pjhash" ] && badhash="n" badhash="y" && [ "$pjhash" = "$old_pjhash" ] && badhash="n"
[ -f "cache/hash/$project$tree" ] || badhash="y" [ -f "$XBMK_CACHE/hash/$project$tree" ] || badhash="y"
printf "%s\n" "$pjhash" > "cache/hash/$project$tree" || \ printf "%s\n" "$pjhash" > "$XBMK_CACHE/hash/$project$tree" || \
$err "!mk cache/hash/$project$tree" $err "!mk $XBMK_CACHE/hash/$project$tree"
[ "$badhash" = "n" ] || rm -Rf "src/$project/$tree" \ [ "$badhash" = "n" ] || rm -Rf "src/$project/$tree" \
"elf/$project/$tree" "elf/$project/$target" || \ "elf/$project/$tree" "elf/$project/$target" || \