lib/ruboto/util/setup.rb in ruboto-1.2.0 vs lib/ruboto/util/setup.rb in ruboto-1.3.0

- old
+ new

@@ -4,11 +4,11 @@ module Ruboto module Util module Setup include Ruboto::Util::Verify REPOSITORY_BASE = 'http://dl-ssl.google.com/android/repository' - REPOSITORY_URL = "#{REPOSITORY_BASE}/repository-8.xml" + REPOSITORY_URL = "#{REPOSITORY_BASE}/repository-10.xml" SDK_DOWNLOAD_PAGE = 'http://developer.android.com/sdk/index.html?hl=sk' RUBOTO_GEM_ROOT = File.expand_path '../../../..', __FILE__ WINDOWS_ELEVATE_CMD = "#{RUBOTO_GEM_ROOT}/bin/elevate_32.exe -c -w" @@ -108,11 +108,11 @@ def get_tools_version(type='tool') require 'rexml/document' require 'open-uri' doc = REXML::Document.new(open(REPOSITORY_URL)) - version = doc.root.elements.to_a("sdk:#{type}/sdk:revision").map do |t| + doc.root.elements.to_a("sdk:#{type}/sdk:revision").map do |t| major = t.elements['sdk:major'] minor = t.elements['sdk:minor'] micro = t.elements['sdk:micro'] prev = t.elements['sdk:preview'] next if prev @@ -120,11 +120,10 @@ version += ".#{minor.text}" if minor version += ".#{micro.text}" if micro version += "_rc#{prev.text}" if prev version end.compact.sort_by { |v| Gem::Version.new(v.gsub('_', '.')) }.last - version end def get_android_sdk_version require 'net/http' require 'uri' @@ -143,11 +142,11 @@ raise "Unknown host os: #{android_package_os_id}" end link = page_content.scan(/#{regex}/) raise "SDK link cannot be found on download page: #{SDK_DOWNLOAD_PAGE}" if link.nil? - + version = link.to_s.match(/r(\d+.)?(\d+.)?(\d+)/)[0] raise "SDK version cannot be determined from download page: #{SDK_DOWNLOAD_PAGE}" if version.nil? version.delete! 'r' end @@ -188,13 +187,24 @@ def check_for_haxm case android_package_os_id when MAC_OS_X @haxm_kext_loc = '/System/Library/Extensions/intelhaxm.kext' found = File.exists?(@haxm_kext_loc) - @haxm_kext_loc = nil unless found - puts "#{'%-25s' % 'Intel HAXM'}: #{(found ? 'Found' : 'Not found')}" + if found + @haxm_kext_version = `kextstat | grep com.intel.kext.intelhaxm`.slice(/\(.*\)/)[1..-2] + else + @haxm_kext_loc = nil + end + # FIXME(uwe): Use the system version to choose the right .dmg + os_x_version = ENV['_system_version'] @haxm_installer_loc = Dir[File.join(android_package_directory, 'extras', 'intel', 'Hardware_Accelerated_Execution_Manager', 'IntelHAXM*.dmg')].first + @haxm_installer_version = @haxm_installer_loc.slice(/IntelHAXM_1.1.1_/)[10..-2] + if @haxm_kext_version == @haxm_installer_version + puts "#{'%-25s' % 'Intel HAXM'}: #{(found ? "Found" : 'Not found')}" + else + puts "#{'%-25s' % 'Intel HAXM'}: Old #{@haxm_kext_version}/#{@haxm_installer_version}" + end when LINUX @haxm_installer_loc = 'Not supported, yet.' @haxm_kext_loc = 'Not supported, yet.' return when WINDOWS @@ -211,12 +221,13 @@ @adb_loc = check_for('adb', 'Android SDK Command adb', File.join(android_package_directory, 'platform-tools', windows? ? 'adb.exe' : 'adb')) end def check_for_build_tools - @dx_loc = check_for('dx', 'Android SDK Command dx', - Dir[File.join android_package_directory, 'build-tools', '*', windows? ? 'dx.bat' : 'dx'][-1]) + dx_locations = Dir[File.join android_package_directory, 'build-tools', '*', windows? ? 'dx.bat' : 'dx'] + sorted_dx_locations = dx_locations.sort_by { |f| Gem::Version.new f[%r{build-tools/[^/]+/}][12..-2] } + @dx_loc = check_for('dx', 'Android SDK Command dx', sorted_dx_locations[-1]) end def check_for_android_sdk @android_loc = check_for('android', 'Android Package Installer', File.join(android_package_directory, 'tools', windows? ? 'android.bat' : 'android')) @@ -279,23 +290,27 @@ case android_package_os_id when LINUX puts "#{pretty_name} was not found." installer = package_installer if installer - unless accept_all - print 'Would you like to and install it? (Y/n): ' - a = STDIN.gets.chomp.upcase - end - if accept_all || a == 'Y' || a.empty? - puts "sudo #{installer} install -y #{package_name}" - IO.popen("sudo #{installer} install -y #{package_name}") {|io| while (l = io.gets) do; puts l; end } - else - puts - puts "You can install #{pretty_name} manually by:" - puts "sudo #{installer} install #{package_name}" - puts - end + unless accept_all + print 'Would you like to and install it? (Y/n): ' + a = STDIN.gets.chomp.upcase + end + if accept_all || a == 'Y' || a.empty? + puts "sudo #{installer} install -y #{package_name}" + IO.popen("sudo #{installer} install -y #{package_name}") do |io| + while (l = io.gets) + puts l + end + end + else + puts + puts "You can install #{pretty_name} manually by:" + puts "sudo #{installer} install #{package_name}" + puts + end else puts "Package installer not found. You'll need to install #{pretty_name} manually." end else raise "Unknown host os for package install: #{RbConfig::CONFIG['host_os']}" @@ -571,12 +586,14 @@ a = STDIN.gets.chomp.upcase end if accept_all || a == 'Y' || a.empty? case android_package_os_id when MAC_OS_X + puts "Mounting the HAXM install image" system "hdiutil attach #{@haxm_installer_loc}" fileName = Dir['/Volumes/IntelHAXM*/IntelHAXM*.mpkg'][0] + puts "Starting the HAXM installer. Sudo password required." system "sudo -S installer -pkg #{fileName} -target /" when LINUX puts ' HAXM installation on Linux is not supported, yet.' return when WINDOWS @@ -608,12 +625,12 @@ end end def update_sdk(update_cmd, accept_all) if accept_all - IO.popen(update_cmd, 'r+') do |cmd_io| + IO.popen(update_cmd, 'r+', external_encoding: Encoding::BINARY) do |cmd_io| begin - output = '' + output = ''.encode(Encoding::BINARY) question_pattern = /.*Do you accept the license '[a-z-]+-[0-9a-f]{8}' \[y\/n\]: /m STDOUT.sync = true cmd_io.each_char do |text| print text output << text