Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

WIP: Add more ways to filter schemes #90

Open
wants to merge 12 commits into
base: main
Choose a base branch
from
36 changes: 29 additions & 7 deletions bin/list_schemes.sh
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,33 @@

set -o pipefail

while getopts "f:t:i:" opt; do
get_schemes() {
xcrun xcodebuild -list "$1" "$2" 2>/dev/null \
| awk '/Schemes:/,0' \
| tail -n +2 \
| sed -e "s/^[[:space:]]*//"
}

get_sources_ignore() {
if [ ! -e "$1" ]; then
return
fi
case "$1" in
*xcworkspace) type='-workspace';;
*xcodeproj) type='-project';;
*) return;;
esac
echo "^($(get_schemes "$type" "$1" | tr '\n' '|' | sed 's/|*$//'))$"
}

ignore_sources_pattern=""

while getopts "f:t:i:e:" opt; do
case $opt in
f) target_type_flag="$OPTARG";;
t) target="$OPTARG";;
i) ignore_pattern="$OPTARG";;
e) ignore_sources_pattern="$ignore_sources_pattern|$(get_sources_ignore "$OPTARG")";;
\?)
echo "Invalid option: -$OPTARG" >&2
exit 1
Expand All @@ -18,12 +40,12 @@ while getopts "f:t:i:" opt; do
esac
done

schemes="$(
xcrun xcodebuild -list "$target_type_flag" "$target" 2>/dev/null \
| awk '/Schemes:/,0' \
| tail -n +2 \
| sed -e "s/^[[:space:]]*//"
)"
schemes="$(get_schemes "$target_type_flag" "$target")"

if [ -n "$ignore_sources_pattern" ]; then
ignore_sources_pattern="/$(echo "$ignore_sources_pattern" | sed 's/^|*//')/d"
schemes="$(echo "$schemes" | sed -E "$ignore_sources_pattern")"
fi

if [ -z "$ignore_pattern" ]; then
echo "$schemes"
Expand Down
38 changes: 38 additions & 0 deletions compiler/xcode.vim
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
if exists('current_compiler')
finish
endif
let current_compiler = 'xcode'

" vint: -ProhibitAbbreviationOption
let s:save_cpo = &cpo
set cpo&vim
" vint: +ProhibitAbbreviationOption

if exists(':CompilerSet') != 2
command -nargs=* CompilerSet setlocal <args>
endif

if !exists('g:xcode_compiler_cmd') || g:xcode_compiler_cmd ==? ''
Xcompiler
endif

call setbufvar(bufnr('%'), '&makeprg', g:xcode_compiler_cmd)

CompilerSet errorformat=
\%f:%l:%c:\ %trror:\ %m,
\%f:%l:%c:\ %tarning:\ %m,
\%trror:\ %m\ at\ %l:%c\ in\ %f.,
\[x]\ %trror:\ %m\ at\ %l:%c\ in\ %f.,
\❌\ %trror:\ %m\ at\ %l:%c\ in\ %f.,
\[!]\ %tarning:\ %m\ at\ %l:%c\ in\ %f.,
\⚠️\ %tarning:\ %m\ at\ %l:%c\ in\ %f.,
\%E[x]\ %f:%l:%c:\ %m,
\%E❌\ %f:%l:%c:\ %m,
\%W[!]\ %f:%l:%c:\ %m,
\%W⚠️\ %f:%l:%c:\ %m,
\%E%>\ \ %[a-zA-Z]%#\\,\ failed\ \-\ %m,%Z\ \ %f:%l

" vint: -ProhibitAbbreviationOption
let &cpo = s:save_cpo
unlet s:save_cpo
" vint: +ProhibitAbbreviationOption
41 changes: 40 additions & 1 deletion plugin/xcode.vim
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
command! -nargs=? -complete=customlist,s:build_actions
\ Xbuild call <sid>build("<args>")

command! -bang -bar -nargs=? -complete=customlist,s:compiler_actions
\ Xcompiler call <sid>compiler(<bang>0, "<args>")

command! -nargs=? -complete=customlist,s:list_simulators
\ Xrun call <sid>run("<args>")

Expand Down Expand Up @@ -62,6 +65,30 @@ function! s:build_actions(a, l, f)
return ['build', 'analyze', 'archive', 'test', 'installsrc', 'install', 'clean']
endfunction

function! s:compiler(bang, actions) abort
if s:assert_project()
let simulator = s:simulator()
let run_cmd = ''

if empty(a:actions)
let actions = 'build'
elseif a:actions == 'run'
let actions = 'build'
let run_cmd = ' && '.s:run_command(simulator)
else
let actions = a:actions
endif

let cmd = s:base_command(actions, simulator) . s:xcpretty()
let g:xcode_compiler_cmd = cmd . run_cmd
execute 'compiler'.(a:bang ? '!' : '').' xcode'
endif
endfunction

function! s:compiler_actions(a, l, f)
return s:build_actions(a:a, a:l, a:f) + ['run']
endfunction

function! s:run(simulator)
if s:assert_project()
if empty(a:simulator)
Expand Down Expand Up @@ -164,13 +191,19 @@ function! s:workspace_exists()
endfunction

function! s:base_command(actions, simulator)
let xcargs = 'xcode_additional_xcargs'
if a:actions ==# 'test'
let xcargs .= '_test'
endif
return 'set -o pipefail; '
\ . 'NSUnbufferedIO=YES xcrun xcodebuild '
\ . a:actions
\ . ' '
\ . s:build_target_with_scheme()
\ . ' '
\ . s:destination(a:simulator)
\ . ' '
\ . get(g:, xcargs, '')
endfunction

function! s:run_command(simulator)
Expand Down Expand Up @@ -297,6 +330,12 @@ function! s:get_available_schemes()
let scheme_command .= ' ' . '-i' . s:cli_args(g:xcode_scheme_ignore_pattern)
endif

if exists('g:xcode_scheme_source_ignore')
for item in g:xcode_scheme_source_ignore
let scheme_command .= ' ' . '-e' . s:cli_args(item)
endfor
endif

let s:available_schemes = systemlist(scheme_command)
endfunction

Expand Down Expand Up @@ -358,7 +397,7 @@ function! s:runner_template()
endfunction

function! s:xcpretty()
if executable('xcpretty')
if executable('xcpretty') && !get(g:, 'xcode_disable_xcpretty', 0)
return ' | xcpretty ' . s:xcpretty_flags()
else
return ''
Expand Down