sim_launcher 0.4.8.pre1 → 0.4.9

Sign up to get free protection for your applications and to get access to all the features.
data/bin/sim_launcher CHANGED
@@ -17,7 +17,7 @@ shared_simulator = SimLauncher::Simulator.new
17
17
 
18
18
  get '/' do
19
19
  <<EOS
20
- <h1>SimLauncher is up and running</h1>
20
+ <h1>SimLauncher is up and running...</h1>
21
21
  <a href="/showsdks">Here's a list of sdks that SimLauncher has detected</a>
22
22
  EOS
23
23
  end
@@ -30,22 +30,35 @@ end
30
30
 
31
31
  get '/launch_ipad_app' do
32
32
  app_path = params[:app_path]
33
- raise 'no app_path provided' if app_path.nil?
34
-
33
+ app_name = params[:app_name]
34
+
35
35
  sdk = params[:sdk]
36
36
  restart_requested = ("true" == params[:restart])
37
37
 
38
38
  shared_simulator.quit_simulator if restart_requested
39
- shared_simulator.launch_ipad_app( app_path, sdk )
39
+
40
+ if (!app_name.nil? && !app_name.empty?)
41
+ shared_simulator.launch_ipad_app_with_name( app_name, sdk )
42
+ else
43
+ raise 'no app_path provided' if app_path.nil?
44
+ shared_simulator.launch_ipad_app( app_path, sdk )
45
+ end
46
+
40
47
  end
41
48
 
42
49
  get '/launch_iphone_app' do
43
50
  app_path = params[:app_path]
44
- raise 'no app_path provided' if app_path.nil?
51
+ app_name = params[:app_name]
45
52
 
46
53
  sdk = params[:sdk]
47
54
  restart_requested = ("true" == params[:restart])
48
55
 
49
56
  shared_simulator.quit_simulator if restart_requested
50
- shared_simulator.launch_iphone_app( app_path, sdk )
57
+
58
+ if (!app_name.nil? && !app_name.empty?)
59
+ shared_simulator.launch_iphone_app_with_name( app_name, sdk )
60
+ else
61
+ raise 'no app_path provided' if app_path.nil?
62
+ shared_simulator.launch_iphone_app( app_path, sdk )
63
+ end
51
64
  end
data/lib/sim_launcher.rb CHANGED
@@ -4,6 +4,10 @@ require 'sim_launcher/simulator'
4
4
  require 'sim_launcher/sdk_detector'
5
5
 
6
6
  module SimLauncher
7
+
8
+ DERIVED_DATA = File.expand_path("~/Library/Developer/Xcode/DerivedData")
9
+ DEFAULT_DERIVED_DATA_INFO = File.expand_path("#{DERIVED_DATA}/*/info.plist")
10
+
7
11
  def self.check_app_path( app_path )
8
12
  unless File.exists?( app_path )
9
13
  return "The specified app path doesn't seem to exist: #{app_path}"
@@ -24,4 +28,81 @@ module SimLauncher
24
28
 
25
29
  nil
26
30
  end
