[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Automake-NG] [PATCH 5/5] [ng] uninstall: refactor, more processing dele
From: |
Stefano Lattarini |
Subject: |
[Automake-NG] [PATCH 5/5] [ng] uninstall: refactor, more processing delegated to GNU make |
Date: |
Thu, 9 Aug 2012 12:56:06 +0200 |
* lib/am/header-vars.mk (am.chars.space, am.chars.tab): New variables,
defined respectively to a literal white space characters and a literal
tabulation character.
(am.util.whitespace-escape): New function, backslash-escape whitespace
characters in the given string.
(am.util.file-exists): New function, tell whether the given argument
is an existing file; it does so coping correctly with whitespaces and
wildcard metacharacters as well, to be usable with paths containing
references to $(DESTDIR).
(am.uninst.cmd.aux): Re-implement using the new $(am.util.file-exists)
function.
Signed-off-by: Stefano Lattarini <address@hidden>
---
lib/am/header-vars.mk | 57 ++++++++++++++++++++++++++++++++-------------------
t/internals.tap | 29 +++++++++++++++++++++++++-
2 files changed, 64 insertions(+), 22 deletions(-)
diff --git a/lib/am/header-vars.mk b/lib/am/header-vars.mk
index 4ae77e9..50519a1 100644
--- a/lib/am/header-vars.mk
+++ b/lib/am/header-vars.mk
@@ -90,6 +90,12 @@ am.chars.squote := '
# definition of $(am.chars.newline) just below for a significant example.
am.chars.empty :=
+# A single whitespace.
+am.chars.space := $(am.chars.empty) $(am.chars.empty)
+
+# A single tabulation character.
+am.chars.tab := $(am.chars.empty) $(am.chars.empty)
+
# A literal newline character, that does not get stripped if used
# at the end of the expansion of another macro.
define am.chars.newline
@@ -381,6 +387,26 @@ am__base_list = \
sed '$$!N;$$!N;$$!N;$$!N;$$!N;$$!N;$$!N;s/\n/ /g' | \
sed '$$!N;$$!N;$$!N;$$!N;s/\n/ /g'
+# New function, backslash-escape whitespace in the given string.
+define am.util.whitespace-escape
+$(subst $(am.chars.space),\$(am.chars.space),$(subst
$(am.chars.tab),\$(am.chars.tab),$1))
+endef
+
+# Determine whether the given file exists. Since this function is
+# expected to be used on paths referencing $(DESTDIR), it must be
+# ready to cope with whitespaces and shell metacharacters.
+# FIXME: here we assume that the shell found by Autoconf-generated
+# configure supports "test -e"; that is not completely correct ATM, but
+# future versions of Autoconf will reject non-POSIX shells, so we should
+# be safe in the long term.
+define am.util.file-exists
+$(strip \
+ $(if $(strip $(findstring *,$1) $(findstring ?,$1) \
+ $(findstring [,$1) $(findstring ],$1)), \
+ $(shell test -e '$(subst $(am.chars.squote),'\'',$1)' && echo yes), \
+ $(if $(wildcard $(call am.util.whitespace-escape,$1)),yes)))
+endef
+
# $(call am.uninst.cmd,DIR,FILES,[RM-OPTS])
# -----------------------------------------
# Uninstall the given files from the given directory, avoiding to hit
@@ -390,25 +416,14 @@ am__base_list = \
# passed to the rm invocation removing the files (this ca be useful in
# case such files are actually directories (as happens with the HTML
# documentation), in which case rm should be passed the '-r' option.
-# At least Solaris /bin/sh still lacks 'test -e', so we use the multiple
-# "test ! -[fdr]" below instead (FIXME: this should become obsolete when
-# we can assume the $SHELL set by Autoconf-generated configure scripts is
-# a truly POSIX shell; see:
-# <http://lists.gnu.org/archive/html/bug-autoconf/2012-06/msg00009.html>).
-# We expect $dir to be either non-existent or a directory, so the
-# failure we'll experience if it is a regular file is indeed desired
-# and welcome (better to fail loudly than silently).
-# Similarly to the 'am.clean-cmd.f' above, this function is only meant to
-# be used in a "sub-recipe" by its own.
-am.uninst.cmd.aux = \
- $(if $(and $2,$1), \
- { test ! -d '$(DESTDIR)'$2 \
- && test ! -f '$(DESTDIR)'$2 \
- && test ! -r '$(DESTDIR)'$2; } \
- || { \
- echo " cd '$(DESTDIR)$2' && rm -f $1" \
- && cd '$(DESTDIR)$2' \
- && rm -f$(if $3, $3) $1; }$(am.chars.newline))
-am.uninst.cmd = \
- @$(call am.xargs-map,$0.aux,$(strip $2),$(strip $1),$(strip $3))
+# Similarly to the 'am.clean-cmd.f' above, this function is only meant
+# to be used in a "sub-recipe" by its own.
+
+define am.uninst.cmd.aux
+$(if $(and $2,$1),$(if $(call am.util.file-exists,$(DESTDIR)$2),$(strip \
+)cd '$(DESTDIR)$2' && rm -f$(if $3, $3) $1$(am.chars.newline)))
+endef
+define am.uninst.cmd
+$(call am.xargs-map,$0.aux,$(strip $2),$(strip $1),$(strip $3))
+endef
diff --git a/t/internals.tap b/t/internals.tap
index 31b939c..f4c8a18 100755
--- a/t/internals.tap
+++ b/t/internals.tap
@@ -19,7 +19,7 @@
am_create_testdir=empty
. ./defs || exit 1
-plan_ 12
+plan_ 13
# Filter out Automake comments.
grep -v '^##' "$am_amdir"/header-vars.mk > defn.mk \
@@ -252,4 +252,31 @@ test:
test -f n3
END
+T 'am.util.file-exists' <<'END'
+prepare:
+ : > 'a'
+ test -f 'a'
+ : > '?'
+ test -f '?'
+ : > 'foo bar'
+ test -f 'foo bar'
+ mkdir 'a b'
+ test -d 'a b'
+ : > 'a b'/'c d'
+ test -f 'a b'/'c d'
+test: prepare
+ test x'$(call am.util.file-exists,.)' = x'yes'
+ test x'$(call am.util.file-exists,Makefile)' = x'yes'
+ test x'$(call am.util.file-exists,.././defn.mk)' = x'yes'
+ test x'$(call am.util.file-exists,none)' = x
+ test x'$(call am.util.file-exists,Makefile oops)' = x
+ test x'$(call am.util.file-exists,foo bar)' = x'yes'
+ test x'$(call am.util.file-exists,a b)' = x'yes'
+ test x'$(call am.util.file-exists,a b/c d)' = x'yes'
+ test x'$(call am.util.file-exists,*)' = x
+ test x'$(call am.util.file-exists,a)' = x'yes'
+ test x'$(call am.util.file-exists,[ab])' = x
+ test x'$(call am.util.file-exists,?)' = x'yes'
+END
+
:
--
1.7.12.rc0