pkgsrc-Changes-HG archive
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]
[pkgsrc/trunk]: pkgsrc mk/tools: in the wrapper log, quote arguments containi...
details: https://anonhg.NetBSD.org/pkgsrc/rev/bee8ca14a178
branches: trunk
changeset: 396141:bee8ca14a178
user: rillig <rillig%pkgsrc.org@localhost>
date: Wed May 22 20:47:05 2019 +0000
description:
mk/tools: in the wrapper log, quote arguments containing = naturally
diffstat:
mk/tools/shquote.sh | 20 +++++++++++++++++---
regress/tools/files/logging-test.sh | 6 +++---
regress/tools/files/shquote-test.sh | 9 +++++++++
3 files changed, 29 insertions(+), 6 deletions(-)
diffs (76 lines):
diff -r b0eb8a486782 -r bee8ca14a178 mk/tools/shquote.sh
--- a/mk/tools/shquote.sh Wed May 22 20:01:17 2019 +0000
+++ b/mk/tools/shquote.sh Wed May 22 20:47:05 2019 +0000
@@ -1,5 +1,5 @@
#! /bin/sh
-# $NetBSD: shquote.sh,v 1.1 2019/03/24 11:29:19 rillig Exp $
+# $NetBSD: shquote.sh,v 1.2 2019/05/22 20:47:05 rillig Exp $
# Quotes all shell meta characters from $1 and writes the result to $shquoted.
shquote()
@@ -7,13 +7,27 @@
shquoted=$1
case $shquoted in
*\'*)
- shquoted=`$tools_wrapper_sed -e 's,'\'','\''\\\\'\'''\'',g' <<EOF
+ # replace each ' with '\''
+ shquoted=`$tools_wrapper_sed -e "s,','\\\\\\\\'',g" <<EOF
$shquoted
EOF`
esac
case $shquoted in
- *[!!%+,\-./0-9:=@A-Z_a-z]*|'')
+ (*[!!%+,\-./0-9:=@A-Z_a-z]*|'')
+
+ # Move the single quote after the first equals sign, so that
+ # macro definitions look like -DMACRO='"value"' instead of
+ # the less common '-DMACRO="value"'.
+ case $shquoted in
+ (*=*) lhs=${shquoted%%=*}
+ case $lhs in
+ (*[!!%+,\-./0-9:=@A-Z_a-z]*|'') ;;
+ (*) shquoted="$lhs='${shquoted#*=}'"
+ return
+ esac
+ esac
+
shquoted="'$shquoted'"
esac
}
diff -r b0eb8a486782 -r bee8ca14a178 regress/tools/files/logging-test.sh
--- a/regress/tools/files/logging-test.sh Wed May 22 20:01:17 2019 +0000
+++ b/regress/tools/files/logging-test.sh Wed May 22 20:47:05 2019 +0000
@@ -1,5 +1,5 @@
#! /bin/sh
-# $NetBSD: logging-test.sh,v 1.6 2019/03/24 11:29:19 rillig Exp $
+# $NetBSD: logging-test.sh,v 1.7 2019/05/22 20:47:05 rillig Exp $
# Up to March 2019, the command logging for the wrapped tools didn't properly
# quote the command line arguments. This meant the logging did not reflect
@@ -152,7 +152,7 @@
-DB=\"a\ b\"
assert_log <<'EOF'
-[*] WRKDIR/.tools/bin/for-loop '-DSD="a b"' '-DSS='\''a b'\''' '-DDD="a b"' '-DB="a b"'
-<.> set args '-DSD="a b"' '-DSS='\''a b'\''' '-DDD="a b"' '-DB="a b"'; shift; printf '%s' "$0"; for arg in "$@"; do printf ' <%s>' "$arg"; done; printf '\n'
+[*] WRKDIR/.tools/bin/for-loop -DSD='"a b"' -DSS=''\''a b'\''' -DDD='"a b"' -DB='"a b"'
+<.> set args -DSD='"a b"' -DSS=''\''a b'\''' -DDD='"a b"' -DB='"a b"'; shift; printf '%s' "$0"; for arg in "$@"; do printf ' <%s>' "$arg"; done; printf '\n'
EOF
}
diff -r b0eb8a486782 -r bee8ca14a178 regress/tools/files/shquote-test.sh
--- a/regress/tools/files/shquote-test.sh Wed May 22 20:01:17 2019 +0000
+++ b/regress/tools/files/shquote-test.sh Wed May 22 20:47:05 2019 +0000
@@ -52,3 +52,12 @@
test_shquote '-n' becomes '-n'
test_shquote '\\\\\\\\' becomes \''\\\\\\\\'\'
test_shquote \"\$\'\;\<\\\` becomes \'\"\$\'\\\'\'\;\<\\\`\'
+
+# Move the single quote to the right of the equals sign, if possible.
+test_shquote '-DMACRO="value"' becomes "-DMACRO='\"value\"'"
+test_shquote '--prefix="/usr/local"' becomes "--prefix='\"/usr/local\"'"
+test_shquote '-assignment=first=second=""' becomes "-assignment='first=second=\"\"'"
+test_shquote '-assignment=first=second' becomes '-assignment=first=second'
+
+# If the left-hand side needs to be quoted as well, quote the whole string.
+test_shquote '"left"="right"' becomes "'\"left\"=\"right\"'"
Home |
Main Index |
Thread Index |
Old Index