Merge pull request #3136 from MilhouseVH/le90_pkg_function

buildsystem: proxy calls to package functions
This commit is contained in:
Matthias Reichl 2018-11-29 16:47:09 +01:00 committed by GitHub
commit 54b9972093
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
6 changed files with 45 additions and 61 deletions

View File

@ -10,6 +10,24 @@ die() {
exit "${2:-1}" exit "${2:-1}"
} }
# p1: name of potential function to execute if it exists
# return 0 if function executed, 1 if not, die if error
pkg_call() {
[ -n "${PKG_NAME}" ] || die "$(print_color CLR_ERROR "FAILURE: Cannot call ${1} package function when package is not known!")"
if [ "$(type -t ${1})" = "function" ]; then
${1} || die "$(print_color CLR_ERROR "FAILURE: ${1} for package ${PKG_NAME} did not succeed!")"
else
return 1
fi
}
# p1: name of potential function to execute if it exists
# return 0 if function executed or not, or die if error
pkg_call_optional() {
pkg_call ${1} || return 0
}
# return 0 if $2 in space-separated list $1, otherwise return 1 # return 0 if $2 in space-separated list $1, otherwise return 1
listcontains() { listcontains() {
if [ -n "$1" -a -n "$2" ]; then if [ -n "$1" -a -n "$2" ]; then
@ -20,7 +38,7 @@ listcontains() {
} }
# remove item(s) from list. # remove item(s) from list.
# looping makes it greedy (eg. removefromlist "abc def ghi" "(abc|def)" will work). # looping makes it greedy (eg. listremoveitem "abc def ghi" "(abc|def)" removes both "abc" and "def").
listremoveitem() { listremoveitem() {
local data="${1}" odata tmp_array local data="${1}" odata tmp_array
if [ -n "$1" -a -n "$2" ]; then if [ -n "$1" -a -n "$2" ]; then

View File

@ -164,9 +164,7 @@ BUILD_INDENT_SIZE=4
# If sourcing a package, configure any package variables dependent on variables we have set # If sourcing a package, configure any package variables dependent on variables we have set
if [ -n "$PKG_DIR" -a -r $PKG_DIR/package.mk ]; then if [ -n "$PKG_DIR" -a -r $PKG_DIR/package.mk ]; then
if [ "$(type -t configure_package)" = "function" ]; then pkg_call_optional configure_package
configure_package
fi
fi fi
# multilib? nah # multilib? nah

View File

@ -192,9 +192,7 @@ BOOTSTRAP_MESON_OPTS="$HOST_MESON_OPTS"
. $PKG_DIR/package.mk . $PKG_DIR/package.mk
# finalise package configuration # finalise package configuration
if [ "$(type -t configure_package)" = "function" ]; then pkg_call_optional configure_package
configure_package
fi
# build dependencies, only when PKG_DEPENDS_? is filled # build dependencies, only when PKG_DEPENDS_? is filled
unset _pkg_depends unset _pkg_depends
@ -274,9 +272,7 @@ if [ "$PKG_TOOLCHAIN" = "autotools" ]; then
fi fi
# include build template and build # include build template and build
if [ "$(type -t pre_build_$TARGET)" = "function" ]; then pkg_call_optional pre_build_$TARGET
pre_build_$TARGET
fi
# ensure $PKG_BUILD is there. (installer? PKG_URL="") # ensure $PKG_BUILD is there. (installer? PKG_URL="")
if [ ! -d "$PKG_BUILD" ] ; then if [ ! -d "$PKG_BUILD" ] ; then
@ -299,12 +295,9 @@ if [ -f "$PKG_CONFIGURE_SCRIPT" -o -f "$PKG_CMAKE_SCRIPT" -o -f "$PKG_MESON_SCRI
fi fi
# configure # configure
if [ "$(type -t pre_configure_$TARGET)" = "function" ]; then pkg_call_optional pre_configure_$TARGET
pre_configure_$TARGET
fi if ! pkg_call configure_$TARGET; then
if [ "$(type -t configure_$TARGET)" = "function" ]; then
configure_$TARGET
else
case "$PKG_TOOLCHAIN:$TARGET" in case "$PKG_TOOLCHAIN:$TARGET" in
# meson builds # meson builds
"meson:target") "meson:target")
@ -383,17 +376,13 @@ else
;; ;;
esac esac
fi fi
if [ "$(type -t post_configure_$TARGET)" = "function" ]; then
post_configure_$TARGET pkg_call_optional post_configure_$TARGET
fi
# make # make
if [ "$(type -t pre_make_$TARGET)" = "function" ]; then pkg_call_optional pre_make_$TARGET
pre_make_$TARGET
fi if ! pkg_call make_$TARGET; then
if [ "$(type -t make_$TARGET)" = "function" ]; then
make_$TARGET
else
case "$PKG_TOOLCHAIN:$TARGET" in case "$PKG_TOOLCHAIN:$TARGET" in
# ninja based builds # ninja based builds
"meson:target"|"cmake:target"|"ninja:target") "meson:target"|"cmake:target"|"ninja:target")
@ -432,17 +421,13 @@ else
;; ;;
esac esac
fi fi
if [ "$(type -t post_make_$TARGET)" = "function" ]; then
post_make_$TARGET pkg_call_optional post_make_$TARGET
fi
# make install # make install
if [ "$(type -t pre_makeinstall_$TARGET)" = "function" ]; then pkg_call_optional pre_makeinstall_$TARGET
pre_makeinstall_$TARGET
fi if ! pkg_call makeinstall_$TARGET; then
if [ "$(type -t makeinstall_$TARGET)" = "function" ]; then
makeinstall_$TARGET
else
case "$PKG_TOOLCHAIN:$TARGET" in case "$PKG_TOOLCHAIN:$TARGET" in
# ninja based builds # ninja based builds
"meson:target"|"cmake:target") "meson:target"|"cmake:target")
@ -475,9 +460,8 @@ else
;; ;;
esac esac
fi fi
if [ "$(type -t post_makeinstall_$TARGET)" = "function" ]; then
post_makeinstall_$TARGET pkg_call_optional post_makeinstall_$TARGET
fi
if [ "$TARGET" = "target" -o "$TARGET" = "init" ]; then if [ "$TARGET" = "target" -o "$TARGET" = "init" ]; then
if [ -d $INSTALL ]; then if [ -d $INSTALL ]; then

