makeWrapper: Don't glob in prefix/suffix
Disable file globbing in --prefix/--suffix, since bash will otherwise try to find filenames matching the the value to be prefixed/suffixed if it contains characters considered wildcards, such as `?` and `*`. We want the value as is, except we also want to split it on on the separator; hence we can't quote it.
This commit is contained in:
parent
2ea430e624
commit
183147a037
@ -51,7 +51,19 @@ makeWrapper() {
|
|||||||
local varName="$2" # name of list variable to add to
|
local varName="$2" # name of list variable to add to
|
||||||
local separator="$3" # character used to separate elements of list
|
local separator="$3" # character used to separate elements of list
|
||||||
local value="$4" # one value, or multiple values separated by `separator`, to add to list
|
local value="$4" # one value, or multiple values separated by `separator`, to add to list
|
||||||
if test -n "$value"; then
|
|
||||||
|
# Disable file globbing, since bash will otherwise try to find
|
||||||
|
# filenames matching the the value to be prefixed/suffixed if
|
||||||
|
# it contains characters considered wildcards, such as `?` and
|
||||||
|
# `*`. We want the value as is, except we also want to split
|
||||||
|
# it on on the separator; hence we can't quote it.
|
||||||
|
local reenableGlob=0
|
||||||
|
if [[ ! -o noglob ]]; then
|
||||||
|
reenableGlob=1
|
||||||
|
fi
|
||||||
|
set -o noglob
|
||||||
|
|
||||||
|
if [[ -n "$value" ]]; then
|
||||||
local old_ifs=$IFS
|
local old_ifs=$IFS
|
||||||
IFS=$separator
|
IFS=$separator
|
||||||
|
|
||||||
@ -86,6 +98,10 @@ makeWrapper() {
|
|||||||
done
|
done
|
||||||
IFS=$old_ifs
|
IFS=$old_ifs
|
||||||
fi
|
fi
|
||||||
|
|
||||||
|
if (( reenableGlob )); then
|
||||||
|
set +o noglob
|
||||||
|
fi
|
||||||
}
|
}
|
||||||
|
|
||||||
mkdir -p "$(dirname "$wrapper")"
|
mkdir -p "$(dirname "$wrapper")"
|
||||||
|
@ -64,6 +64,7 @@ runCommand "make-wrapper-test"
|
|||||||
(mkWrapperBinary { name = "test-run-and-set"; args = [ "--run" "export VAR=foo" "--set" "VAR" "bar" ]; })
|
(mkWrapperBinary { name = "test-run-and-set"; args = [ "--run" "export VAR=foo" "--set" "VAR" "bar" ]; })
|
||||||
(mkWrapperBinary { name = "test-args"; args = [ "--add-flags" "abc" ]; wrapped = wrappedBinaryArgs; })
|
(mkWrapperBinary { name = "test-args"; args = [ "--add-flags" "abc" ]; wrapped = wrappedBinaryArgs; })
|
||||||
(mkWrapperBinary { name = "test-prefix"; args = [ "--prefix" "VAR" ":" "abc" ]; })
|
(mkWrapperBinary { name = "test-prefix"; args = [ "--prefix" "VAR" ":" "abc" ]; })
|
||||||
|
(mkWrapperBinary { name = "test-prefix-noglob"; args = [ "--prefix" "VAR" ":" "./*" ]; })
|
||||||
(mkWrapperBinary { name = "test-suffix"; args = [ "--suffix" "VAR" ":" "abc" ]; })
|
(mkWrapperBinary { name = "test-suffix"; args = [ "--suffix" "VAR" ":" "abc" ]; })
|
||||||
(mkWrapperBinary { name = "test-prefix-and-suffix"; args = [ "--prefix" "VAR" ":" "foo" "--suffix" "VAR" ":" "bar" ]; })
|
(mkWrapperBinary { name = "test-prefix-and-suffix"; args = [ "--prefix" "VAR" ":" "foo" "--suffix" "VAR" ":" "bar" ]; })
|
||||||
(mkWrapperBinary { name = "test-prefix-multi"; args = [ "--prefix" "VAR" ":" "abc:foo:foo" ]; })
|
(mkWrapperBinary { name = "test-prefix-multi"; args = [ "--prefix" "VAR" ":" "abc:foo:foo" ]; })
|
||||||
@ -112,6 +113,8 @@ runCommand "make-wrapper-test"
|
|||||||
# Only append the value once when given multiple times in a parameter
|
# Only append the value once when given multiple times in a parameter
|
||||||
# to makeWrapper
|
# to makeWrapper
|
||||||
+ mkTest "test-prefix" "VAR=abc"
|
+ mkTest "test-prefix" "VAR=abc"
|
||||||
|
# --prefix doesn't expand globs
|
||||||
|
+ mkTest "VAR=f?oo test-prefix-noglob" "VAR=./*:f?oo"
|
||||||
|
|
||||||
|
|
||||||
# --suffix works
|
# --suffix works
|
||||||
|
Loading…
Reference in New Issue
Block a user