bin/calabash-ios-setup.rb in calabash-cucumber-0.9.19 vs bin/calabash-ios-setup.rb in calabash-cucumber-0.9.20

- old
+ new

@@ -1,5 +1,7 @@ +require "calabash-cucumber/version" + def dup_scheme(project_name, pbx_dir) userdata_dirs = Dir.foreach("#{pbx_dir}/xcuserdata").find_all { |x| /\.xcuserdatad$/.match(x) } @@ -30,13 +32,23 @@ else msg("Action") do puts "Duplicating scheme #{project_name}.xcscheme as #{project_name}-cal.xcscheme" doc = REXML::Document.new(File.new("#{pbx_dir}/xcuserdata/#{userdata_dir}/xcschemes/#{scheme}")) + doc.elements.each("Scheme/LaunchAction") do |la| la.attributes["buildConfiguration"] = "Calabash" end + doc.elements.each("Scheme/ArchiveAction") do |la| + la.attributes["buildConfiguration"] = "Calabash" + end + doc.elements.each("Scheme/AnalyzeAction") do |la| + la.attributes["buildConfiguration"] = "Calabash" + end + doc.elements.each("Scheme/ProfileAction") do |la| + la.attributes["buildConfiguration"] = "Calabash" + end doc.write(File.open("#{pbx_dir}/xcuserdata/#{userdata_dir}/xcschemes/#{project_name}-cal.xcscheme", "w")) end end end @@ -55,11 +67,11 @@ msg("Setup done") do puts "Please validate by running the #{project_name}-cal scheme" puts "from Xcode." puts "When starting the iOS Simulator using the" - puts "new scheme: #{project_name}-cal, you should see:\n" + puts "new scheme: #{project_name}-cal, you should see:\n\n" puts ' "Started LPHTTP server on port 37265"' puts "\nin the application log in Xcode." puts "\n\n" puts "After validating, you can generate a features folder:" puts "Go to your project (the dir containing the .xcodeproj file)." @@ -140,20 +152,18 @@ end file = 'calabash.framework' ##Download calabash.framework if not Dir.exists?(File.join(project_path, file)) msg("Info") do - zip_file = 'calabash.framework-0.9.15.zip' - puts "Did not find calabash.framework. I'll download the latest version...'" - puts "https://raw.github.com/calabash/calabash-ios/master/frameworks/#{zip_file}" + zip_file = "calabash.framework-#{Calabash::Cucumber::VERSION}.zip" + puts "Did not find calabash.framework. I'll download it...'" + puts "http://cloud.github.com/downloads/calabash/calabash-ios/#{zip_file}" require 'uri' - require 'net/https' - uri = URI.parse "https://raw.github.com/calabash/calabash-ios/master/frameworks/#{zip_file}" + uri = URI.parse "http://cloud.github.com/downloads/calabash/calabash-ios/#{zip_file}" - Net::HTTP.start(uri.host, uri.port, - :use_ssl => uri.scheme == 'https') do |http| + Net::HTTP.start(uri.host, uri.port) do |http| request = Net::HTTP::Get.new uri.request_uri http.request request do |response| open zip_file, 'wb' do |io| response.read_body do |chunk| @@ -209,11 +219,11 @@ build_phase_entry = PBXProject::PBXTypes::BasicValue.new(:value => bf.guid, :comment => bf.comment) pbx.sections['PBXFrameworksBuildPhase'][0].files << build_phase_entry - #TODO first check if already linking with CFNetwork + cfnet = pbx.find_item :name => "CFNetwork.framework", :type => PBXProject::PBXTypes::PBXFileReference unless cfnet f = PBXProject::PBXTypes::PBXFileReference.new(:path => "System/Library/Frameworks/CFNetwork.framework", :lastKnownFileType => "wrapper.framework", :sourceTree => 'SDKROOT') f.comment = "CFNetwork.framework" @@ -283,10 +293,30 @@ project_cal_build_settings[k] = v.clone end ld_flags = cal_build_settings['OTHER_LDFLAGS'] || [] + + if not ld_flags.is_a?Array + ld_flags = [ld_flags] + end + danger = ld_flags.find_all {|f| /-ObjC/i.match(f.value) || /-all_load/i.match(f.value)} + + if not danger.empty? + msg("Error") do + puts "Detected Other Linker Flag: #{(danger.map {|d| d.value}).join(", ")}" + puts "calabash-ios setup does not yet support this scenario" + puts "(why? karl@lesspainful.com)" + puts "You must manually setup ios see:" + puts "https://github.com/calabash/calabash-ios" + end + exit 1 + end + + + + ld_flags << PBXProject::PBXTypes::BasicValue.new(:value => '"-force_load"') ld_flags << PBXProject::PBXTypes::BasicValue.new(:value => '"$(SRCROOT)/calabash.framework/calabash"') ld_flags << PBXProject::PBXTypes::BasicValue.new(:value => '"-lstdc++"') @@ -312,17 +342,133 @@ sp = bc.buildSettings["FRAMEWORK_SEARCH_PATHS"] || [] if not sp.is_a?Array sp = [sp] end inherit = sp.find { |x| x.value == '"$(inherited)"' } - srcroot = sp.find { |x| p x.value;x.value == "\"$(SRCROOT)\""} - p srcroot + srcroot = sp.find { |x| x.value == "\"$(SRCROOT)\""} sp << PBXProject::PBXTypes::BasicValue.new(:value => '"$(inherited)"') unless inherit sp << PBXProject::PBXTypes::BasicValue.new(:value => "\"$(SRCROOT)\"") unless srcroot bc.buildSettings["FRAMEWORK_SEARCH_PATHS"] = sp end pbx.write_to :file => proj_file end + +require 'calabash-cucumber/launch/simulator_helper' +def validate_setup(args) + if args.length > 0 + if args[0].end_with?(".ipa") + validate_ipa(args[0]) + elsif args[0].end_with?(".app") + validate_app(args[0]) + end + else + dd_dir = Calabash::Cucumber::SimulatorHelper.derived_data_dir_for_project + if not dd_dir + puts "Unable to find iOS project." + puts "You should run this command from an iOS project directory." + exit 1 + end + app_bundles = Dir.glob(File.join(dd_dir, "Build", "Products", "*", "*.app")) + sim_dirs = Dir.glob(File.join(dd_dir, "Build", "Products", "Debug-iphonesimulator", "*.app")) + sim_dirs = sim_dirs.concat(Dir.glob(File.join(dd_dir, "Build", "Products", "Calabash-iphonesimulator", "*.app"))) + if sim_dirs.empty? + msg = ["Have you built your app for simulator?"] + msg << "You should build the -cal scheme and your normal scheme" + msg << "(with configuration Debug)." + msg << "Searched dir: #{dd_dir}/Build/Products" + msg("Error") do + puts msg.join("\n") + end + exit 1 + elsif sim_dirs.count != 2 + msg = ["Have you built your app for simulator?"] + msg << "You should build the -cal scheme and your normal scheme" + msg << "(with configuration Debug)." + msg << "Searched dir: #{dd_dir}/Build/Products" + msg("Error") do + puts msg.join("\n") + end + exit 1 + end + out_debug = `otool #{sim_dirs[0]}/* -o 2> /dev/null | grep CalabashServer` + out_cal = `otool #{sim_dirs[1]}/* -o 2> /dev/null | grep CalabashServer 2> /dev/null` + ok = (not /CalabashServer/.match(out_debug)) and /CalabashServer/.match(out_cal) + if ok + msg("OK") do + puts "Your configuration seems ok." + puts "app in directory:" + puts sim_dirs[0] + puts "does not have calabash.framework linked in." + puts "directory:" + puts sim_dirs[1] + puts "does." + end + else + msg("Fail") do + puts "Your configuration looks bad." + if (not /CalabashServer/.match(out_debug)) + puts "WARNING: You Debug build seems to be linking with Calabash." + puts "You should restore your xcodeproject file from backup." + else + puts "app in directory" + puts sim_dirs[1] + puts "does not have calabash.framework linked in." + end + end + end + end + + +end + +def validate_ipa(ipa) + require 'tmpdir' + fail = false + Dir.mktmpdir do |dir| + if not system("unzip -C -K -o -q -d #{dir} #{ipa}") + msg("Error") do + puts "Unable to unzip ipa: #{ipa}" + end + Dir + fail = true + end + + app_dir = Dir.foreach("#{dir}/Payload").find {|d| /\.app$/.match(d)} + app = app_dir.split(".")[0] + res = `otool #{dir}/Payload/#{app_dir}/#{app} -o 2> /dev/null | grep CalabashServer` + msg("Info") do + if /CalabashServer/.match(res) + puts "Ipa: #{ipa} *contains* calabash.framework" + else + puts "Ipa: #{ipa} *does not contain* calabash.framework" + end + end + + end + if fail + exit(1) + end + +end + +def validate_app(app) + if not Dir.exists?app + msg("Error") do + puts "Path: #{app} is not a directory." + end + exit 1 + end + out = `otool #{app}/* -o 2> /dev/null | grep CalabashServer` + + msg("Info") do + if /CalabashServer/.match(out) + puts "App: #{app} *contains* calabash.framework" + else + puts "App: #{app} *does not contain* calabash.framework" + end + end + +end \ No newline at end of file