package cache: initialise with a function

This commit is contained in:
MilhouseVH 2017-12-21 13:41:30 +00:00
parent bf71ef864b
commit 64156ea8c8
3 changed files with 94 additions and 87 deletions

View File

@ -515,6 +515,28 @@ enable_service () {
done
}
init_package_cache() {
local _ANCHOR="@?+?@" DIR
# If the package caches are unset, then populate them
if [ -z "${_CACHE_PACKAGE_LOCAL+x}" -o -z "${_CACHE_PACKAGE_GLOBAL+x}" ]; then
_CACHE_PACKAGE_LOCAL=""
_CACHE_PACKAGE_GLOBAL=""
# cache project folder for a package
for DIR in $(find $ROOT/projects/$PROJECT/packages -type d 2>/dev/null); do
[ -r "$DIR/package.mk" ] && _CACHE_PACKAGE_LOCAL+="${DIR}${_ANCHOR}\n"
done
# cache packages folder
for DIR in $(find $ROOT/$PACKAGES -type d 2>/dev/null); do
[ -r "$DIR/package.mk" ] && _CACHE_PACKAGE_GLOBAL+="${DIR}${_ANCHOR}\n"
done
export _CACHE_PACKAGE_LOCAL _CACHE_PACKAGE_GLOBAL
fi
}
check_path() {
dashes="==========================="
if [ "${PWD##/usr}" != "${PWD}" ]; then

View File

@ -53,36 +53,32 @@ SED="sed -i"
unset LD_LIBRARY_PATH
# If the package caches are unset, then populate them
init_package_cache
# set package metadata
reset_pkg_vars "$1"
reset_pkg_vars "$1"
if [ -n "$1" ]; then
_PKG_ROOT_NAME=${1%:*}
_ALL_DIRS=""
_FOUND=0
_ANCHOR="@?+?@"
PKG_DIR=""
if [ -n "$1" ]; then
_PKG_ROOT_NAME=${1%:*}
_ALL_DIRS=""
_FOUND=0
_ANCHOR="@?+?@"
PKG_DIR=""
# If the package caches are unset, then populate them
if [ -z "${_CACHE_PACKAGE_LOCAL+x}" -o -z "${_CACHE_PACKAGE_GLOBAL+x}" ]; then
_CACHE_PACKAGE_LOCAL=""
_CACHE_PACKAGE_GLOBAL=""
# Check for any available local package in preference to a global package
for DIR in $(echo -e "${_CACHE_PACKAGE_LOCAL}" | grep -F "/${_PKG_ROOT_NAME}${_ANCHOR}"); do
DIR="${DIR%${_ANCHOR}}"
# found first, set $PKG_DIR
PKG_DIR="$DIR"
# keep track of dirs with package.mk for detecting multiple folders
_ALL_DIRS+="${DIR}\n"
_FOUND=$((_FOUND+1))
done
# cache project folder for a package
for DIR in $(find $ROOT/projects/$PROJECT/packages -type d 2>/dev/null); do
[ -r "$DIR/package.mk" ] && _CACHE_PACKAGE_LOCAL+="${DIR}${_ANCHOR}\n"
done
# cache packages folder
for DIR in $(find $ROOT/$PACKAGES -type d 2>/dev/null); do
[ -r "$DIR/package.mk" ] && _CACHE_PACKAGE_GLOBAL+="${DIR}${_ANCHOR}\n"
done
export _CACHE_PACKAGE_LOCAL _CACHE_PACKAGE_GLOBAL
fi
# Check for any available local package in preference to a global package
for DIR in $(echo -e "${_CACHE_PACKAGE_LOCAL}" | grep -F "/${_PKG_ROOT_NAME}${_ANCHOR}"); do
# If there's no local package available, use the global package
if [ $_FOUND -eq 0 ]; then
for DIR in $(echo -e "${_CACHE_PACKAGE_GLOBAL}" | grep -F "/${_PKG_ROOT_NAME}${_ANCHOR}"); do
DIR="${DIR%${_ANCHOR}}"
# found first, set $PKG_DIR
PKG_DIR="$DIR"
@ -90,72 +86,61 @@ unset LD_LIBRARY_PATH
_ALL_DIRS+="${DIR}\n"
_FOUND=$((_FOUND+1))
done
# If there's no local package available, use the global package
if [ $_FOUND -eq 0 ]; then
for DIR in $(echo -e "${_CACHE_PACKAGE_GLOBAL}" | grep -F "/${_PKG_ROOT_NAME}${_ANCHOR}"); do
DIR="${DIR%${_ANCHOR}}"
# found first, set $PKG_DIR
PKG_DIR="$DIR"
# keep track of dirs with package.mk for detecting multiple folders
_ALL_DIRS+="${DIR}\n"
_FOUND=$((_FOUND+1))
done
fi
# _FOUND multiple packages? fail
if [ $_FOUND -gt 1 ]; then
echo "Error - multiple package folders:"
echo -e "$_ALL_DIRS"
exit 1
fi
fi
if [ -n "$PKG_DIR" -a -r $PKG_DIR/package.mk ]; then
unset -f configure_package
. $PKG_DIR/package.mk
[ -z "$PKG_SHORTDESC" ] && PKG_SHORTDESC="$PKG_NAME (autogenerated)"
[ -z "$PKG_LONGDESC" ] && PKG_LONGDESC="$PKG_NAME (autogenerated)"
# _FOUND multiple packages? fail
if [ $_FOUND -gt 1 ]; then
echo "Error - multiple package folders:"
echo -e "$_ALL_DIRS"
exit 1
fi
fi
if [ "$PKG_IS_ADDON" = "yes" ] ; then
[ -z $PKG_SECTION ] && PKG_ADDON_ID="$PKG_NAME" || PKG_ADDON_ID="${PKG_SECTION//\//.}.$PKG_NAME"
[ "$PKG_ADDON_IS_STANDALONE" != "yes" ] && PKG_NEED_UNPACK="${PKG_NEED_UNPACK} $(get_pkg_directory $MEDIACENTER)"
if [ -n "$PKG_DIR" -a -r $PKG_DIR/package.mk ]; then
unset -f configure_package
. $PKG_DIR/package.mk
[ -z "$PKG_SHORTDESC" ] && PKG_SHORTDESC="$PKG_NAME (autogenerated)"
[ -z "$PKG_LONGDESC" ] && PKG_LONGDESC="$PKG_NAME (autogenerated)"
fi
if [ "$PKG_IS_ADDON" = "yes" ] ; then
[ -z $PKG_SECTION ] && PKG_ADDON_ID="$PKG_NAME" || PKG_ADDON_ID="${PKG_SECTION//\//.}.$PKG_NAME"
[ "$PKG_ADDON_IS_STANDALONE" != "yes" ] && PKG_NEED_UNPACK="${PKG_NEED_UNPACK} $(get_pkg_directory $MEDIACENTER)"
fi
# Automatically set PKG_SOURCE_NAME unless it is already defined.
# PKG_SOURCE_NAME will be automatically set to a name based on
# the $PKG_NAME-$PKG_VERSION convention.
#
# Any $PKG_URL that references more than a single url will abort
# the build as these are no longer supported - use mkpkg instead.
if [ -n "$PKG_URL" -a -z "$PKG_SOURCE_NAME" ]; then
if [[ $PKG_URL =~ .*\ .* ]]; then
echo "Error - packages with multiple urls are no longer supported, use mkpkg:"
echo "$PKG_URL"
exit 1
fi
PKG_SOURCE_NAME="${PKG_URL##*/}"
case $PKG_SOURCE_NAME in
${PKG_NAME}-${PKG_VERSION}.*)
PKG_SOURCE_NAME=$PKG_SOURCE_NAME
;;
*.tar | *.tbz | *.tgz | *.txz | *.7z | *.zip)
PKG_SOURCE_NAME=${PKG_NAME}-${PKG_VERSION}.${PKG_SOURCE_NAME##*\.}
;;
*.tar.bz2 | *.tar.gz | *.tar.xz)
PKG_SOURCE_NAME=${PKG_NAME}-${PKG_VERSION}.tar.${PKG_SOURCE_NAME##*\.}
;;
*.diff | *.patch | *.diff.bz2 | *.patch.bz2 | patch-*.bz2 | *.diff.gz | *.patch.gz | patch-*.gz)
PKG_SOURCE_NAME=$PKG_SOURCE_NAME
;;
*)
PKG_SOURCE_NAME=${PKG_NAME}-${PKG_VERSION}.${PKG_SOURCE_NAME##*\.}
;;
esac
fi
# Automatically set PKG_SOURCE_NAME unless it is already defined.
# PKG_SOURCE_NAME will be automatically set to a name based on
# the $PKG_NAME-$PKG_VERSION convention.
#
# Any $PKG_URL that references more than a single url will abort
# the build as these are no longer supported - use mkpkg instead.
if [ -n "$PKG_URL" -a -z "$PKG_SOURCE_NAME" ]; then
if [[ $PKG_URL =~ .*\ .* ]]; then
echo "Error - packages with multiple urls are no longer supported, use mkpkg:"
echo "$PKG_URL"
exit 1
fi
PKG_SOURCE_NAME="${PKG_URL##*/}"
case $PKG_SOURCE_NAME in
${PKG_NAME}-${PKG_VERSION}.*)
PKG_SOURCE_NAME=$PKG_SOURCE_NAME
;;
*.tar | *.tbz | *.tgz | *.txz | *.7z | *.zip)
PKG_SOURCE_NAME=${PKG_NAME}-${PKG_VERSION}.${PKG_SOURCE_NAME##*\.}
;;
*.tar.bz2 | *.tar.gz | *.tar.xz)
PKG_SOURCE_NAME=${PKG_NAME}-${PKG_VERSION}.tar.${PKG_SOURCE_NAME##*\.}
;;
*.diff | *.patch | *.diff.bz2 | *.patch.bz2 | patch-*.bz2 | *.diff.gz | *.patch.gz | patch-*.gz)
PKG_SOURCE_NAME=$PKG_SOURCE_NAME
;;
*)
PKG_SOURCE_NAME=${PKG_NAME}-${PKG_VERSION}.${PKG_SOURCE_NAME##*\.}
;;
esac
fi
PKG_BUILD="$BUILD/${PKG_NAME}-${PKG_VERSION}"
PKG_BUILD="$BUILD/${PKG_NAME}-${PKG_VERSION}"
XORG_PATH_DRI=/usr/lib/dri
XORG_PATH_XKB=/usr/share/X11/xkb

View File

@ -20,7 +20,7 @@
unset _CACHE_PACKAGE_LOCAL _CACHE_PACKAGE_GLOBAL
. config/options TRIGGER_POPULATION_OF_CACHE_PACKAGE
. config/options ""
. config/show_config
show_config