31
+
32
+ def self.derived_data_dir_for_project_name(project_name)
33
+
34
+ build_dirs = Dir.glob("#{DERIVED_DATA}/*").find_all do |xc_proj|
35
+ File.basename(xc_proj).start_with?(project_name)
36
+ end
37
+
38
+ if (build_dirs.count == 0 && !project_name.empty?)
39
+ # check for directory named "workspace-{deriveddirectoryrandomcharacters}"
40
+ build_dirs = Dir.glob("#{DERIVED_DATA}/*").find_all do |xc_proj|
41
+ File.basename(xc_proj).downcase.start_with?(project_name)
42
+ end
43
+ end
44
+
45
+ puts build_dirs
46
+
47
+ if (build_dirs.count == 0)
48
+ msg = ["Unable to find your built app."]
49
+ msg << "This means that sim_launcher can't automatically launch the build for the #{project_name}."
50
+ msg << "Searched in Xcode 4.x default: #{DERIVED_DATA}"
51
+ raise msg.join("\n")
52
+
53
+ elsif (build_dirs.count > 1)
54
+ msg = ["Unable to auto detect bundle."]
55
+ msg << "You have several projects with the same name: #{project_name} in #{DERIVED_DATA}:\n"
56
+ msg << build_dirs.join("\n")
57
+
58
+ msg << "\n\nThis means that sim_launcher can't automatically launch iOS simulator."
59
+ msg << "Searched in Xcode 4.x default: #{DEFAULT_DERIVED_DATA_INFO}\n"
60
+ raise msg.join("\n")
61
+ else
62
+ puts "Found potential build dir: #{build_dirs.first}"
63
+ puts "Checking..."
64
+ return build_dirs.first
65
+ end
66
+ end
67
+
68
+ def self.app_bundle_or_raise(path)
69
+ bundle_path = nil
70
+
71
+ if path and not File.directory?(path)
72
+ puts "Unable to find .app bundle at #{path}. It should be an .app directory."
73
+ dd_dir = derived_data_dir_for_project_name(path)
74
+ app_bundles = Dir.glob(File.join(dd_dir, "Build", "Products", "*", "*.app"))
75
+ msg = "sim_launcher found the following bundles:\n\n"
76
+ msg << app_bundles.join("\n")
77
+ raise msg
78
+ elsif path
79
+ bundle_path = path
80
+ else
81
+ dd_dir = derived_data_dir_for_project_name(path)
82
+ sim_dirs = Dir.glob(File.join(dd_dir, "Build", "Products", "*-iphonesimulator", "*.app"))
83
+ if sim_dirs.empty?
84
+ msg = ["Unable to auto detect bundle."]
85
+ msg << "Have you built your app for simulator?."
86
+ msg << "Searched dir: #{dd_dir}/Build/Products"
87
+ msg << "Please build your app from Xcode\n"
88
+ raise msg.join("\n")
89
+ end
90
+ preferred_dir = find_preferred_dir(sim_dirs)
91
+ if preferred_dir.nil?
92
+ msg = ["Error... Unable to find bundle."]
93
+ msg << "Cannot find a built app that is linked with calabash.framework"
94
+ msg << "Please build your app from Xcode"
95
+ msg << "You should build your calabash target.\n"
96
+ raise msg.join("\n")
97
+ end
98
+ puts("-"*37)
99
+ puts "Auto detected bundle:\n\n"
100
+ puts "bundle = #{preferred_dir || sim_dirs[0]}\n\n"
101
+ puts "Please verify!"
102
+ puts("-"*37)
103
+ bundle_path = sim_dirs[0]
104
+ end
105
+ bundle_path
106
+ end
107
+
27
108
  end
@@ -1,8 +1,9 @@
1
1
  module SimLauncher
2
+
2
3
  class Simulator
3
4
 
4
5
  def initialize( iphonesim_path_external = nil )
5
- @iphonesim_path = iphonesim_path_external || iphonesim_path(xcode_version)
6
+ @iphonesim_path = iphonesim_path_external || iphonesim_path
6
7
  end
7
8
 
8
9
  def showsdks
@@ -58,15 +59,26 @@ class Simulator
58
59
  launch_ios_app( app_path, sdk, 'ipad' )
59
60
  end
60
61
 
62
+ def launch_ipad_app_with_name( app_name, sdk )
63
+ app_path = SimLauncher.app_bundle_or_raise(app_name)
64
+ launch_ios_app( app_path, sdk, 'iphone' )
65
+ end
66
+
61
67
  def launch_iphone_app( app_path, sdk )
62
68
  launch_ios_app( app_path, sdk, 'iphone' )
63
69
  end
64
70
 
71
+ def launch_iphone_app_with_name( app_name, sdk )
72
+ app_path = SimLauncher.app_bundle_or_raise(app_name)
73
+ launch_ios_app( app_path, sdk, 'iphone' )
74
+ end
75
+
65
76
  def quit_simulator
