···5151 local varName="$2" # name of list variable to add to
5252 local separator="$3" # character used to separate elements of list
5353 local value="$4" # one value, or multiple values separated by `separator`, to add to list
5454- if test -n "$value"; then
5454+5555+ # Disable file globbing, since bash will otherwise try to find
5656+ # filenames matching the the value to be prefixed/suffixed if
5757+ # it contains characters considered wildcards, such as `?` and
5858+ # `*`. We want the value as is, except we also want to split
5959+ # it on on the separator; hence we can't quote it.
6060+ local reenableGlob=0
6161+ if [[ ! -o noglob ]]; then
6262+ reenableGlob=1
6363+ fi
6464+ set -o noglob
6565+6666+ if [[ -n "$value" ]]; then
5567 local old_ifs=$IFS
5668 IFS=$separator
5769···8597 } >> "$wrapper"
8698 done
8799 IFS=$old_ifs
100100+ fi
101101+102102+ if (( reenableGlob )); then
103103+ set +o noglob
88104 fi
89105 }
90106
+3
pkgs/test/make-wrapper/default.nix
···6464 (mkWrapperBinary { name = "test-run-and-set"; args = [ "--run" "export VAR=foo" "--set" "VAR" "bar" ]; })
6565 (mkWrapperBinary { name = "test-args"; args = [ "--add-flags" "abc" ]; wrapped = wrappedBinaryArgs; })
6666 (mkWrapperBinary { name = "test-prefix"; args = [ "--prefix" "VAR" ":" "abc" ]; })
6767+ (mkWrapperBinary { name = "test-prefix-noglob"; args = [ "--prefix" "VAR" ":" "./*" ]; })
6768 (mkWrapperBinary { name = "test-suffix"; args = [ "--suffix" "VAR" ":" "abc" ]; })
6869 (mkWrapperBinary { name = "test-prefix-and-suffix"; args = [ "--prefix" "VAR" ":" "foo" "--suffix" "VAR" ":" "bar" ]; })
6970 (mkWrapperBinary { name = "test-prefix-multi"; args = [ "--prefix" "VAR" ":" "abc:foo:foo" ]; })
···112113 # Only append the value once when given multiple times in a parameter
113114 # to makeWrapper
114115 + mkTest "test-prefix" "VAR=abc"
116116+ # --prefix doesn't expand globs
117117+ + mkTest "VAR=f?oo test-prefix-noglob" "VAR=./*:f?oo"
115118116119117120 # --suffix works