lib/calabash-cucumber/launch/simulator_helper.rb in calabash-cucumber-0.9.43 vs lib/calabash-cucumber/launch/simulator_helper.rb in calabash-cucumber-0.9.44
- old
+ new
@@ -5,11 +5,13 @@
module Calabash
module Cucumber
module SimulatorHelper
- DEFAULT_DERIVED_DATA = File.expand_path("~/Library/Developer/Xcode/DerivedData/*/info.plist")
+ DERIVED_DATA = File.expand_path("~/Library/Developer/Xcode/DerivedData")
+ DEFAULT_DERIVED_DATA_INFO = File.expand_path("#{DERIVED_DATA}/*/info.plist")
+
MAX_PING_ATTEMPTS = 5
def self.relaunch(path, sdk = nil, version = 'iphone')
app_bundle_path = app_bundle_or_raise(path)
@@ -24,37 +26,71 @@
def self.derived_data_dir_for_project
dir = project_dir
- info_plist = Dir.glob(DEFAULT_DERIVED_DATA).find { |plist_file|
+ info_plist = Dir.glob(DEFAULT_DERIVED_DATA_INFO).find { |plist_file|
begin
plist = CFPropertyList::List.new(:file => plist_file)
hash = CFPropertyList.native_types(plist.value)
ws_dir = File.dirname(hash['WorkspacePath']).downcase
p_dir = dir.downcase
ws_dir == p_dir
rescue
false
end
}
+
if not info_plist.nil?
- File.dirname(info_plist)
+ return File.dirname(info_plist)
else
- msg = ["Unable to find your built app."]
- msg << "This means that Calabash can't automatically launch iOS simulator."
- msg << "Searched in Xcode 4.x default: #{DEFAULT_DERIVED_DATA}"
- msg << ""
- msg << "To fix there are a couple of options:\n"
- msg << "Option 1) Make sure you are running this command from your project directory, "
- msg << "i.e., the directory containing your .xcodeproj file."
- msg << "In Xcode, build your calabash target for simulator."
- msg << "Check that your app can be found in\n #{File.expand_path("~/Library/Developer/Xcode/DerivedData")}"
- msg << "\n\nOption 2). In features/support/launch.rb set APP_BUNDLE_PATH to"
- msg << "the path where Xcode has built your Calabash target."
- msg << "Alternatively you can use the environment variable APP_BUNDLE_PATH.\n"
- raise msg.join("\n")
+ res = Dir.glob("#{dir}/*.xcodeproj")
+ if res.empty?
+ raise "Unable to find *.xcodeproj in #{dir}"
+ elsif res.count > 1
+ raise "Unable to found several *.xcodeproj in #{dir}: #{res}"
+ end
+
+ xcode_proj_name = res.first.split(".xcodeproj")[0]
+
+ xcode_proj_name = File.basename(xcode_proj_name)
+
+ build_dirs = Dir.glob("#{DERIVED_DATA}/*").find_all do |xc_proj|
+ File.basename(xc_proj).start_with?(xcode_proj_name)
+ end
+
+ if (build_dirs.count == 0)
+ msg = ["Unable to find your built app."]
+ msg << "This means that Calabash can't automatically launch iOS simulator."
+ msg << "Searched in Xcode 4.x default: #{DEFAULT_DERIVED_DATA_INFO}"
+ msg << ""
+ msg << "To fix there are a couple of options:\n"
+ msg << "Option 1) Make sure you are running this command from your project directory, "
+ msg << "i.e., the directory containing your .xcodeproj file."
+ msg << "In Xcode, build your calabash target for simulator."
+ msg << "Check that your app can be found in\n #{File.expand_path("~/Library/Developer/Xcode/DerivedData")}"
+ msg << "\n\nOption 2). In features/support/launch.rb set APP_BUNDLE_PATH to"
+ msg << "the path where Xcode has built your Calabash target."
+ msg << "Alternatively you can use the environment variable APP_BUNDLE_PATH.\n"
+ raise msg.join("\n")
+
+ elsif (build_dirs.count > 1)
+ msg = ["Unable to auto detect APP_BUNDLE_PATH."]
+ msg << "You have several projects with the same name: #{xcode_proj_name} in #{DERIVED_DATA}:\n"
+ msg << build_dirs.join("\n")
+
+ msg << "\nThis means that Calabash can't automatically launch iOS simulator."
+ msg << "Searched in Xcode 4.x default: #{DEFAULT_DERIVED_DATA_INFO}"
+ msg << "\nIn features/support/launch.rb set APP_BUNDLE_PATH to"
+ msg << "the path where Xcode has built your Calabash target."
+ msg << "Alternatively you can use the environment variable APP_BUNDLE_PATH.\n"
+ raise msg.join("\n")
+ else
+ puts "Found potential build dir: #{build_dirs.first}"
+ puts "Checking..."
+ return build_dirs.first
+ end
end
end
def self.project_dir
File.expand_path(ENV['PROJECT_DIR'] || Dir.pwd)
@@ -177,6 +213,5 @@
end
end
end
-