shift words array before passing from _cmake to build tool
* this fixes #581
This commit is contained in:
parent
d3a273cedf
commit
2527ac9c03
26
src/_cmake
26
src/_cmake
|
@ -78,9 +78,15 @@ local cmake_build_options;cmake_build_options=(
|
||||||
|
|
||||||
# ------------------------
|
# ------------------------
|
||||||
# _cmake_generator_options
|
# _cmake_generator_options
|
||||||
|
#
|
||||||
|
# arguments are $1: build working directory (top level Makefile or build.ninja file)
|
||||||
|
# $2: position of "--" in the command line
|
||||||
# ------------------------
|
# ------------------------
|
||||||
(( $+functions[_cmake_generator_options] )) ||
|
(( $+functions[_cmake_generator_options] )) ||
|
||||||
_cmake_generator_options() {
|
_cmake_generator_options() {
|
||||||
|
# pass only the part of the command line starting at "--" to the completion
|
||||||
|
shift (( $2 - 1 )) words
|
||||||
|
(( CURRENT = $CURRENT + 1 - $2 ))
|
||||||
if [ -f $1/Makefile ]
|
if [ -f $1/Makefile ]
|
||||||
then
|
then
|
||||||
$_comps[make]
|
$_comps[make]
|
||||||
|
@ -116,6 +122,10 @@ _cmake_targets() {
|
||||||
_describe 'build targets' targets
|
_describe 'build targets' targets
|
||||||
}
|
}
|
||||||
|
|
||||||
|
_cmake_suggest_builddirs() {
|
||||||
|
_alternative ':current directory:(.)' 'directory::_directories' && return 0
|
||||||
|
}
|
||||||
|
|
||||||
_cmake_on_build() {
|
_cmake_on_build() {
|
||||||
local build_extras;build_extras=(
|
local build_extras;build_extras=(
|
||||||
'--[Native build tool options]'
|
'--[Native build tool options]'
|
||||||
|
@ -130,14 +140,14 @@ _cmake_on_build() {
|
||||||
(( i++ ))
|
(( i++ ))
|
||||||
done
|
done
|
||||||
inbuild=false
|
inbuild=false
|
||||||
nativemode=false
|
dashdashposition=-1
|
||||||
for ((i = (($CURRENT - 1)); i > 1 ; i--)); do
|
for ((i = (($CURRENT - 1)); i > 1 ; i--)); do
|
||||||
if [[ $words[$i] == --build ]] ; then
|
if [[ $words[$i] == --build ]] ; then
|
||||||
inbuild=true
|
inbuild=true
|
||||||
buildat=$i
|
buildat=$i
|
||||||
(( difference = $CURRENT - $i ))
|
(( difference = $CURRENT - $i ))
|
||||||
elif [[ $words[$i] == -- ]] ; then
|
elif [[ $words[$i] == -- ]] ; then
|
||||||
nativemode=true
|
dashdashposition=$i
|
||||||
fi
|
fi
|
||||||
done
|
done
|
||||||
# check if build mode has been left
|
# check if build mode has been left
|
||||||
|
@ -149,18 +159,16 @@ _cmake_on_build() {
|
||||||
if [[ $words[(($i - 1))] == --config ]] ; then continue ; fi
|
if [[ $words[(($i - 1))] == --config ]] ; then continue ; fi
|
||||||
outofbuild=true
|
outofbuild=true
|
||||||
done
|
done
|
||||||
if [ "$nativemode" = true ] ; then
|
if (( $dashdashposition > 0 )) ; then
|
||||||
_cmake_generator_options $words[(($buildat + 1))] && return 0
|
_cmake_generator_options $words[(($buildat + 1))] $dashdashposition && return 0
|
||||||
fi
|
fi
|
||||||
if [ "$inbuild" = false ] ; then
|
if [[ "$inbuild" == false || "$difference" -eq 1 ]] ; then
|
||||||
|
# either there is no --build or completing the directory after --build
|
||||||
_arguments -C -s \
|
_arguments -C -s \
|
||||||
- build_opts \
|
- build_opts \
|
||||||
"$cmake_build_options[@]" \
|
"$cmake_build_options[@]" \
|
||||||
- build_cmds \
|
- build_cmds \
|
||||||
"$cmake_suggest_build[@]" && return 0
|
"$cmake_suggest_build[@]" && return 0
|
||||||
elif [ $difference -eq 1 ] ; then
|
|
||||||
# directly after --build comes the build directory
|
|
||||||
_alternative ':current directory:(.)' 'directory::_directories' && return 0
|
|
||||||
elif [[ $words[(($CURRENT - 1))] == --target ]] ; then
|
elif [[ $words[(($CURRENT - 1))] == --target ]] ; then
|
||||||
# after --build <dir> --target, suggest targets
|
# after --build <dir> --target, suggest targets
|
||||||
_cmake_targets $words[(($buildat + 1))] && return 0
|
_cmake_targets $words[(($buildat + 1))] && return 0
|
||||||
|
@ -444,7 +452,7 @@ _cmake_command() {
|
||||||
}
|
}
|
||||||
|
|
||||||
local cmake_suggest_build;cmake_suggest_build=(
|
local cmake_suggest_build;cmake_suggest_build=(
|
||||||
'--build[build]'
|
'--build[build]:build dir:_cmake_suggest_builddirs'
|
||||||
)
|
)
|
||||||
|
|
||||||
if [ $CURRENT -eq 2 ] ; then
|
if [ $CURRENT -eq 2 ] ; then
|
||||||
|
|
Loading…
Reference in New Issue