automake-ng
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Automake-NG] [PATCH 3/5] [ng] am.xargs-map: can pass further arguments


From: Stefano Lattarini
Subject: [Automake-NG] [PATCH 3/5] [ng] am.xargs-map: can pass further arguments to the mapped function
Date: Thu, 9 Aug 2012 12:56:04 +0200

This is just a preparatory refactoring that will be needed by future
changes.

* lib/am/header-vars.mk (am.xargs-map): Improve.
* t/am-xargs-map.sh: Enhance to check the enhanced behaviour.

Signed-off-by: Stefano Lattarini <address@hidden>
---
 lib/am/header-vars.mk | 15 +++++++------
 t/am-xargs-map.sh     | 60 +++++++++++++++++++++++++++++++++++++++++++--------
 2 files changed, 60 insertions(+), 15 deletions(-)

diff --git a/lib/am/header-vars.mk b/lib/am/header-vars.mk
index 2714c60..92b74f6 100644
--- a/lib/am/header-vars.mk
+++ b/lib/am/header-vars.mk
@@ -285,10 +285,12 @@ am.max-cmdline-args := 
xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
 # the system would allow it), or our implementation will likely suffer in
 # performance and in memory consumption.
 
-# $(call am.xargs-map,FUNCTION,LIST)
-# ----------------------------------
-# Map the function $1 on the arguments $2, ensuring that each
-# call of $1 has at most 40 arguments.
+# $(call am.xargs-map,FUNCTION,LIST,[EXTRA-ARGS..])
+# -------------------------------------------------
+# Map the function $1 on the whitespace-separated list $2, ensuring that
+# each call of $1 has at most 40 entries from that list at once.  If
+# further arguments are given (up to $9), they are passed to each $1
+# invocation.
 # This implementation is hacky, but the more elegant or "naive" ones
 # (based on recursion) proved to be ludicrously memory-hungry with
 # huge lists.
@@ -303,10 +305,11 @@ $(if $2,$(strip \
     )$(eval $0.counter := $$($0.counter)x)$(strip \
     )$(eval $0.partial-args += $$i)$(strip \
     )$(if $(filter $(am.max-cmdline-args),$($0.counter)),$(strip \
-      )$(call $1,$(strip $($0.partial-args)))$(strip \
+      )$(call $1,$(strip $($0.partial-args)),$3,$4,$5,$6,$7,$8,$9)$(strip \
       )$(eval $0.partial-args :=)$(strip \
       )$(eval $0.counter :=)))$(strip \
-  )$(if $($0.counter),$(call $1,$(strip $($0.partial-args)))))
+  )$(if $($0.counter),$(call $1,$(strip \
+                        $($0.partial-args)),$3,$4,$5,$6,$7,$8,$9)))
 endef
 
 # Used only by the 'am.clean-cmd.*' functions below.  Do not use in
diff --git a/t/am-xargs-map.sh b/t/am-xargs-map.sh
index e2bbdd0..93c4ef4 100755
--- a/t/am-xargs-map.sh
+++ b/t/am-xargs-map.sh
@@ -23,6 +23,8 @@ am_create_testdir=empty
 # Filter out Automake comments.
 grep -v '^##' "$am_amdir"/header-vars.mk > defn.mk \
   || fatal_ "fetching makefile fragment headers-vars.am"
+echo 'x-warning = $(warning $1)' >> defn.mk
+echo 'y-warning = $(warning $1 -- $2)' >> defn.mk
 
 sed 's/^[0-9][0-9]*:://' > Makefile << 'END'
 01::include ./defn.mk
@@ -35,10 +37,11 @@ sed 's/^[0-9][0-9]*:://' > Makefile << 'END'
 08::
 09::WARN := no
 10::ifeq ($(WARN),yes)
