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,6 +53,9 @@ 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"
@ -63,24 +66,6 @@ unset LD_LIBRARY_PATH
_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=""
# 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
DIR="${DIR%${_ANCHOR}}"

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