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

Fix issue where device builds would be installed in the simulator #71

Closed
wants to merge 3 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion bin/run_ios_app
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#!/usr/bin/env sh

build_path=$(xcodebuild -showBuildSettings "$@" 2>/dev/null | egrep "\bBUILD_DIR\b" | sed -E "s/[[:space:]]+BUILD_DIR = //")
build_path=$(xcodebuild -showBuildSettings "$@" 2>/dev/null | sed -nE "s/^[[:space:]]+CONFIGURATION_BUILD_DIR = //p")
app_path=$(find "$build_path" -iname "*.app" | head -n1)
app_id=$(defaults read "$app_path/Info" "CFBundleIdentifier")
uuid=$(xcrun simctl list devices | grep "$SIMULATOR" | head -n1 | grep -E "[0-9A-F-]{8,}" -o)
Expand Down
15 changes: 14 additions & 1 deletion doc/xcode.txt
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ CONTENTS *xcode-Contents*
3.5 .............................. |xcode_project_file|
3.6 .............................. |xcode_default_scheme|
3.7 .............................. |xcode_default_simulator|
3.8 .............................. |xcode_default_configuration|

==============================================================================
ABOUT (1) *xcode-About*
Expand Down Expand Up @@ -287,7 +288,7 @@ If not set, `xcode.vim` will default to the first scheme listed as a result of

------------------------------------------------------------------------------
*xcode_default_simulator*
3.6 g:xcode_default_simulator~
3.7 g:xcode_default_simulator~

The default simulator to use for building/testing/running.

Expand All @@ -296,5 +297,17 @@ time you build/run/test your iOS app, you can set this variable to do so.

If not set, `xcode.vim` will default to `"iPhone 6s"`

------------------------------------------------------------------------------
*xcode_default_configuration*
3.8 g:xcode_default_configuration~

The default build configuration to use for building/testing/running.

If you'd like to make sure that you use a specific build configuration by
default every time you build/run/test your iOS app, you can set this variable
to do so.

If not set, `xcode.vim` will default to `"Debug"`

==============================================================================
vim:tw=78:ts=8:ft=help:norl:
39 changes: 33 additions & 6 deletions plugin/xcode.vim
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ let s:default_runner_command = '! {cmd}'
let s:default_xcpretty_flags = '--color'
let s:default_xcpretty_testing_flags = ''
let s:default_simulator = 'iPhone 6s'
let s:default_configuration = 'Debug'

let s:plugin_path = expand('<sfile>:p:h:h')

Expand Down Expand Up @@ -120,6 +121,10 @@ function! s:set_simulator(simulator)
let s:chosen_simulator = a:'simulator
endfunction

function! s:set_configuration(configuration)
let s:chosen_configuration = a:configuration
endfunction

function! s:execute_command(cmd)
let run_cmd = substitute(s:runner_template(), '{cmd}', a:cmd, 'g')
execute run_cmd
Expand All @@ -139,7 +144,7 @@ function! s:base_command(actions, simulator)
\ . 'NSUnbufferedIO=YES xcrun xcodebuild '
\ . a:actions
\ . ' '
\ . s:build_target_with_scheme()
\ . s:build_target_with_options()
\ . ' '
\ . s:destination(a:simulator)
endfunction
Expand All @@ -156,15 +161,17 @@ function! s:iphone_simulator_run_command(simulator)
return 'SIMULATOR="' . a:simulator . '" '
\ . s:bin_script('run_ios_app')
\ . ' '
\ . s:build_target_with_scheme()
\ . s:build_target_with_options()
\ . ' '
\ . s:iphone_simulator_sdk()
endfunction

function! s:mac_run_command()
return s:bin_script('run_mac_app') . ' ' . s:build_target_with_scheme()
return s:bin_script('run_mac_app') . ' ' . s:build_target_with_options()
endfunction

function! s:build_target_with_scheme()
return s:build_target() . ' ' . s:scheme()
function! s:build_target_with_options()
return s:build_target() . ' ' . s:scheme() . ' ' . s:configuration()
endfunction

function! s:build_target()
Expand Down Expand Up @@ -243,6 +250,22 @@ function! s:schemes()
return s:available_schemes
endfunction

function! s:configuration()
return '-configuration' . s:cli_args(s:configuration_name())
endfunction

function! s:configuration_name()
if !exists('s:chosen_configuration')
if exists('g:xcode_default_configuration')
let s:chosen_configuration = g:xcode_default_configuration
else
let s:chosen_configuration = s:default_configuration
endif
endif

return s:chosen_configuration
endfunction

function! s:simulator()
if !exists('s:chosen_simulator')
if exists('g:xcode_default_simulator')
Expand All @@ -269,7 +292,7 @@ endfunction

function! s:use_simulator()
if !exists('s:use_simulator')
let platform = system('source ' . s:bin_script('project_platform.sh') . ' ' . s:build_target_with_scheme())
let platform = system('source ' . s:bin_script('project_platform.sh') . ' ' . s:build_target_with_options())
let s:use_simulator = platform ==# "ios"
endif

Expand All @@ -288,6 +311,10 @@ function! s:iphone_simulator_destination(simulator)
return '-destination "platform=iOS Simulator,name=' . a:simulator . '"'
endfunction

function! s:iphone_simulator_sdk()
return '-sdk iphonesimulator'
endfunction

function! s:osx_destination()
return '-destination "platform=OS X"'
endfunction
Expand Down