1
0
Fork 0
mirror of git://git.code.sf.net/p/zsh/code synced 2025-09-10 00:31:07 +02:00

35957: fix _make-expandVars()

Also use variables set in the command line and environment.
This commit is contained in:
Jun-ichi Takimoto 2015-08-02 20:51:06 +09:00
parent 3d9a8073c2
commit f4723a0c08
2 changed files with 77 additions and 60 deletions

View file

@ -1,3 +1,8 @@
2015-08-01 Jun-ichi Takimoto <takimoto-j@kba.biglobe.ne.jp>
* 35957: Completion/Unix/Command/_make: fix _make-expandVars(),
and use variables set in the command line and environment.
2015-07-31 Oliver Kiddle <opk@zsh.org> 2015-07-31 Oliver Kiddle <opk@zsh.org>
* 35963: Src/Modules/system.c: simplify condition found by * 35963: Src/Modules/system.c: simplify condition found by

View file

@ -4,58 +4,68 @@
# are used in those targets and their dependencies. # are used in those targets and their dependencies.
_make-expandVars() { _make-expandVars() {
local open close var val front ret tmp=$1 local open close var val front='' rest=$1
front=${tmp%%\$*} while [[ $rest == (#b)[^$]#($)* ]]; do
case $tmp in front=$front${rest[1,$mbegin[1]-1]}
(\(*) # Variable of the form $(foobar) rest=${rest[$mbegin[1],-1]}
open='('
close=')'
;;
({*) # ${foobar} case $rest[2] in
open='{' ($) # '$$'. may not appear in target and variable's value
close='}' front=$front\$\$
;; rest=${rest[3,-1]}
continue
;;
(\() # Variable of the form $(foobar)
open='('
close=')'
;;
({) # ${foobar}
open='{'
close='}'
;;
([[:alpha:]]) # $foobar. This is exactly $(f)oobar.
open=''
close=''
var=$rest[2]
;;
(*) # bad parameter name
print -- $front$rest
return 1
;;
esac
([[:alpha:]]*) # $foobar. This is exactly $(f)oobar. if [[ -n $open ]]; then
open='' if [[ $rest == \$$open(#b)([[:alnum:]_]##)(#B)$close* ]]; then
close='' var=$match
var=${(s::)var[1]} else # unmatched () or {}, or bad parameter name
;; print -- $front$rest
return 1
fi
fi
(\$*) # Escaped $. val=''
print -- "${front}\$$(_make-expandVars ${tmp#\$})" if [[ -n ${VAR_ARGS[(i)$var]} ]]; then
return val=${VAR_ARGS[$var]}
;; else
if [[ -n $opt_args[(I)(-e|--environment-overrides)] ]]; then
if [[ $parameters[$var] == scalar-export* ]]; then
val=${(P)var}
elif [[ -n ${VARIABLES[(i)$var]} ]]; then
val=${VARIABLES[$var]}
fi
else
if [[ -n ${VARIABLES[(i)$var]} ]]; then
val=${VARIABLES[$var]}
elif [[ $parameters[$var] == scalar-export* ]]; then
val=${(P)var}
fi
fi
fi
rest=${rest//\$$open$var$close/$val}
done
(*) # Nothing left to substitute. print -- ${front}${rest}
print -- $tmp
return
;;
esac
if [[ -n $open ]]
then
var=${tmp#$open}
var=${var%%$close*}
fi
case $var in
([[:alnum:]_]#)
val=${VARIABLES[$var]}
ret=${ret//\$$open$var$close/$val}
;;
(*)
# Improper variable name. No replacement.
# I'm not sure if this is desired behavior.
front+="\$$open$var$close"
ret=${ret/\$$open$var$close/}
;;
esac
print -- "${front}$(_make-expandVars ${ret})"
} }
_make-parseMakefile () { _make-parseMakefile () {
@ -84,16 +94,9 @@ _make-parseMakefile () {
# TARGET: dependencies # TARGET: dependencies
# TARGET1 TARGET2 TARGET3: dependencies # TARGET1 TARGET2 TARGET3: dependencies
([[:alnum:]][^$TAB:=]#:[^=]*) ([[*?[:alnum:]$][^$TAB:=%]#:[^=]*)
input=$(_make-expandVars $input) target=$(_make-expandVars ${input%%:*})
target=${input%%:*} TARGETS+=( ${(z)target} )
dep=${input#*:}
dep=${(z)dep}
dep="$dep"
for tmp in ${(z)target}
do
TARGETS[$tmp]=$dep
done
;; ;;
# Include another makefile # Include another makefile
@ -150,9 +153,18 @@ _make() {
local prev="$words[CURRENT-1]" file expl tmp is_gnu dir incl match local prev="$words[CURRENT-1]" file expl tmp is_gnu dir incl match
local context state state_descr line local context state state_descr line
local -a option_specs local -a option_specs
local -A TARGETS VARIABLES opt_args local -A VARIABLES VAR_ARGS opt_args
local -aU TARGETS keys
local ret=1 local ret=1
# VAR=VAL on the current command line
for tmp in $words; do
if [[ $tmp == (#b)([[:alnum:]_]##)=(*) ]]; then
VAR_ARGS[${tmp[$mbegin[1],$mend[1]]}]=${(e)tmp[$mbegin[2],$mend[2]]}
fi
done
keys=( ${(k)VAR_ARGS} ) # to be used in 'compadd -F keys'
_pick_variant -r is_gnu gnu=GNU unix -v -f _pick_variant -r is_gnu gnu=GNU unix -v -f
if [[ $is_gnu == gnu ]] if [[ $is_gnu == gnu ]]
@ -275,9 +287,9 @@ _make() {
while _tags while _tags
do do
_requested targets expl 'make targets' \ _requested targets expl 'make targets' \
compadd -- ${(k)TARGETS} && ret=0 compadd -Q -- $TARGETS && ret=0
_requested variables expl 'make variables' \ _requested variables expl 'make variables' \
compadd -S '=' -- ${(k)VARIABLES} && ret=0 compadd -S '=' -F keys -- ${(k)VARIABLES} && ret=0
done done
fi fi
esac esac