[pacman-dev] [PATCH] makepkg: allow make-style environment var overrides
This allows for VAR=value and VAR+=value variable declarations. Signed-off-by: Dave Reisner <dreisner@archlinux.org> --- Similar to the RFC I sent but with the addition of support for appending, not just overriding (as make allows as well). doc/makepkg.8.txt | 2 +- scripts/makepkg.sh.in | 15 +++++++++++++++ 2 files changed, 16 insertions(+), 1 deletion(-) diff --git a/doc/makepkg.8.txt b/doc/makepkg.8.txt index 899858e..512f8ed 100644 --- a/doc/makepkg.8.txt +++ b/doc/makepkg.8.txt @@ -11,7 +11,7 @@ makepkg - package build utility Synopsis -------- -'makepkg' [options] +'makepkg' [options] [ENVVAR=value] [ENVVAR+=value] ... Description diff --git a/scripts/makepkg.sh.in b/scripts/makepkg.sh.in index a2d0d7d..59013f6 100644 --- a/scripts/makepkg.sh.in +++ b/scripts/makepkg.sh.in @@ -2624,6 +2624,16 @@ while true; do shift done +# attempt to consume any extra argv as environment variables. this supports +# overriding (e.g. CC=clang) as well as overriding (e.g. CFLAGS+=' -g'). +extra_environment=() +while [[ $1 ]]; do + if [[ $1 = ?(_[[:alpha:]])+([[:alnum:]_])?(+)=* ]]; then + extra_environment+=("$1") + fi + shift +done + # setup signal traps trap 'clean_up' 0 for signal in TERM HUP QUIT; do @@ -2706,6 +2716,11 @@ if [[ ! -w $BUILDDIR ]]; then exit 1 fi +# override settings from extra variables on commandline, if any +if (( ${#extra_environment[*]} )); then + export "${extra_environment[@]}" +fi + PKGDEST=${_PKGDEST:-$PKGDEST} PKGDEST=${PKGDEST:-$startdir} #default to $startdir if undefined if (( ! (NOBUILD || GENINTEG) )) && [[ ! -w $PKGDEST ]]; then -- 1.8.3.4
On 04/08/13 02:26, Dave Reisner wrote:
This allows for VAR=value and VAR+=value variable declarations.
Signed-off-by: Dave Reisner <dreisner@archlinux.org> --- Similar to the RFC I sent but with the addition of support for appending, not just overriding (as make allows as well).
doc/makepkg.8.txt | 2 +- scripts/makepkg.sh.in | 15 +++++++++++++++ 2 files changed, 16 insertions(+), 1 deletion(-)
diff --git a/doc/makepkg.8.txt b/doc/makepkg.8.txt index 899858e..512f8ed 100644 --- a/doc/makepkg.8.txt +++ b/doc/makepkg.8.txt @@ -11,7 +11,7 @@ makepkg - package build utility
Synopsis -------- -'makepkg' [options] +'makepkg' [options] [ENVVAR=value] [ENVVAR+=value] ...
Description diff --git a/scripts/makepkg.sh.in b/scripts/makepkg.sh.in index a2d0d7d..59013f6 100644 --- a/scripts/makepkg.sh.in +++ b/scripts/makepkg.sh.in @@ -2624,6 +2624,16 @@ while true; do shift done
+# attempt to consume any extra argv as environment variables. this supports +# overriding (e.g. CC=clang) as well as overriding (e.g. CFLAGS+=' -g'). +extra_environment=() +while [[ $1 ]]; do + if [[ $1 = ?(_[[:alpha:]])+([[:alnum:]_])?(+)=* ]]; then
This matches "1=2" which then bails on the export. Should it be: +(_[[:alpha:]])?([[:alnum:]_])?(+)=*
+ extra_environment+=("$1") + fi + shift +done + # setup signal traps trap 'clean_up' 0 for signal in TERM HUP QUIT; do @@ -2706,6 +2716,11 @@ if [[ ! -w $BUILDDIR ]]; then exit 1 fi
+# override settings from extra variables on commandline, if any +if (( ${#extra_environment[*]} )); then + export "${extra_environment[@]}" +fi + PKGDEST=${_PKGDEST:-$PKGDEST} PKGDEST=${PKGDEST:-$startdir} #default to $startdir if undefined if (( ! (NOBUILD || GENINTEG) )) && [[ ! -w $PKGDEST ]]; then
Allan McRae <allan@archlinux.org> wrote:
On 04/08/13 02:26, Dave Reisner wrote:
+ if [[ $1 = ?(_[[:alpha:]])+([[:alnum:]_])?(+)=* ]]; then
This matches "1=2" which then bails on the export. Should it be:
+(_[[:alpha:]])?([[:alnum:]_])?(+)=*
There must be a typo, I think it should be this: [_[:alpha]]*([_[:alnum:]])?(+) which also allows setting the special shell variable $_ but maybe it's fine.
On Mon, Aug 5, 2013 at 11:30 AM, lolilolicon <lolilolicon@gmail.com> wrote:
There must be a typo, I think it should be this:
[_[:alpha]]*([_[:alnum:]])?(+)
Uh, what did I say? There must be a typo! [_[:alpha:]]*([_[:alnum:]])?(+)
which also allows setting the special shell variable $_ but maybe it's fine.
On Mon, Aug 05, 2013 at 11:30:09AM +0800, lolilolicon wrote:
Allan McRae <allan@archlinux.org> wrote:
On 04/08/13 02:26, Dave Reisner wrote:
+ if [[ $1 = ?(_[[:alpha:]])+([[:alnum:]_])?(+)=* ]]; then
This matches "1=2" which then bails on the export. Should it be:
+(_[[:alpha:]])?([[:alnum:]_])?(+)=*
There must be a typo, I think it should be this:
[_[:alpha]]*([_[:alnum:]])?(+)
which also allows setting the special shell variable $_ but maybe it's fine.
Yeah, this is the correct solution. It's fine if people try to set things they aren't supposed to -- makepkg shouldn't actively be in the game of trying to discourage it.
On 06/08/13 00:23, Dave Reisner wrote:
On Mon, Aug 05, 2013 at 11:30:09AM +0800, lolilolicon wrote:
Allan McRae <allan@archlinux.org> wrote:
On 04/08/13 02:26, Dave Reisner wrote:
+ if [[ $1 = ?(_[[:alpha:]])+([[:alnum:]_])?(+)=* ]]; then
This matches "1=2" which then bails on the export. Should it be:
+(_[[:alpha:]])?([[:alnum:]_])?(+)=*
There must be a typo, I think it should be this:
[_[:alpha]]*([_[:alnum:]])?(+)
which also allows setting the special shell variable $_ but maybe it's fine.
Yeah, this is the correct solution. It's fine if people try to set things they aren't supposed to -- makepkg shouldn't actively be in the game of trying to discourage it.
@Dave: updated patch on its way?
This allows for VAR=value and VAR+=value variable declarations. Signed-off-by: Dave Reisner <dreisner@archlinux.org> --- doc/makepkg.8.txt | 2 +- scripts/makepkg.sh.in | 15 +++++++++++++++ 2 files changed, 16 insertions(+), 1 deletion(-) diff --git a/doc/makepkg.8.txt b/doc/makepkg.8.txt index 899858e..0b548bc 100644 --- a/doc/makepkg.8.txt +++ b/doc/makepkg.8.txt @@ -11,7 +11,7 @@ makepkg - package build utility Synopsis -------- -'makepkg' [options] +'makepkg' [options] [ENVVAR=value[ENVVAR+=value] ... Description diff --git a/scripts/makepkg.sh.in b/scripts/makepkg.sh.in index a2d0d7d..eff4d9e 100644 --- a/scripts/makepkg.sh.in +++ b/scripts/makepkg.sh.in @@ -2624,6 +2624,16 @@ while true; do shift done +# attempt to consume any extra argv as environment variables. this supports +# overriding (e.g. CC=clang) as well as overriding (e.g. CFLAGS+=' -g'). +extra_environment=() +while [[ $1 ]]; do + if [[ $1 = [_[:alpha:]]*([[:alnum:]_])?(+)=* ]]; then + extra_environment+=("$1") + fi + shift +done + # setup signal traps trap 'clean_up' 0 for signal in TERM HUP QUIT; do @@ -2706,6 +2716,11 @@ if [[ ! -w $BUILDDIR ]]; then exit 1 fi +# override settings from extra variables on commandline, if any +if (( ${#extra_environment[*]} )); then + export "${extra_environment[@]}" +fi + PKGDEST=${_PKGDEST:-$PKGDEST} PKGDEST=${PKGDEST:-$startdir} #default to $startdir if undefined if (( ! (NOBUILD || GENINTEG) )) && [[ ! -w $PKGDEST ]]; then -- 1.8.3.4
participants (4)
-
Allan McRae
-
Dave Reisner
-
Dave Reisner
-
lolilolicon