]> arthur.barton.de Git - bup.git/commitdiff
Fix the handling of the configure MAKE and PYTHON vars
authorRob Browning <rlb@defaultvalue.org>
Thu, 26 Dec 2019 00:08:13 +0000 (18:08 -0600)
committerRob Browning <rlb@defaultvalue.org>
Sat, 11 Jan 2020 20:39:27 +0000 (14:39 -0600)
Instead of trying to negotiate the maze of twisty quoting
passages (bash vs sh, how do you get it to work correctly from a
makefile target, etc.), drop config.vars.sh and just store each
variable value in a separate config/config.var/NAME file, and read
that file whenever we need the value, so that we should be able to
handle more or less arbitrary values, e.g.:

  make PYTHON='srsly?
  why?'

Along the same lines, instead of trying to figure out, in any given
case, how to quote values for sed (through various layers), add
dev/replace, which just does literal replacements of values provided
on the command line.

Also along the same lines, add dev/shquote that quotes values properly
for POSIX sh, and use it.  Previously we produced bash %q quotations,
which can result in $'' bashisms, and then handed them to /bin/sh.

These changes (particularly the switch to the literal @bup_python@
replacement) also lay the groundwork for forthcoming adjustments to
cmd/bup.

Thanks to Johannes Berg for pointing out a couple of bugs, including
that I'd forgotten to use fsdecode after adding it.

Signed-off-by: Rob Browning <rlb@defaultvalue.org>
Tested-by: Rob Browning <rlb@defaultvalue.org>
Makefile
cmd/python-cmd.sh
config/.gitignore
config/configure
dev/replace [new file with mode: 0755]
dev/shquote [new file with mode: 0755]
t/test-release-archive.sh

index 9f111000c06da7997c7f1b9fb88d1e61c6ef696a..87e78fab1731ec7fe72096cff444273c06c7320d 100644 (file)
--- a/Makefile
+++ b/Makefile
@@ -257,9 +257,10 @@ check: test
 distcheck: all
        ./wvtest run t/test-release-archive.sh
 
-cmd/bup-python: cmd/python-cmd.sh config/config.vars Makefile
-       sed -e '$$ d' $< > "$@".$$PPID.tmp
-       printf "exec %q \"\$$@\"\n" "$(bup_python)" >> "$@".$$PPID.tmp
+cmd/bup-python: cmd/python-cmd.sh config/config.var/bup-python
+       dev/replace -l '@bup_python@' \
+         "$$(dev/shquote < config/config.var/bup-python)" \
+         < "$<" > "$@".$$PPID.tmp
        chmod +x "$@".$$PPID.tmp
        mv "$@".$$PPID.tmp "$@"
 
@@ -323,6 +324,7 @@ import-docs: Documentation/clean
 clean: Documentation/clean cmd/bup-python
        cd config && rm -f *~ .*~ \
          ${CONFIGURE_DETRITUS} ${CONFIGURE_FILES} ${GENERATED_FILES}
+       cd config && rm -rf config.var
        rm -f *.o lib/*/*.o *.so lib/*/*.so *.dll lib/*/*.dll *.exe \
                .*~ *~ */*~ lib/*/*~ lib/*/*/*~ \
                *.pyc */*.pyc lib/*/*.pyc lib/*/*/*.pyc \
index 8449bc8b722ca7ee8c2977a63324fd6591b80b38..39ec997a48a61e9eb1c246072e303ad8fc199d2e 100644 (file)
@@ -36,4 +36,4 @@ bup_libdir="$script_home/../lib"  # bup_libdir will be adjusted during install
 
 export PYTHONPATH="$bup_libdir${PYTHONPATH:+:$PYTHONPATH}"
 
-# This last line will be replaced with 'exec some/python "$@"
+exec @bup_python@ "$@"
index 0887ad8ec83051511b6a47947c994d1e110b8a06..aaad15dca1942671ab4035551392592154cd3f44 100644 (file)
@@ -4,5 +4,5 @@ config.log
 config.mak
 config.md
 config.sub
+config.var/
 config.vars
-config.vars.sh
index 66f62501a1b8c37ae787a506b7abc1c35de50873..33e9ba26a00da52d3c769e536635483d7f3a7b17 100755 (executable)
@@ -158,9 +158,8 @@ AC_CHECK_FIELD stat st_ctimensec sys/types.h sys/stat.h unistd.h
 
 AC_CHECK_FIELD tm tm_gmtoff time.h
 
-__config_files="$__config_files config.vars.sh"
-
 AC_OUTPUT config.vars
 
-printf 'bup_make=%q\n' "$MAKE" > config.vars.sh
-printf 'bup_python=%q\n' "$bup_python" >> config.vars.sh
+mkdir -p config.var
+echo -n "$MAKE" > config.var/bup-make
+echo -n "$bup_python" > config.var/bup-python
diff --git a/dev/replace b/dev/replace
new file mode 100755 (executable)
index 0000000..4ac0c0e
--- /dev/null
@@ -0,0 +1,29 @@
+#!/bin/sh
+"""": # -*-python-*-
+exec env LC_CTYPE=iso-8859-1 python "$0" ${1+"$@"}
+"""
+
+from __future__ import absolute_import, print_function
+import sys
+
+py_maj = sys.version_info[0]
+
+import argparse
+if py_maj > 2:
+    byte_stream = lambda x: x.buffer
+    from os import fsencode
+else:
+    byte_stream = lambda x: x
+    fsencode = lambda x: x
+
+parser = argparse.ArgumentParser()
+parser.add_argument('-l', nargs=2, metavar=('ORIG', 'NEW'), action='append',
+                    help='literally replace ORIG with NEW')
+opt = parser.parse_args()
+
+sys.stdout.flush()
+with byte_stream(sys.stdin) as stdin:
+    content = stdin.read()
+for orig, new in opt.l:
+    content = content.replace(fsencode(orig), fsencode(new))
+byte_stream(sys.stdout).write(content)
diff --git a/dev/shquote b/dev/shquote
new file mode 100755 (executable)
index 0000000..d0590a0
--- /dev/null
@@ -0,0 +1,14 @@
+#!/bin/sh
+
+set -eu
+
+case "$#" in
+    0) src="$(cat)";;
+    1) src="$1";;
+    *)
+        echo "Usage: shquote [SOMETHING]" 1>&2
+        exit 2
+        ;;
+esac
+
+printf %s\\n "$src" | sed "s/'/'\\\\''/g;1s/^/'/;\$s/\$/'/"
index 4c5487aab27157c399870616888ceeda04569c86..74ce474c54f698f41c10d86825481c74bcb8035a 100755 (executable)
@@ -1,10 +1,11 @@
 #!/usr/bin/env bash
 . ./wvtest-bup.sh || exit $?
 . t/lib.sh || exit $?
-. config/config.vars.sh
 
 set -o pipefail
 
+bup_make=$(< config/config.var/bup-make)
+
 WVPASS git status > /dev/null
 
 if ! git diff-index --quiet HEAD; then