66
77
  `echo 'application "iPhone Simulator" quit' | osascript`
67
78
  end
68
79
 
69
80
  def run_synchronous_command( *args )
81
+ args.compact!
70
82
  cmd = cmd_line_with_args( args )
71
83
  puts "executing #{cmd}" if $DEBUG
72
84
  `#{cmd}`
@@ -76,21 +88,32 @@ class Simulator
76
88
  cmd_sections = [@iphonesim_path] + args.map{ |x| "\"#{x.to_s}\"" } << '2>&1'
77
89
  cmd_sections.join(' ')
78
90
  end
79
-
91
+
80
92
  def xcode_version
81
- version = `xcodebuild -version`
82
- raise "xcodebuild not found" unless $? == 0
83
- version[/([0-9]\.[0-9])/, 1].to_f
93
+ version_out = `xcodebuild -version`
94
+ begin
95
+ Float(version_out[/([0-9]\.[0-9])/, 1])
96
+ rescue => ex
97
+ raise "Cannot determine xcode version: #{ex}"
98
+ end
84
99
  end
85
-
86
- def iphonesim_path(version)
87
- installed = `which ios-sim`
100
+
101
+ def iphonesim_path
102
+ binary_name = 'ios-sim'
103
+
104
+ framework_dir = `xcode-select -p`.chomp + 'Platforms/iPhoneSimulator.platform/Developer/Library/PrivateFrameworks/iPhoneSimulatorRemoteClient.framework'
105
+
106
+ if File.directory?(framework_dir)
107
+ binary_name = 'ios-sim-old'
108
+ end
109
+
110
+ installed = `which #{binary_name}`
88
111
  if installed =~ /(.*ios-sim)/
89
- puts "Using installed ios-sim at #{$1}"
112
+ puts "Using installed #{binary_name} at #{$1}"
90
113
  return $1
91
114
  end
92
115
 
93
- File.join( File.dirname(__FILE__), '..', '..', 'native', 'ios-sim' )
116
+ File.join( File.dirname(__FILE__), '..', '..', 'native', binary_name )
94
117
  end
95
118
  end
96
119
  end
@@ -1,3 +1,3 @@
1
1
  module SimLauncher
2
- VERSION = "0.4.8.pre1"
2
+ VERSION = "0.4.9"
3
3
  end
data/native/ios-sim CHANGED
Binary file
Binary file
metadata CHANGED
@@ -1,15 +1,15 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: sim_launcher
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.4.8.pre1
5
- prerelease: 6
4
+ version: 0.4.9
5
+ prerelease:
6
6
  platform: ruby
7
7
  authors:
8
8
  - Pete Hodgson
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2013-03-08 00:00:00.000000000 Z
12
+ date: 2014-03-14 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: sinatra
@@ -47,6 +47,7 @@ files:
47
47
  - lib/sim_launcher/simulator.rb
48
48
  - lib/sim_launcher/version.rb
49
49
  - native/ios-sim
50
+ - native/ios-sim-old
50
51
  - native/iphonesim
51
52
  - scripts/reset_simulator.applescript
52
53
  - scripts/rotate_simulator_left.applescript
@@ -67,14 +68,13 @@ required_ruby_version: !ruby/object:Gem::Requirement
67
68
  required_rubygems_version: !ruby/object:Gem::Requirement
68
69
  none: false
69
70
  requirements:
70
- - - ! '>'
71
+ - - ! '>='
71
72
  - !ruby/object:Gem::Version
72
- version: 1.3.1
73
+ version: '0'
73
74
  requirements: []
74
75
  rubyforge_project:
75
- rubygems_version: 1.8.24
76
+ rubygems_version: 1.8.25
76
77
  signing_key:
77
78
  specification_version: 3
78
79
  summary: tiny HTTP server to launch an app in the iOS simulator
79
80
  test_files: []
80
- has_rdoc: