[pacman-dev] [PATCH] [RFC] makepkg: move build enviroment set-up to function
This is the first set require to split the preparation of the build environment into libmakepkg, which will allow dropping in extensions (e.g. to allow PGO). After this patch, disabling buildflags or makeflags and enabling debug CFLAGS will only effect the build() and check() functions. These are no longer exported for the prepare() and package() function. This should have zero impact for the prepare() and package() functions of a properly written PKGBUILD, as no building/linking is done there... Signed-off-by: Allan McRae <allan@archlinux.org> --- Can anyone think of a case where a well written PKGBUILD will be affected by this change to handling '!buildflags', '!makeflags' and 'debug'? scripts/makepkg.sh.in | 77 +++++++++++++++++++++++++++------------------------ 1 file changed, 41 insertions(+), 36 deletions(-) diff --git a/scripts/makepkg.sh.in b/scripts/makepkg.sh.in index f80e37a..beb90b9 100644 --- a/scripts/makepkg.sh.in +++ b/scripts/makepkg.sh.in @@ -763,6 +763,45 @@ source_buildfile() { source_safe "$@" } +prepare_buildenv() { + # clear user-specified buildflags if requested + if check_option "buildflags" "n"; then + unset CPPFLAGS CFLAGS CXXFLAGS LDFLAGS + fi + + if check_option "debug" "y"; then + CFLAGS+=" $DEBUG_CFLAGS" + CXXFLAGS+=" $DEBUG_CXXFLAGS" + fi + + # clear user-specified makeflags if requested + if check_option "makeflags" "n"; then + unset MAKEFLAGS + fi + + # ensure all necessary build variables are exported + export CPPFLAGS CFLAGS CXXFLAGS LDFLAGS MAKEFLAGS CHOST + + local ccache=0 + + # use ccache if it is requested (check buildenv and PKGBUILD opts) + 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" + export CCACHE_BASEDIR="$srcdir" + elif [[ -d /usr/lib/distcc/bin ]]; then + export PATH="/usr/lib/distcc/bin:$PATH" + fi + export DISTCC_HOSTS + fi +} + run_function_safe() { local restoretrap @@ -786,26 +825,9 @@ run_function() { fi local pkgfunc="$1" - # clear user-specified buildflags if requested - if check_option "buildflags" "n"; then - unset CPPFLAGS CFLAGS CXXFLAGS LDFLAGS - fi - - if check_option "debug" "y"; then - CFLAGS+=" $DEBUG_CFLAGS" - CXXFLAGS+=" $DEBUG_CXXFLAGS" - fi - - # clear user-specified makeflags if requested - if check_option "makeflags" "n"; then - unset MAKEFLAGS - fi - msg "$(gettext "Starting %s()...")" "$pkgfunc" cd_safe "$srcdir" - # ensure all necessary build variables are exported - export CPPFLAGS CFLAGS CXXFLAGS LDFLAGS MAKEFLAGS CHOST # save our shell options so pkgfunc() can't override what we need local shellopts=$(shopt -p) @@ -847,25 +869,6 @@ run_prepare() { } run_build() { - local ccache=0 - - # use ccache if it is requested (check buildenv and PKGBUILD opts) - 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" - export CCACHE_BASEDIR="$srcdir" - elif [[ -d /usr/lib/distcc/bin ]]; then - export PATH="/usr/lib/distcc/bin:$PATH" - fi - export DISTCC_HOSTS - fi - run_function_safe "build" } @@ -2122,6 +2125,8 @@ else chmod a-srw "$pkgdirbase" cd_safe "$startdir" + prepare_buildenv + if (( ! REPKG )); then (( BUILDFUNC )) && run_build (( CHECKFUNC )) && run_check -- 2.7.4
On 02/04/16 22:50, Allan McRae wrote:
This is the first set require to split the preparation of the build environment into libmakepkg, which will allow dropping in extensions (e.g. to allow PGO).
After this patch, disabling buildflags or makeflags and enabling debug CFLAGS will only effect the build() and check() functions. These are no longer exported for the prepare() and package() function. This should have zero impact for the prepare() and package() functions of a properly written PKGBUILD, as no building/linking is done there...
Signed-off-by: Allan McRae <allan@archlinux.org> ---
Can anyone think of a case where a well written PKGBUILD will be affected by this change to handling '!buildflags', '!makeflags' and 'debug'?
To answer my own question... I can. Shitty makefiles mean '!makeflags' may be important for "make install" during package(). So prepare_buildenv will need run before packaging A
participants (1)
-
Allan McRae