diff --git a/bin/list_schemes.sh b/bin/list_schemes.sh index 06feda1..e10d20b 100644 --- a/bin/list_schemes.sh +++ b/bin/list_schemes.sh @@ -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 @@ -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" diff --git a/compiler/xcode.vim b/compiler/xcode.vim new file mode 100644 index 0000000..350fb5b --- /dev/null +++ b/compiler/xcode.vim @@ -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 +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 diff --git a/plugin/xcode.vim b/plugin/xcode.vim index 0fbf962..c043580 100644 --- a/plugin/xcode.vim +++ b/plugin/xcode.vim @@ -1,6 +1,9 @@ command! -nargs=? -complete=customlist,s:build_actions \ Xbuild call build("") +command! -bang -bar -nargs=? -complete=customlist,s:compiler_actions + \ Xcompiler call compiler(0, "") + command! -nargs=? -complete=customlist,s:list_simulators \ Xrun call run("") @@ -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) @@ -164,6 +191,10 @@ 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 @@ -171,6 +202,8 @@ function! s:base_command(actions, simulator) \ . s:build_target_with_scheme() \ . ' ' \ . s:destination(a:simulator) + \ . ' ' + \ . get(g:, xcargs, '') endfunction function! s:run_command(simulator) @@ -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 @@ -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 ''