|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
progname=$0 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
func_exit () |
|
|
{ |
|
|
(exit $1); exit $1 |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
func_fatal_error () |
|
|
{ |
|
|
echo "$progname: *** $1" 1>&2 |
|
|
echo "$progname: *** Stop." 1>&2 |
|
|
func_exit 1 |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
if (type readlink) > /dev/null 2>&1; then |
|
|
func_readlink () |
|
|
{ |
|
|
|
|
|
readlink "$1" |
|
|
} |
|
|
else |
|
|
func_readlink () |
|
|
{ |
|
|
|
|
|
|
|
|
LC_ALL=C ls -l "$1" | sed -e 's, -> ,#%%#,' | sed -n -e 's,^.*#%%#\(.*\)$,\1,p' |
|
|
} |
|
|
fi |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
func_gnulib_dir () |
|
|
{ |
|
|
case "$progname" in |
|
|
/* | ?:*) self_abspathname="$progname" ;; |
|
|
*/*) self_abspathname=`pwd`/"$progname" ;; |
|
|
*) |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
self_abspathname= |
|
|
if test "$PATH_SEPARATOR" = ";"; then |
|
|
|
|
|
pathx=".;$PATH" |
|
|
else |
|
|
|
|
|
pathx="$PATH" |
|
|
case :$PATH: in |
|
|
*::*) |
|
|
pathx=`echo ":$PATH:" | sed -e 's/:::*/:.:/g' -e 's/^://' -e 's/:\$//'` |
|
|
;; |
|
|
esac |
|
|
fi |
|
|
saved_IFS="$IFS" |
|
|
IFS="$PATH_SEPARATOR" |
|
|
for d in $pathx; do |
|
|
IFS="$saved_IFS" |
|
|
test -z "$d" && d=. |
|
|
if test -x "$d/$progname" && test ! -d "$d/$progname"; then |
|
|
self_abspathname="$d/$progname" |
|
|
break |
|
|
fi |
|
|
done |
|
|
IFS="$saved_IFS" |
|
|
if test -z "$self_abspathname"; then |
|
|
func_fatal_error "could not locate the gnulib-tool program - how did you invoke it?" |
|
|
fi |
|
|
;; |
|
|
esac |
|
|
while test -h "$self_abspathname"; do |
|
|
|
|
|
linkval=`func_readlink "$self_abspathname"` |
|
|
test -n "$linkval" || break |
|
|
case "$linkval" in |
|
|
/* | ?:* ) self_abspathname="$linkval" ;; |
|
|
* ) self_abspathname=`echo "$self_abspathname" | sed -e 's,/[^/]*$,,'`/"$linkval" ;; |
|
|
esac |
|
|
done |
|
|
gnulib_dir=`echo "$self_abspathname" | sed -e 's,/[^/]*$,,'` |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if case $progname in |
|
|
*/*) test -h "$0" ;; |
|
|
esac |
|
|
then |
|
|
func_gnulib_dir |
|
|
prog=$gnulib_dir/gnulib-tool |
|
|
else |
|
|
prog=${progname%/*}/gnulib-tool |
|
|
fi |
|
|
|
|
|
case "$GNULIB_TOOL_IMPL" in |
|
|
'') |
|
|
|
|
|
|
|
|
if (python3 -c 'import sys; sys.exit(not sys.version_info >= (3,7))') 2>/dev/null; then |
|
|
exec "$prog.py" "$@" |
|
|
else |
|
|
echo "gnulib-tool: warning: python3 not found or too old, using the slow shell-based implementation" 1>&2 |
|
|
exec "$prog.sh" "$@" |
|
|
fi |
|
|
;; |
|
|
sh) |
|
|
exec "$prog.sh" "$@" ;; |
|
|
py) |
|
|
exec "$prog.py" "$@" ;; |
|
|
sh+py) |
|
|
case " $* " in |
|
|
*" --import"* | *" --add-import"* | *" --remove-import"* | *" --update"* | *" --copy-file"*) |
|
|
|
|
|
|
|
|
tmpdir=`cd .. && pwd` |
|
|
{ |
|
|
|
|
|
|
|
|
tmp=`(umask 077 && mktemp -d "$tmpdir/glpyXXXXXX") 2>/dev/null` && |
|
|
test -n "$tmp" && test -d "$tmp" |
|
|
} || |
|
|
{ |
|
|
|
|
|
|
|
|
tmp=$tmpdir/glpy$$ |
|
|
(umask 077 && mkdir "$tmp") |
|
|
} || |
|
|
{ |
|
|
echo "$progname: cannot create a temporary directory in $tmpdir" >&2 |
|
|
func_exit 1 |
|
|
} |
|
|
|
|
|
{ tar cf - . | (cd "$tmp" && tar xf -); } || |
|
|
{ |
|
|
echo "$progname: failed to clone the current directory" >&2 |
|
|
func_exit 1 |
|
|
} |
|
|
|
|
|
case $prog in |
|
|
/*) absprog=$prog ;; |
|
|
*) absprog=$PWD/prog ;; |
|
|
esac |
|
|
(cd "$tmp" && "$absprog.py" "$@" >"$tmp-py-out" 2>"$tmp-py-err") |
|
|
pyrc=$? |
|
|
|
|
|
"$prog.sh" "$@" >"$tmp-sh-out" 2>"$tmp-sh-err" |
|
|
shrc=$? |
|
|
if test $shrc != 0; then |
|
|
if test $pyrc = 0; then |
|
|
func_fatal_error "gnulib-tool.sh failed but gnulib-tool.py succeeded! Inspect $tmp-sh-err and $tmp-py-err." |
|
|
else |
|
|
cat "$tmp-sh-out" |
|
|
cat "$tmp-sh-err" >&2 |
|
|
rm -rf "$tmp" "$tmp-sh-out" "$tmp-sh-err" "$tmp-py-out" "$tmp-py-err" |
|
|
exit $shrc |
|
|
fi |
|
|
fi |
|
|
if test $pyrc != 0; then |
|
|
func_fatal_error "gnulib-tool.sh succeeded but gnulib-tool.py failed! Inspect $tmp/ and $tmp-py-err." |
|
|
fi |
|
|
|
|
|
|
|
|
|
|
|
if LC_ALL=C diff --help 2>/dev/null | grep no-dereference >/dev/null; then |
|
|
diff_options='--no-dereference' |
|
|
else |
|
|
diff_options= |
|
|
fi |
|
|
diff -r $diff_options --exclude=__pycache__ --exclude=autom4te.cache -q . "$tmp" >/dev/null || |
|
|
func_fatal_error "gnulib-tool.py produced different files than gnulib-tool.sh! Compare `pwd` and $tmp." |
|
|
|
|
|
diff -q "$tmp-sh-out" "$tmp-py-out" >/dev/null || |
|
|
func_fatal_error "gnulib-tool.py produced different output than gnulib-tool.sh! Compare $tmp-sh-out and $tmp-py-out." |
|
|
|
|
|
cat "$tmp-sh-out" |
|
|
cat "$tmp-sh-err" >&2 |
|
|
rm -rf "$tmp" "$tmp-sh-out" "$tmp-sh-err" "$tmp-py-out" "$tmp-py-err" |
|
|
exit 0 |
|
|
;; |
|
|
*" --create-testdir"* | *" --create-megatestdir"*) |
|
|
|
|
|
|
|
|
dir=`echo " $* " | sed -n -e 's/^.* --dir=//p' | sed -e 's/ .*//'` |
|
|
if test -z "$dir"; then |
|
|
dir=`echo " $* " | sed -n -e 's/^.* --dir *//p' | sed -e 's/ .*//'` |
|
|
if test -z "$dir"; then |
|
|
func_fatal_error "could not extract --dir value" |
|
|
fi |
|
|
fi |
|
|
|
|
|
tmp="$dir-glpy$$" |
|
|
|
|
|
"$prog.py" "$@" --dir="$tmp" >"$tmp-py-out" 2>"$tmp-py-err" |
|
|
pyrc=$? |
|
|
|
|
|
"$prog.sh" "$@" >"$tmp-sh-out" 2>"$tmp-sh-err" |
|
|
shrc=$? |
|
|
if test $shrc != 0; then |
|
|
if test $pyrc = 0; then |
|
|
func_fatal_error "gnulib-tool.sh failed but gnulib-tool.py succeeded! Inspect $tmp-sh-err and $tmp-py-err." |
|
|
else |
|
|
cat "$tmp-sh-out" |
|
|
cat "$tmp-sh-err" >&2 |
|
|
rm -rf "$tmp" "$tmp-sh-out" "$tmp-sh-err" "$tmp-py-out" "$tmp-py-err" |
|
|
exit $shrc |
|
|
fi |
|
|
fi |
|
|
if test $pyrc != 0; then |
|
|
func_fatal_error "gnulib-tool.sh succeeded but gnulib-tool.py failed! Inspect $tmp/ and $tmp-py-err." |
|
|
fi |
|
|
|
|
|
|
|
|
|
|
|
if LC_ALL=C diff --help 2>/dev/null | grep no-dereference >/dev/null; then |
|
|
diff_options='--no-dereference' |
|
|
else |
|
|
diff_options= |
|
|
fi |
|
|
diff -r $diff_options -q "$dir" "$tmp" >/dev/null || |
|
|
func_fatal_error "gnulib-tool.py produced different files than gnulib-tool.sh! Compare $dir and $tmp." |
|
|
|
|
|
diff -q "$tmp-sh-out" "$tmp-py-out" >/dev/null || |
|
|
func_fatal_error "gnulib-tool.py produced different output than gnulib-tool.sh! Compare $tmp-sh-out and $tmp-py-out." |
|
|
|
|
|
cat "$tmp-sh-out" |
|
|
cat "$tmp-sh-err" >&2 |
|
|
rm -rf "$tmp" "$tmp-sh-out" "$tmp-sh-err" "$tmp-py-out" "$tmp-py-err" |
|
|
exit 0 |
|
|
;; |
|
|
*) |
|
|
|
|
|
tmp="glpy$$" |
|
|
|
|
|
"$prog.py" "$@" >"$tmp-py-out" 2>"$tmp-py-err" |
|
|
pyrc=$? |
|
|
|
|
|
"$prog.sh" "$@" >"$tmp-sh-out" 2>"$tmp-sh-err" |
|
|
shrc=$? |
|
|
if test $shrc != 0; then |
|
|
if test $pyrc = 0; then |
|
|
func_fatal_error "gnulib-tool.sh failed but gnulib-tool.py succeeded! Inspect $tmp-sh-err and $tmp-py-err." |
|
|
else |
|
|
cat "$tmp-sh-out" |
|
|
cat "$tmp-sh-err" >&2 |
|
|
rm -rf "$tmp-sh-out" "$tmp-sh-err" "$tmp-py-out" "$tmp-py-err" |
|
|
exit $shrc |
|
|
fi |
|
|
fi |
|
|
if test $pyrc != 0; then |
|
|
func_fatal_error "gnulib-tool.sh succeeded but gnulib-tool.py failed! Inspect $tmp-py-err." |
|
|
fi |
|
|
|
|
|
diff -q "$tmp-sh-out" "$tmp-py-out" >/dev/null || |
|
|
func_fatal_error "gnulib-tool.py produced different output than gnulib-tool.sh! Compare $tmp-sh-out and $tmp-py-out." |
|
|
|
|
|
cat "$tmp-sh-out" |
|
|
cat "$tmp-sh-err" >&2 |
|
|
rm -rf "$tmp-sh-out" "$tmp-sh-err" "$tmp-py-out" "$tmp-py-err" |
|
|
exit 0 |
|
|
;; |
|
|
esac |
|
|
;; |
|
|
*) |
|
|
func_fatal_error "invalid value of GNULIB_TOOL_IMPL: $GNULIB_TOOL_IMPL" ;; |
|
|
esac |
|
|
|