summaryrefslogtreecommitdiff
path: root/mk/tools
diff options
context:
space:
mode:
authorrillig <rillig@pkgsrc.org>2019-03-24 11:29:19 +0000
committerrillig <rillig@pkgsrc.org>2019-03-24 11:29:19 +0000
commitde1c0cf419fc4db4d616f4e660304e8e9a7e246f (patch)
tree0aa85d2b1d3fac35ad5941c80b28d40fa8d52605 /mk/tools
parent353cc33f53c2437d199641bd96dfc929ca768a13 (diff)
downloadpkgsrc-de1c0cf419fc4db4d616f4e660304e8e9a7e246f.tar.gz
mk/tools: correctly quote arguments in the tool wrapper log
Before, the tool arguments were written to the log as plain strings. Now the arguments are properly quoted, which makes it possible to replay the commands by copying them from the .work.log file. This only affects tools that are shell builtins (echo, true, false), get additional arguments (mkdir -p) or define a custom TOOLS_SCRIPT (pkg-config, to set an environment variable; or autotools). Tools that are symlinked to the real tool are not affected. The calls to the compiler are already properly logged since cwrappers takes care of that. This commit therefore makes the log entries for the compilers and the other tools more similar.
Diffstat (limited to 'mk/tools')
-rw-r--r--mk/tools/create.mk19
-rw-r--r--mk/tools/shquote.sh27
2 files changed, 38 insertions, 8 deletions
diff --git a/mk/tools/create.mk b/mk/tools/create.mk
index db2974f1ed8..719bce97a34 100644
--- a/mk/tools/create.mk
+++ b/mk/tools/create.mk
@@ -1,4 +1,4 @@
-# $NetBSD: create.mk,v 1.10 2019/03/24 08:40:07 rillig Exp $
+# $NetBSD: create.mk,v 1.11 2019/03/24 11:29:19 rillig Exp $
#
# Copyright (c) 2005, 2006 The NetBSD Foundation, Inc.
# All rights reserved.
@@ -149,7 +149,7 @@ ${TOOLS_CMD.${_t_}}:
if ${TEST} -n ${TOOLS_SCRIPT.${_t_}:Q}""; then \
create=wrapper; \
script=${TOOLS_SCRIPT.${_t_}:Q}; \
- logprefix='"set args "$$@"; shift; "'; \
+ logprefix='"set args$$shquoted_args; shift; "'; \
logmain=${TOOLS_SCRIPT.${_t_}:Q:Q}; \
logsuffix=''; \
elif ${TEST} -n ${TOOLS_PATH.${_t_}:Q}""; then \
@@ -158,7 +158,7 @@ ${TOOLS_CMD.${_t_}}:
script=${TOOLS_SCRIPT_DFLT.${_t_}:Q}; \
logprefix=''; \
logmain=${TOOLS_PATH.${_t_}:Q:Q}\"\ \"${TOOLS_ARGS.${_t_}:Q:Q}; \
- logsuffix=' "$$*"'; \
+ logsuffix='$$shquoted_args'; \
else \
case ${TOOLS_PATH.${_t_}:Q}"" in \
/*) create=symlink ;; \
@@ -166,7 +166,7 @@ ${TOOLS_CMD.${_t_}}:
script=${TOOLS_SCRIPT_DFLT.${_t_}:Q}; \
logprefix=''; \
logmain=${TOOLS_PATH.${_t_}:Q:Q}\"\ \"; \
- logsuffix=' "$$*"'; \
+ logsuffix='$$shquoted_args'; \
esac; \
fi; \
else \
@@ -175,11 +175,14 @@ ${TOOLS_CMD.${_t_}}:
case "$$create" in \
wrapper) \
{ ${ECHO} '#!'${TOOLS_SHELL:Q}; \
+ ${ECHO} 'tools_wrapper_sed='${SED:Q:Q}; \
+ ${SED} -e '/^$$/d' -e '/^\#/d' ${PKGSRCDIR}/mk/tools/shquote.sh; \
${ECHO} 'wrapperlog="$${TOOLS_WRAPPER_LOG-'${_TOOLS_WRAP_LOG:Q}'}"'; \
- ${ECHO} '${ECHO} "[*] "'${.TARGET:Q}'" $$*" >> $$wrapperlog'; \
- ${ECHO} 'logprefix='$$logprefix; \
- ${ECHO} 'logmain='$$logmain; \
- ${ECHO} "${ECHO} '<.>' \"\$$logprefix\$$logmain\"$$logsuffix >> \$$wrapperlog"; \
+ ${ECHO} 'shquote_args "$$@"'; \
+ ${ECHO} '${ECHO} "[*] "'${.TARGET:Q}'"$$shquoted_args" >> $$wrapperlog'; \
+ ${ECHO} 'logprefix='$$logprefix; \
+ ${ECHO} 'logmain='$$logmain; \
+ ${ECHO} "${ECHO} '<.>' \"\$$logprefix\$$logmain$$logsuffix\" >> \$$wrapperlog"; \
${ECHO} "$$script"; \
} > ${.TARGET:Q}; \
${CHMOD} +x ${.TARGET:Q}; \
diff --git a/mk/tools/shquote.sh b/mk/tools/shquote.sh
new file mode 100644
index 00000000000..39755c4deb9
--- /dev/null
+++ b/mk/tools/shquote.sh
@@ -0,0 +1,27 @@
+#! /bin/sh
+# $NetBSD: shquote.sh,v 1.1 2019/03/24 11:29:19 rillig Exp $
+
+# Quotes all shell meta characters from $1 and writes the result to $shquoted.
+shquote()
+{
+ shquoted=$1
+ case $shquoted in
+ *\'*)
+ shquoted=`$tools_wrapper_sed -e 's,'\'','\''\\\\'\'''\'',g' <<EOF
+$shquoted
+EOF`
+ esac
+
+ case $shquoted in
+ *[!!%+,\-./0-9:=@A-Z_a-z]*|'')
+ shquoted="'$shquoted'"
+ esac
+}
+
+shquote_args() {
+ shquoted_args=''
+ for arg in "$@"; do
+ shquote "$arg"
+ shquoted_args="$shquoted_args $shquoted"
+ done
+}