[pacman-dev] FS#30582 : add a postextract() to PKGBUILD
Hi A lot of PKGBUILD calls patch in build(), causing errors when you run makepkg --noextract. Patchs/sed and other non-idempotent operations on the sources should be run in another function, which whould only been called after extracting the sources, and not all the times build() is run. Patch attached : diff --git a/scripts/makepkg.sh.in b/scripts/makepkg.sh.in index abfabdf..cf4b542 100644 --- a/scripts/makepkg.sh.in +++ b/scripts/makepkg.sh.in @@ -70,6 +70,7 @@ LOGGING=0 SOURCEONLY=0 IGNOREARCH=0 HOLDVER=0 +POSTEXTRACTFUNC=0 BUILDFUNC=0 CHECKFUNC=0 PKGFUNC=0 @@ -1004,6 +1005,10 @@ run_function() { eval "$shellopts" } +run_postextract() { + run_function_safe "postextract" +} + run_build() { # use distcc if it is requested (check buildenv and PKGBUILD opts) if check_buildenv "distcc" "y" && ! check_option "distc" "n"; then @@ -2280,6 +2285,9 @@ if (( ${#pkgname[@]} > 1 )); then fi # test for available PKGBUILD functions +if declare -f postextract >/dev/null; then + POSTEXTRACTFUNC=1 +fi if declare -f build >/dev/null; then BUILDFUNC=1 fi @@ -2491,6 +2499,9 @@ else download_sources check_source_integrity extract_sources + if (( POSTEXTRACTFUNC )); then + run_postextract + fi fi if (( NOBUILD )); then
http://www.archlinux.org/pacman/submitting-patches.html Please use git format-patch and git send-email if at all possible to submit your patch. Thanks! -Dan On Fri, Jul 27, 2012 at 4:45 PM, Enjolras <0enjolras0@laposte.net> wrote:
Hi
A lot of PKGBUILD calls patch in build(), causing errors when you run makepkg --noextract. Patchs/sed and other non-idempotent operations on the sources should be run in another function, which whould only been called after extracting the sources, and not all the times build() is run.
Patch attached :
diff --git a/scripts/makepkg.sh.in b/scripts/makepkg.sh.in index abfabdf..cf4b542 100644 --- a/scripts/makepkg.sh.in +++ b/scripts/makepkg.sh.in @@ -70,6 +70,7 @@ LOGGING=0 SOURCEONLY=0 IGNOREARCH=0 HOLDVER=0 +POSTEXTRACTFUNC=0 BUILDFUNC=0 CHECKFUNC=0 PKGFUNC=0 @@ -1004,6 +1005,10 @@ run_function() { eval "$shellopts" }
+run_postextract() { + run_function_safe "postextract" +} + run_build() { # use distcc if it is requested (check buildenv and PKGBUILD opts) if check_buildenv "distcc" "y" && ! check_option "distc" "n"; then @@ -2280,6 +2285,9 @@ if (( ${#pkgname[@]} > 1 )); then fi
# test for available PKGBUILD functions +if declare -f postextract >/dev/null; then + POSTEXTRACTFUNC=1 +fi if declare -f build >/dev/null; then BUILDFUNC=1 fi @@ -2491,6 +2499,9 @@ else download_sources check_source_integrity extract_sources + if (( POSTEXTRACTFUNC )); then + run_postextract + fi fi
if (( NOBUILD )); then
prepare is run after the source extraction, and is not run with --noextract option. --- scripts/makepkg.sh.in | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/scripts/makepkg.sh.in b/scripts/makepkg.sh.in index abfabdf..9940d1e 100644 --- a/scripts/makepkg.sh.in +++ b/scripts/makepkg.sh.in @@ -70,6 +70,7 @@ LOGGING=0 SOURCEONLY=0 IGNOREARCH=0 HOLDVER=0 +PREPAREFUNC=0 BUILDFUNC=0 CHECKFUNC=0 PKGFUNC=0 @@ -1004,6 +1005,10 @@ run_function() { eval "$shellopts" } +run_prepare() { + run_function_safe "prepare" +} + run_build() { # use distcc if it is requested (check buildenv and PKGBUILD opts) if check_buildenv "distcc" "y" && ! check_option "distc" "n"; then @@ -2280,6 +2285,9 @@ if (( ${#pkgname[@]} > 1 )); then fi # test for available PKGBUILD functions +if declare -f prepare >/dev/null; then + PREPAREFUNC=1 +fi if declare -f build >/dev/null; then BUILDFUNC=1 fi @@ -2491,6 +2499,9 @@ else download_sources check_source_integrity extract_sources + if (( PREPAREFUNC )); then + run_prepare + fi fi if (( NOBUILD )); then -- 1.7.11.3
I'm a very poor english speaker, don't know if this is ok --- doc/PKGBUILD.5.txt | 9 +++++++++ doc/makepkg.8.txt | 14 +++++++------- 2 files changed, 16 insertions(+), 7 deletions(-) diff --git a/doc/PKGBUILD.5.txt b/doc/PKGBUILD.5.txt index 404a55c..46c6cd9 100644 --- a/doc/PKGBUILD.5.txt +++ b/doc/PKGBUILD.5.txt @@ -296,6 +296,15 @@ If you create any variables of your own in the build function, it is recommended to use the bash `local` keyword to scope the variable to inside the build function. +prepare() Function +------------------ +An optional prepare() function can be specified in addition to the build() +function. This function is useful for operations which should only be run +once on the sources. This function is run after the source extraction and +before the build() function, but is not run if the sources are not extracted. +The function is run in `bash -e` mode, meaning any command that exits with a +non zero status will cause the function to exit. + check() Function ---------------- An optional check() function can be specified in which a packages test-suite diff --git a/doc/makepkg.8.txt b/doc/makepkg.8.txt index 27875a3..1b2421d 100644 --- a/doc/makepkg.8.txt +++ b/doc/makepkg.8.txt @@ -60,10 +60,10 @@ Options *-e, \--noextract*:: Do not extract source files; use whatever source already exists in the - src/ directory. This is handy if you want to go into src/ and manually - patch or tweak code, then make a package out of the result. Keep in mind - that creating a patch may be a better solution to allow others to use - your PKGBUILD. + src/ directory. Do not run the prepare() function. This is handy if you + want to go into src/ and manually patch or tweak code, then make a + package out of the result. Keep in mind that creating a patch may be + a better solution to allow others to use your PKGBUILD. *-f, \--force*:: makepkg will not build a package if a built package already exists in @@ -116,9 +116,9 @@ Options Disable color in output messages. *-o, \--nobuild*:: - Download and extract files only, but do not build them. Useful with the - '\--noextract' option if you wish to tweak the files in src/ before - building. + Download and extract files, run the prepare() function, but do not build + them. Useful with the '\--noextract' option if you wish to tweak the files + in src/ before building. *-p* <buildscript>:: Read the package script `buildscript` instead of the `PKGBUILD` default; -- 1.7.11.3
On 28/07/12 19:20, Enjolras wrote:
I'm a very poor english speaker, don't know if this is ok
Thanks. This was a great start. I altered the text to this and pushed to my working branch: diff --git a/doc/PKGBUILD.5.txt b/doc/PKGBUILD.5.txt index c49007e..47f9e88 100644 --- a/doc/PKGBUILD.5.txt +++ b/doc/PKGBUILD.5.txt @@ -305,6 +305,15 @@ If you create any variables of your own in the build function, it is recommended to use the bash `local` keyword to scope the variable to inside the build function. +prepare() Function +------------------ +An optional prepare() function can be specified in which operations that are +to be run in order to prepare the sources for building (such as patching) are +performed. This function is run after the source extraction and before the +build() function and is skipped when source extraction is skipped. The +function is run in `bash -e` mode, meaning any command that exits with a +non-zero status will cause the function to exit. + check() Function ---------------- An optional check() function can be specified in which a packages test-suite diff --git a/doc/makepkg.8.txt b/doc/makepkg.8.txt index ab3c276..9d19e38 100644 --- a/doc/makepkg.8.txt +++ b/doc/makepkg.8.txt @@ -59,11 +59,11 @@ Options installed. *-e, \--noextract*:: - Do not extract source files; use whatever source already exists in the - src/ directory. This is handy if you want to go into src/ and manually - patch or tweak code, then make a package out of the result. Keep in mind - that creating a patch may be a better solution to allow others to use - your PKGBUILD. + Do not extract source files or run the prepare() function (if present); + use whatever source already exists in the $srcdir/ directory. This is + handy if you want to go into $srcdir/ and manually patch or tweak code, + then make a package out of the result. Keep in mind that creating a + patch may be a better solution to allow others to use your PKGBUILD. *-f, \--force*:: makepkg will not build a package if a built package already exists in @@ -110,9 +110,9 @@ Options Disable color in output messages. *-o, \--nobuild*:: - Download and extract files only, but do not build them. Useful with the - '\--noextract' option if you wish to tweak the files in src/ before - building. + Download and extract files, run the prepare() function, but do not build + them. Useful with the '\--noextract' option if you wish to tweak the files + in $srcdir/ before building. *-p* <buildscript>:: Read the package script `buildscript` instead of the `PKGBUILD` default;
On 28/07/12 19:20, Enjolras wrote:
prepare is run after the source extraction, and is not run with --noextract option. --- scripts/makepkg.sh.in | 11 +++++++++++ 1 file changed, 11 insertions(+)
diff --git a/scripts/makepkg.sh.in b/scripts/makepkg.sh.in index abfabdf..9940d1e 100644 --- a/scripts/makepkg.sh.in +++ b/scripts/makepkg.sh.in @@ -70,6 +70,7 @@ LOGGING=0 SOURCEONLY=0 IGNOREARCH=0 HOLDVER=0 +PREPAREFUNC=0 BUILDFUNC=0 CHECKFUNC=0 PKGFUNC=0 @@ -1004,6 +1005,10 @@ run_function() { eval "$shellopts" }
+run_prepare() { + run_function_safe "prepare" +} + run_build() { # use distcc if it is requested (check buildenv and PKGBUILD opts) if check_buildenv "distcc" "y" && ! check_option "distc" "n"; then @@ -2280,6 +2285,9 @@ if (( ${#pkgname[@]} > 1 )); then fi
# test for available PKGBUILD functions +if declare -f prepare >/dev/null; then + PREPAREFUNC=1 +fi if declare -f build >/dev/null; then BUILDFUNC=1 fi @@ -2491,6 +2499,9 @@ else download_sources check_source_integrity extract_sources + if (( PREPAREFUNC )); then + run_prepare + fi
Whitespace issue here. Fixed and pulled to my working branch.
fi
if (( NOBUILD )); then
On 28/07/12 07:45, Enjolras wrote:
Hi
A lot of PKGBUILD calls patch in build(), causing errors when you run makepkg --noextract. Patchs/sed and other non-idempotent operations on the sources should be run in another function, which whould only been called after extracting the sources, and not all the times build() is run.
I would prefer it to be name "prepare()". A single function name fits the style of the rest (build, check, package). Also, documentation is needed - both PKGBUILD.5 and makepkg.8 (behaviour of --noextract).
Patch attached :
diff --git a/scripts/makepkg.sh.in b/scripts/makepkg.sh.in index abfabdf..cf4b542 100644 --- a/scripts/makepkg.sh.in +++ b/scripts/makepkg.sh.in @@ -70,6 +70,7 @@ LOGGING=0 SOURCEONLY=0 IGNOREARCH=0 HOLDVER=0 +POSTEXTRACTFUNC=0 BUILDFUNC=0 CHECKFUNC=0 PKGFUNC=0 @@ -1004,6 +1005,10 @@ run_function() { eval "$shellopts" }
+run_postextract() { + run_function_safe "postextract" +} + run_build() { # use distcc if it is requested (check buildenv and PKGBUILD opts) if check_buildenv "distcc" "y" && ! check_option "distc" "n"; then @@ -2280,6 +2285,9 @@ if (( ${#pkgname[@]} > 1 )); then fi
# test for available PKGBUILD functions +if declare -f postextract >/dev/null; then + POSTEXTRACTFUNC=1 +fi if declare -f build >/dev/null; then BUILDFUNC=1 fi @@ -2491,6 +2499,9 @@ else download_sources check_source_integrity extract_sources + if (( POSTEXTRACTFUNC )); then + run_postextract + fi fi
if (( NOBUILD )); then
participants (3)
-
Allan McRae
-
Dan McGee
-
Enjolras