[pacman-dev] [PATCH 1/3] libmakepkg: Add check_buildoption for distcc and ccache
This reduces code duplication a bit. It also highlights how these options are checked. Signed-off-by: Jan Alexander Steffens (heftig) <jan.steffens@gmail.com> --- scripts/libmakepkg/util/option.sh | 22 ++++++++++++++++++++++ scripts/makepkg.sh.in | 8 ++++---- 2 files changed, 26 insertions(+), 4 deletions(-) diff --git a/scripts/libmakepkg/util/option.sh b/scripts/libmakepkg/util/option.sh index 1b2d94d..1266e05 100644 --- a/scripts/libmakepkg/util/option.sh +++ b/scripts/libmakepkg/util/option.sh @@ -106,3 +106,25 @@ check_buildenv() { # not found return 127 } + +## +# Check if option is present in BUILDENV and not inverted in options +# +# usage : check_buildoption( $option, $expected_val ) +# return : 0 - matches expected +# 1 - does not match expected +# 127 - not found +## +check_buildoption() { + case "$2" in + y) # assert enabled + check_buildenv "$1" "y" && ! check_option "$1" "n" + return ;; + n) # assert disabled + check_buildenv "$1" "n" && ! check_option "$1" "y" + return ;; + esac + + # not found + return 127 +} diff --git a/scripts/makepkg.sh.in b/scripts/makepkg.sh.in index ec8218f..a8bac02 100644 --- a/scripts/makepkg.sh.in +++ b/scripts/makepkg.sh.in @@ -857,13 +857,13 @@ run_prepare() { run_build() { # use distcc if it is requested (check buildenv and PKGBUILD opts) - if check_buildenv "distcc" "y" && ! check_option "distcc" "n"; then + if check_buildoption "distcc" "y"; then [[ -d /usr/lib/distcc/bin ]] && export PATH="/usr/lib/distcc/bin:$PATH" export DISTCC_HOSTS fi # use ccache if it is requested (check buildenv and PKGBUILD opts) - if check_buildenv "ccache" "y" && ! check_option "ccache" "n"; then + if check_buildoption "ccache" "y"; then [[ -d /usr/lib/ccache/bin ]] && export PATH="/usr/lib/ccache/bin:$PATH" fi @@ -1562,7 +1562,7 @@ check_software() { fi # distcc - compilation with distcc - if check_buildenv "distcc" "y" && ! check_option "distcc" "n"; then + if check_buildoption "distcc" "y"; then if ! type -p distcc >/dev/null; then error "$(gettext "Cannot find the %s binary required for distributed compilation.")" "distcc" ret=1 @@ -1570,7 +1570,7 @@ check_software() { fi # ccache - compilation with ccache - if check_buildenv "ccache" "y" && ! check_option "ccache" "n"; then + if check_buildoption "ccache" "y"; then if ! type -p ccache >/dev/null; then error "$(gettext "Cannot find the %s binary required for compiler cache usage.")" "ccache" ret=1 -- 2.5.2
ccache expects further compiler wrappers to be specified via CCACHE_PREFIX. Otherwise, ccache will hash the wrapper executable instead of the real one. Signed-off-by: Jan Alexander Steffens (heftig) <jan.steffens@gmail.com> --- scripts/makepkg.sh.in | 21 ++++++++++++++------- 1 file changed, 14 insertions(+), 7 deletions(-) diff --git a/scripts/makepkg.sh.in b/scripts/makepkg.sh.in index a8bac02..076d315 100644 --- a/scripts/makepkg.sh.in +++ b/scripts/makepkg.sh.in @@ -856,15 +856,22 @@ run_prepare() { } run_build() { - # use distcc if it is requested (check buildenv and PKGBUILD opts) - if check_buildoption "distcc" "y"; then - [[ -d /usr/lib/distcc/bin ]] && export PATH="/usr/lib/distcc/bin:$PATH" - export DISTCC_HOSTS - fi + local ccache=0 # use ccache if it is requested (check buildenv and PKGBUILD opts) - if check_buildoption "ccache" "y"; then - [[ -d /usr/lib/ccache/bin ]] && export PATH="/usr/lib/ccache/bin:$PATH" + if check_buildoption "ccache" "y" && [[ -d /usr/lib/ccache/bin ]]; then + export PATH="/usr/lib/ccache/bin:$PATH" + ccache=1 + fi + + # use distcc if it is requested (check buildenv and PKGBUILD opts) + if check_buildoption "distcc" "y"; then + if (( ccache )); then + export CCACHE_PREFIX="${CCACHE_PREFIX:+$CCACHE_PREFIX }distcc" + elif [[ -d /usr/lib/distcc/bin ]]; then + export PATH="/usr/lib/distcc/bin:$PATH" + fi + export DISTCC_HOSTS fi run_function_safe "build" -- 2.5.2
--- scripts/makepkg.sh.in | 1 + 1 file changed, 1 insertion(+) diff --git a/scripts/makepkg.sh.in b/scripts/makepkg.sh.in index 076d315..7c3cc4b 100644 --- a/scripts/makepkg.sh.in +++ b/scripts/makepkg.sh.in @@ -868,6 +868,7 @@ run_build() { if check_buildoption "distcc" "y"; then if (( ccache )); then export CCACHE_PREFIX="${CCACHE_PREFIX:+$CCACHE_PREFIX }distcc" + export CCACHE_BASEDIR="$srcdir" elif [[ -d /usr/lib/distcc/bin ]]; then export PATH="/usr/lib/distcc/bin:$PATH" fi -- 2.5.2
On 16/09/15 06:17, Jan Alexander Steffens (heftig) wrote:
This reduces code duplication a bit. It also highlights how these options are checked.
Signed-off-by: Jan Alexander Steffens (heftig) <jan.steffens@gmail.com> --- scripts/libmakepkg/util/option.sh | 22 ++++++++++++++++++++++ scripts/makepkg.sh.in | 8 ++++---- 2 files changed, 26 insertions(+), 4 deletions(-)
diff --git a/scripts/libmakepkg/util/option.sh b/scripts/libmakepkg/util/option.sh index 1b2d94d..1266e05 100644 --- a/scripts/libmakepkg/util/option.sh +++ b/scripts/libmakepkg/util/option.sh @@ -106,3 +106,25 @@ check_buildenv() { # not found return 127 } + +## +# Check if option is present in BUILDENV and not inverted in options +# +# usage : check_buildoption( $option, $expected_val ) +# return : 0 - matches expected +# 1 - does not match expected +# 127 - not found +## +check_buildoption() { + case "$2" in + y) # assert enabled + check_buildenv "$1" "y" && ! check_option "$1" "n" + return ;; + n) # assert disabled + check_buildenv "$1" "n" && ! check_option "$1" "y" + return ;; + esac + + # not found + return 127 +}
If you are adding a function for this, might as well fix the issue that the makepkg.conf OPTIONS array is check. Just check the "BUILDENV" and "options" arrays. A
This reduces code duplication a bit. It also highlights how these options are checked. v2: makepkg used to check OPTIONS too, which could override BUILDENV. Fix the implementation to avoid this. Signed-off-by: Jan Alexander Steffens (heftig) <jan.steffens@gmail.com> --- scripts/libmakepkg/util/option.sh | 30 ++++++++++++++++++++++++++++++ scripts/makepkg.sh.in | 8 ++++---- 2 files changed, 34 insertions(+), 4 deletions(-) diff --git a/scripts/libmakepkg/util/option.sh b/scripts/libmakepkg/util/option.sh index 1b2d94d..4ef8766 100644 --- a/scripts/libmakepkg/util/option.sh +++ b/scripts/libmakepkg/util/option.sh @@ -106,3 +106,33 @@ check_buildenv() { # not found return 127 } + +## +# Check if option is present in BUILDENV and not inverted in options +# +# usage : check_buildoption( $option, $expected_val ) +# return : 0 - matches expected +# 1 - does not match expected +# 127 - not found +## +check_buildoption() { + in_opt_array "$1" ${BUILDENV[@]} + case $? in + 0) # assert enabled + [[ $2 = y ]] || return 1 ;; + 1) # assert disabled + [[ $2 = n ]] || return 1 ;; + *) # not found + return 127 ;; + esac + + in_opt_array "$1" ${options[@]} + case $? in + 0) # assert enabled + [[ $2 = y ]] || return 1 ;; + 1) # assert disabled + [[ $2 = n ]] || return 1 ;; + esac + + return 0 +} diff --git a/scripts/makepkg.sh.in b/scripts/makepkg.sh.in index ec8218f..a8bac02 100644 --- a/scripts/makepkg.sh.in +++ b/scripts/makepkg.sh.in @@ -857,13 +857,13 @@ run_prepare() { run_build() { # use distcc if it is requested (check buildenv and PKGBUILD opts) - if check_buildenv "distcc" "y" && ! check_option "distcc" "n"; then + if check_buildoption "distcc" "y"; then [[ -d /usr/lib/distcc/bin ]] && export PATH="/usr/lib/distcc/bin:$PATH" export DISTCC_HOSTS fi # use ccache if it is requested (check buildenv and PKGBUILD opts) - if check_buildenv "ccache" "y" && ! check_option "ccache" "n"; then + if check_buildoption "ccache" "y"; then [[ -d /usr/lib/ccache/bin ]] && export PATH="/usr/lib/ccache/bin:$PATH" fi @@ -1562,7 +1562,7 @@ check_software() { fi # distcc - compilation with distcc - if check_buildenv "distcc" "y" && ! check_option "distcc" "n"; then + if check_buildoption "distcc" "y"; then if ! type -p distcc >/dev/null; then error "$(gettext "Cannot find the %s binary required for distributed compilation.")" "distcc" ret=1 @@ -1570,7 +1570,7 @@ check_software() { fi # ccache - compilation with ccache - if check_buildenv "ccache" "y" && ! check_option "ccache" "n"; then + if check_buildoption "ccache" "y"; then if ! type -p ccache >/dev/null; then error "$(gettext "Cannot find the %s binary required for compiler cache usage.")" "ccache" ret=1 -- 2.5.2
On 20/09/15 06:01, Jan Alexander Steffens (heftig) wrote:
This reduces code duplication a bit. It also highlights how these options are checked.
v2: makepkg used to check OPTIONS too, which could override BUILDENV. Fix the implementation to avoid this.
Signed-off-by: Jan Alexander Steffens (heftig) <jan.steffens@gmail.com> ---
Put "v2" nots below here so they do not get included in the commit message.
scripts/libmakepkg/util/option.sh | 30 ++++++++++++++++++++++++++++++ scripts/makepkg.sh.in | 8 ++++---- 2 files changed, 34 insertions(+), 4 deletions(-)
diff --git a/scripts/libmakepkg/util/option.sh b/scripts/libmakepkg/util/option.sh index 1b2d94d..4ef8766 100644 --- a/scripts/libmakepkg/util/option.sh +++ b/scripts/libmakepkg/util/option.sh @@ -106,3 +106,33 @@ check_buildenv() { # not found return 127 } + +## +# Check if option is present in BUILDENV and not inverted in options +# +# usage : check_buildoption( $option, $expected_val ) +# return : 0 - matches expected +# 1 - does not match expected +# 127 - not found +## +check_buildoption() { + in_opt_array "$1" ${BUILDENV[@]} + case $? in + 0) # assert enabled + [[ $2 = y ]] || return 1 ;; + 1) # assert disabled + [[ $2 = n ]] || return 1 ;; + *) # not found + return 127 ;; + esac + + in_opt_array "$1" ${options[@]} + case $? in + 0) # assert enabled + [[ $2 = y ]] || return 1 ;; + 1) # assert disabled + [[ $2 = n ]] || return 1 ;; + esac + + return 0 +}
The "options" array from the PKGBUILD should take preference. Also, follow the style of the other functions in that file in terms of the return. So it should essentially be check_options but with OPTIONS replaced by BUILDENV. A
makepkg used to check OPTIONS too, which could override BUILDENV. Implement a new function that handles these options more like OPTIONS. This also reduces code duplication a bit. Signed-off-by: Jan Alexander Steffens (heftig) <jan.steffens@gmail.com> --- scripts/libmakepkg/util/option.sh | 34 ++++++++++++++++++++++++++++++++++ scripts/makepkg.sh.in | 8 ++++---- 2 files changed, 38 insertions(+), 4 deletions(-) diff --git a/scripts/libmakepkg/util/option.sh b/scripts/libmakepkg/util/option.sh index 1b2d94d..41c7fd3 100644 --- a/scripts/libmakepkg/util/option.sh +++ b/scripts/libmakepkg/util/option.sh @@ -106,3 +106,37 @@ check_buildenv() { # not found return 127 } + +## +# Checks to see if options are present in BUILDENV or PKGBUILD; +# PKGBUILD options always take precedence. +# +# usage : check_buildoption( $option, $expected_val ) +# return : 0 - matches expected +# 1 - does not match expected +# 127 - not found +## +check_buildoption() { + in_opt_array "$1" ${options[@]} + case $? in + 0) # assert enabled + [[ $2 = y ]] + return ;; + 1) # assert disabled + [[ $2 = n ]] + return + esac + + in_opt_array "$1" ${BUILDENV[@]} + case $? in + 0) # assert enabled + [[ $2 = y ]] + return ;; + 1) # assert disabled + [[ $2 = n ]] + return + esac + + # not found + return 127 +} diff --git a/scripts/makepkg.sh.in b/scripts/makepkg.sh.in index 6ededa3..82dc58f 100644 --- a/scripts/makepkg.sh.in +++ b/scripts/makepkg.sh.in @@ -852,13 +852,13 @@ run_prepare() { run_build() { # use distcc if it is requested (check buildenv and PKGBUILD opts) - if check_buildenv "distcc" "y" && ! check_option "distcc" "n"; then + if check_buildoption "distcc" "y"; then [[ -d /usr/lib/distcc/bin ]] && export PATH="/usr/lib/distcc/bin:$PATH" export DISTCC_HOSTS fi # use ccache if it is requested (check buildenv and PKGBUILD opts) - if check_buildenv "ccache" "y" && ! check_option "ccache" "n"; then + if check_buildoption "ccache" "y"; then [[ -d /usr/lib/ccache/bin ]] && export PATH="/usr/lib/ccache/bin:$PATH" fi @@ -1557,7 +1557,7 @@ check_software() { fi # distcc - compilation with distcc - if check_buildenv "distcc" "y" && ! check_option "distcc" "n"; then + if check_buildoption "distcc" "y"; then if ! type -p distcc >/dev/null; then error "$(gettext "Cannot find the %s binary required for distributed compilation.")" "distcc" ret=1 @@ -1565,7 +1565,7 @@ check_software() { fi # ccache - compilation with ccache - if check_buildenv "ccache" "y" && ! check_option "ccache" "n"; then + if check_buildoption "ccache" "y"; then if ! type -p ccache >/dev/null; then error "$(gettext "Cannot find the %s binary required for compiler cache usage.")" "ccache" ret=1 -- 2.6.1
participants (2)
-
Allan McRae
-
Jan Alexander Steffens (heftig)