-11::  $(call am.xargs-map,warning,$(args16))
-12::  $(call am.xargs-map,warning,$(args16) 0 1 2 3)
-13::  $(call am.xargs-map,warning,x y z)
-14::endif
+11::  $(call am.xargs-map,x-warning,$(args16))
+12::  $(call am.xargs-map,x-warning,$(args16) 0 1 2 3)
+13::  $(call am.xargs-map,x-warning,x y z)
+14::  $(call am.xargs-map,y-warning,$(args16) 0 1 2 3,X)
+15::endif
 
 args32 := $(args16) $(args16)
 args64 := $(args32) $(args32)
@@ -48,9 +51,15 @@ test-xargs-map:
        $(call am.xargs-map,bar,$(args16))
 
 args = $(error 'args' should be overridden from the command line)
+more-args = $(error 'more-args' should be overridden from the command line)
+
 foo = @echo $1$(am.chars.newline)
 echo-xargs-map:
        $(call am.xargs-map,foo,$(args))
+
+foo2 = @echo $1$(if $2, -- $2)$(am.chars.newline)
+echo2-xargs-map:
+       $(call am.xargs-map,foo2,$(args),$(more-args))
 END
 
 args1="0 1 2 3 4 5 6 7 8 9"
@@ -64,21 +73,31 @@ test $(grep -c "^Makefile:11: $args4$" stderr) -eq 4
 test $(grep -c "^Makefile:12: $args4$" stderr) -eq 4
 test $(grep -c "^Makefile:12: 0 1 2 3$" stderr) -eq 1
 test $(grep -c "^Makefile:13: x y z$" stderr) -eq 1
-test $(grep -c "^Makefile:" stderr) -eq 10
+test $(grep -c "^Makefile:14: $args4 -- X$" stderr) -eq 4
+test $(grep -c "^Makefile:14: 0 1 2 3 -- X" stderr) -eq 1
+test $(grep -c "^Makefile:" stderr) -eq 15
 
 $MAKE 'test-xargs-map'
 
 check_echo ()
 {
   cat > exp
-  $MAKE --no-print-directory "echo-xargs-map" args="$1" >got \
+  mk="$MAKE --no-print-directory"
+  case $# in
+    1) $mk "echo-xargs-map" args="$1";;
+    2) $mk "echo2-xargs-map" args="$1" more-args="$2";;
+    *) fatal_ "check_echo: incorrect usage";;
+  esac >got \
     || { cat got >&2; exit 1; }
   cat exp && cat got && diff exp got || exit 1
 }
 
-echo "$args1" | check_echo '$(args1)'
-echo "$args2" | check_echo '$(args2)'
-echo "$args4" | check_echo '$(args4)'
+echo "$args1"           | check_echo '$(args1)'
+echo "$args1 -- x"      | check_echo '$(args1)' x
+echo "$args2"           | check_echo '$(args2)'
+echo "$args2 -- no"     | check_echo '$(args2)' '$(WARN)'
+echo "$args4"           | check_echo '$(args4)'
+echo "$args4 -- a b c"  | check_echo '$(args4)' '$(notdir x/a ./b c)'
 
 check_echo '$(args8)'<<END
 $args4
@@ -96,11 +115,22 @@ $args4
 x
 END
 
+check_echo "$args4 $args4 x" '.:.' <<END
+$args4 -- .:.
+$args4 -- .:.
+x -- .:.
+END
+
 check_echo "$args4 01 02 03 04 05 06 07" <<END
 $args4
 01 02 03 04 05 06 07
 END
 
+check_echo "$args4 01 2 03" "+++" <<END
+$args4 -- +++
+01 2 03 -- +++
+END
+
 check_echo '$(args32) 11 12 13 67' <<END
 $args4
 $args4
@@ -113,6 +143,18 @@ $args4
 11 12 13 67
 END
 
+check_echo '$(args32) 11 12 13 67' 'lol cat' <<END
+$args4 -- lol cat
+$args4 -- lol cat
+$args4 -- lol cat
+$args4 -- lol cat
+$args4 -- lol cat
+$args4 -- lol cat
+$args4 -- lol cat
+$args4 -- lol cat
+11 12 13 67 -- lol cat
+END
+
 check_echo '$(args64)' <<END
 $args4
 $args4
-- 
1.7.12.rc0




reply via email to

[Prev in Thread] Current Thread [Next in Thread]