From 710c6070167e24df88b9f35d33b0db40e0d73199 Mon Sep 17 00:00:00 2001 From: MilhouseVH Date: Wed, 28 Nov 2018 14:52:30 +0000 Subject: [PATCH 1/7] config/functions: add pkg_call/pkg_call_optional helpers --- config/functions | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/config/functions b/config/functions index c36d1ac633..f25325e1bc 100644 --- a/config/functions +++ b/config/functions @@ -10,6 +10,24 @@ die() { 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 listcontains() { if [ -n "$1" -a -n "$2" ]; then From 8b9fd53759bfc1025a90a1db2dc2cc97553d65e5 Mon Sep 17 00:00:00 2001 From: MilhouseVH Date: Wed, 28 Nov 2018 15:40:03 +0000 Subject: [PATCH 2/7] config/path use pkg_call --- config/path | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/config/path b/config/path index 3f540890a7..f16f18e7e1 100644 --- a/config/path +++ b/config/path @@ -164,9 +164,7 @@ BUILD_INDENT_SIZE=4 # 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 [ "$(type -t configure_package)" = "function" ]; then - configure_package - fi + pkg_call_optional configure_package fi # multilib? nah From 9959b29df9d3259835056c07c43c7982738193db Mon Sep 17 00:00:00 2001 From: MilhouseVH Date: Wed, 28 Nov 2018 14:58:22 +0000 Subject: [PATCH 3/7] scripts/build: use pkg_call --- scripts/build | 50 +++++++++++++++++--------------------------------- 1 file changed, 17 insertions(+), 33 deletions(-) diff --git a/scripts/build b/scripts/build index 0c40a98cac..d0bde014ca 100755 --- a/scripts/build +++ b/scripts/build @@ -192,9 +192,7 @@ BOOTSTRAP_MESON_OPTS="$HOST_MESON_OPTS" . $PKG_DIR/package.mk # finalise package configuration -if [ "$(type -t configure_package)" = "function" ]; then - configure_package -fi +pkg_call_optional configure_package # build dependencies, only when PKG_DEPENDS_? is filled unset _pkg_depends @@ -274,9 +272,7 @@ if [ "$PKG_TOOLCHAIN" = "autotools" ]; then fi # include build template and build -if [ "$(type -t pre_build_$TARGET)" = "function" ]; then - pre_build_$TARGET -fi +pkg_call_optional pre_build_$TARGET # ensure $PKG_BUILD is there. (installer? PKG_URL="") 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 # configure -if [ "$(type -t pre_configure_$TARGET)" = "function" ]; then - pre_configure_$TARGET -fi -if [ "$(type -t configure_$TARGET)" = "function" ]; then - configure_$TARGET -else +pkg_call_optional pre_configure_$TARGET + +if ! pkg_call configure_$TARGET; then case "$PKG_TOOLCHAIN:$TARGET" in # meson builds "meson:target") @@ -383,17 +376,13 @@ else ;; esac fi -if [ "$(type -t post_configure_$TARGET)" = "function" ]; then - post_configure_$TARGET -fi + +pkg_call_optional post_configure_$TARGET # make -if [ "$(type -t pre_make_$TARGET)" = "function" ]; then - pre_make_$TARGET -fi -if [ "$(type -t make_$TARGET)" = "function" ]; then - make_$TARGET -else +pkg_call_optional pre_make_$TARGET + +if ! pkg_call make_$TARGET; then case "$PKG_TOOLCHAIN:$TARGET" in # ninja based builds "meson:target"|"cmake:target"|"ninja:target") @@ -432,17 +421,13 @@ else ;; esac fi -if [ "$(type -t post_make_$TARGET)" = "function" ]; then - post_make_$TARGET -fi + +pkg_call_optional post_make_$TARGET # make install -if [ "$(type -t pre_makeinstall_$TARGET)" = "function" ]; then - pre_makeinstall_$TARGET -fi -if [ "$(type -t makeinstall_$TARGET)" = "function" ]; then - makeinstall_$TARGET -else +pkg_call_optional pre_makeinstall_$TARGET + +if ! pkg_call makeinstall_$TARGET; then case "$PKG_TOOLCHAIN:$TARGET" in # ninja based builds "meson:target"|"cmake:target") @@ -475,9 +460,8 @@ else ;; esac fi -if [ "$(type -t post_makeinstall_$TARGET)" = "function" ]; then - post_makeinstall_$TARGET -fi + +pkg_call_optional post_makeinstall_$TARGET if [ "$TARGET" = "target" -o "$TARGET" = "init" ]; then if [ -d $INSTALL ]; then From d0d28ee0a7230e3ca1dc2df0ab2b453b21ba2b7c Mon Sep 17 00:00:00 2001 From: MilhouseVH Date: Wed, 28 Nov 2018 15:38:24 +0000 Subject: [PATCH 4/7] scripts/unpack: use pkg_call --- scripts/unpack | 20 +++++--------------- 1 file changed, 5 insertions(+), 15 deletions(-) diff --git a/scripts/unpack b/scripts/unpack index 83df55c0ef..ea95857afd 100755 --- a/scripts/unpack +++ b/scripts/unpack @@ -53,13 +53,9 @@ if [ -d "$SOURCES/$1" -o -d "$PKG_DIR/sources" ]; then . $PKG_DIR/package.mk - if [ "$(type -t pre_unpack)" = "function" ]; then - pre_unpack - fi + pkg_call_optional pre_unpack - if [ "$(type -t unpack)" = "function" ]; then - unpack - else + if ! pkg_call unpack; then if [ -n "$PKG_URL" ]; then $SCRIPTS/extract $1 $BUILD fi @@ -82,14 +78,10 @@ if [ -d "$SOURCES/$1" -o -d "$PKG_DIR/sources" ]; then mkdir -p "${PKG_BUILD}" fi - if [ "$(type -t post_unpack)" = "function" ]; then - post_unpack - fi + pkg_call_optional post_unpack if [ "${PKG_SKIP_PATCHES}" != "yes" ]; then - if [ "$(type -t pre_patch)" = "function" ]; then - pre_patch - fi + pkg_call_optional pre_patch if [ "$TARGET_ARCH" = "x86_64" ]; then PATCH_ARCH="x86" @@ -158,9 +150,7 @@ if [ -d "$SOURCES/$1" -o -d "$PKG_DIR/sources" ]; then fi done - if [ "$(type -t post_patch)" = "function" ]; then - post_patch - fi + pkg_call_optional post_patch fi if [ ! "$PKG_NAME" = "configtools" ] ; then From b5be90e394f1e5f1224e2236670d0e1a397fdd4d Mon Sep 17 00:00:00 2001 From: MilhouseVH Date: Wed, 28 Nov 2018 15:38:46 +0000 Subject: [PATCH 5/7] scripts/install: use pkg_call --- scripts/install | 8 ++------ 1 file changed, 2 insertions(+), 6 deletions(-) diff --git a/scripts/install b/scripts/install index fbc9b3fd01..b1797d7478 100755 --- a/scripts/install +++ b/scripts/install @@ -130,9 +130,7 @@ unset -f post_install # install if [ "$TARGET" = target ] ; then - if [ "$(type -t pre_install)" = "function" ]; then - pre_install - fi + pkg_call_optional pre_install fi 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 if [ "$TARGET" = target ] ; then - if [ "$(type -t post_install)" = "function" ]; then - post_install - fi + pkg_call_optional post_install fi touch $STAMP From aaa8c7e4931721b397146db892d7f14fe462ba40 Mon Sep 17 00:00:00 2001 From: MilhouseVH Date: Wed, 28 Nov 2018 15:36:51 +0000 Subject: [PATCH 6/7] scripts/create_addon: use pkg_call --- scripts/create_addon | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/scripts/create_addon b/scripts/create_addon index d625a5fe5e..1644793967 100755 --- a/scripts/create_addon +++ b/scripts/create_addon @@ -208,9 +208,7 @@ build_addon() { rm -rf $ADDON_BUILD # install addon parts - if [ "$(type -t addon)" = "function" ]; then - addon - else + if ! pkg_call addon; then install_binary_addon $PKG_ADDON_ID fi From 3b756a1f3ca6c5fc1f2b549ea4d3be84348a63ca Mon Sep 17 00:00:00 2001 From: MilhouseVH Date: Wed, 28 Nov 2018 15:45:00 +0000 Subject: [PATCH 7/7] config/functions: fix comment --- config/functions | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/config/functions b/config/functions index f25325e1bc..d93b501a95 100644 --- a/config/functions +++ b/config/functions @@ -38,7 +38,7 @@ listcontains() { } # 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() { local data="${1}" odata tmp_array if [ -n "$1" -a -n "$2" ]; then