Merge pull request #781 from MilhouseVH/path_optimise

path: optimize package processing
This commit is contained in:
Lukas Rusak 2016-09-30 10:43:17 -07:00 committed by GitHub
commit 14c62f8f3d
2 changed files with 42 additions and 31 deletions

View File

@ -74,49 +74,58 @@ SED="sed -i"
PKG_IS_ADDON="no" PKG_IS_ADDON="no"
if [ -n "$1" ]; then if [ -n "$1" ]; then
_PKG_ROOT_NAME=$(echo $1 | cut -d: -f1) _PKG_ROOT_NAME=${1%:*}
_ALL_DIRS="" _ALL_DIRS=""
_FOUND=0 _FOUND=0
PKG_DIR="" PKG_DIR=""
# check project folder for a package if not found already # If the package caches are unset, then populate them
for DIR in $(find $ROOT/projects/$PROJECT/packages -type d -name $_PKG_ROOT_NAME 2>/dev/null); do if [ -z "${_CACHE_PACKAGE_LOCAL+x}" -o -z "${_CACHE_PACKAGE_GLOBAL+x}" ]; then
if [ -r "$DIR/package.mk" ]; 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}\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}\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 -E "^.*/${_PKG_ROOT_NAME}\$"); do
# 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
# 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 -E "^.*/${_PKG_ROOT_NAME}\$"); do
# found first, set $PKG_DIR # found first, set $PKG_DIR
PKG_DIR="$DIR" PKG_DIR="$DIR"
# keep track of dirs with package.mk for detecting multiple folders # keep track of dirs with package.mk for detecting multiple folders
_ALL_DIRS="${_ALL_DIRS}${DIR}\\n" _ALL_DIRS+="${DIR}\n"
_FOUND=$((_FOUND+1)) _FOUND=$((_FOUND+1))
if [ $_FOUND -gt 1 ]; then
# _FOUND more ? fail
echo "Error - multiple package folders:"
echo -e "$_ALL_DIRS"
exit 1
fi
fi
done
# then check packages folder if not found already
if [ $_FOUND -eq 0 ]; then
for DIR in $(find $ROOT/$PACKAGES -type d -name $_PKG_ROOT_NAME 2>/dev/null); do
if [ -r "$DIR/package.mk" ]; then
# found first, set $PKG_DIR
PKG_DIR="$DIR"
# keep track of dirs with package.mk for detecting multiple folders
_ALL_DIRS="${_ALL_DIRS}${DIR}\\n"
_FOUND=$((_FOUND+1))
if [ $_FOUND -gt 1 ]; then
# found more ? fail
echo "Error - multiple package folders:"
echo -e "$_ALL_DIRS"
exit 1
fi
fi
done done
fi fi
# _FOUND multiple packages? fail
if [ $_FOUND -gt 1 ]; then
echo "Error - multiple package folders:"
echo -e "$_ALL_DIRS"
exit 1
fi
fi fi
if [ -r $PKG_DIR/package.mk ]; then if [ -n "$PKG_DIR" -a -r $PKG_DIR/package.mk ]; then
. $PKG_DIR/package.mk . $PKG_DIR/package.mk
fi fi

View File

@ -18,6 +18,8 @@
# along with OpenELEC. If not, see <http://www.gnu.org/licenses/>. # along with OpenELEC. If not, see <http://www.gnu.org/licenses/>.
################################################################################ ################################################################################
unset _CACHE_PACKAGE_LOCAL _CACHE_PACKAGE_GLOBAL
. config/options $1 . config/options $1
show_config show_config