From 813aa7d002f141db50ff6d2d276542ed91088043 Mon Sep 17 00:00:00 2001 From: Rob Browning Date: Wed, 25 Dec 2019 18:08:13 -0600 Subject: [PATCH 1/1] Fix the handling of the configure MAKE and PYTHON vars 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 Tested-by: Rob Browning --- Makefile | 8 +++++--- cmd/python-cmd.sh | 2 +- config/.gitignore | 2 +- config/configure | 7 +++---- dev/replace | 29 +++++++++++++++++++++++++++++ dev/shquote | 14 ++++++++++++++ t/test-release-archive.sh | 3 ++- 7 files changed, 55 insertions(+), 10 deletions(-) create mode 100755 dev/replace create mode 100755 dev/shquote diff --git a/Makefile b/Makefile index 9f11100..87e78fa 100644 --- 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 \ diff --git a/cmd/python-cmd.sh b/cmd/python-cmd.sh index 8449bc8..39ec997 100644 --- a/cmd/python-cmd.sh +++ b/cmd/python-cmd.sh @@ -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@ "$@" diff --git a/config/.gitignore b/config/.gitignore index 0887ad8..aaad15d 100644 --- a/config/.gitignore +++ b/config/.gitignore @@ -4,5 +4,5 @@ config.log config.mak config.md config.sub +config.var/ config.vars -config.vars.sh diff --git a/config/configure b/config/configure index 66f6250..33e9ba2 100755 --- a/config/configure +++ b/config/configure @@ -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 index 0000000..4ac0c0e --- /dev/null +++ b/dev/replace @@ -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 index 0000000..d0590a0 --- /dev/null +++ b/dev/shquote @@ -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/\$/'/" diff --git a/t/test-release-archive.sh b/t/test-release-archive.sh index 4c5487a..74ce474 100755 --- a/t/test-release-archive.sh +++ b/t/test-release-archive.sh @@ -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 -- 2.39.2