View File

@ -208,9 +208,7 @@ build_addon() {
rm -rf $ADDON_BUILD rm -rf $ADDON_BUILD
# install addon parts # install addon parts
if [ "$(type -t addon)" = "function" ]; then if ! pkg_call addon; then
addon
else
install_binary_addon $PKG_ADDON_ID install_binary_addon $PKG_ADDON_ID
fi fi

View File

@ -130,9 +130,7 @@ unset -f post_install
# install # install
if [ "$TARGET" = target ] ; then if [ "$TARGET" = target ] ; then
if [ "$(type -t pre_install)" = "function" ]; then pkg_call_optional pre_install
pre_install
fi
fi fi
if [ "$TARGET" = "target" -a -d $PKG_BUILD/.install_pkg ]; then if [ "$TARGET" = "target" -a -d $PKG_BUILD/.install_pkg ]; then
@ -144,9 +142,7 @@ elif [ "$TARGET" = "init" -a -d $PKG_BUILD/.install_init ]; then
fi fi
if [ "$TARGET" = target ] ; then if [ "$TARGET" = target ] ; then
if [ "$(type -t post_install)" = "function" ]; then pkg_call_optional post_install
post_install
fi
fi fi
touch $STAMP touch $STAMP

View File

@ -53,13 +53,9 @@ if [ -d "$SOURCES/$1" -o -d "$PKG_DIR/sources" ]; then
. $PKG_DIR/package.mk . $PKG_DIR/package.mk
if [ "$(type -t pre_unpack)" = "function" ]; then pkg_call_optional pre_unpack
pre_unpack
fi
if [ "$(type -t unpack)" = "function" ]; then if ! pkg_call unpack; then
unpack
else
if [ -n "$PKG_URL" ]; then if [ -n "$PKG_URL" ]; then
$SCRIPTS/extract $1 $BUILD $SCRIPTS/extract $1 $BUILD
fi fi
@ -82,14 +78,10 @@ if [ -d "$SOURCES/$1" -o -d "$PKG_DIR/sources" ]; then
mkdir -p "${PKG_BUILD}" mkdir -p "${PKG_BUILD}"
fi fi
if [ "$(type -t post_unpack)" = "function" ]; then pkg_call_optional post_unpack
post_unpack
fi
if [ "${PKG_SKIP_PATCHES}" != "yes" ]; then if [ "${PKG_SKIP_PATCHES}" != "yes" ]; then
if [ "$(type -t pre_patch)" = "function" ]; then pkg_call_optional pre_patch
pre_patch
fi
if [ "$TARGET_ARCH" = "x86_64" ]; then if [ "$TARGET_ARCH" = "x86_64" ]; then
PATCH_ARCH="x86" PATCH_ARCH="x86"
@ -158,9 +150,7 @@ if [ -d "$SOURCES/$1" -o -d "$PKG_DIR/sources" ]; then
fi fi
done done
if [ "$(type -t post_patch)" = "function" ]; then pkg_call_optional post_patch
post_patch
fi
fi fi
if [ ! "$PKG_NAME" = "configtools" ] ; then if [ ! "$PKG_NAME" = "configtools" ] ; then