assets/rakelib/ruboto.rake in ruboto-1.0.2 vs assets/rakelib/ruboto.rake in ruboto-1.0.3

- old
+ new

@@ -75,11 +75,11 @@ end PROJECT_DIR = File.expand_path('..', File.dirname(__FILE__)) UPDATE_MARKER_FILE = File.join(PROJECT_DIR, 'bin', 'LAST_UPDATE') BUNDLE_JAR = File.expand_path 'libs/bundle.jar' -BUNDLE_PATH = File.expand_path 'bin/bundle' +BUNDLE_PATH = File.join(PROJECT_DIR, 'bin', 'bundle') MANIFEST_FILE = File.expand_path 'AndroidManifest.xml' PROJECT_PROPS_FILE = File.expand_path 'project.properties' RUBOTO_CONFIG_FILE = File.expand_path 'ruboto.yml' GEM_FILE = File.expand_path 'Gemfile.apk' GEM_LOCK_FILE = "#{GEM_FILE}.lock" @@ -237,27 +237,57 @@ file RUBOTO_CONFIG_FILE task :jruby_adapter => JRUBY_ADAPTER_FILE file JRUBY_ADAPTER_FILE => RUBOTO_CONFIG_FILE do require 'yaml' + + ruboto_yml = (YAML.load(File.read(RUBOTO_CONFIG_FILE)) || {}) + source = File.read(JRUBY_ADAPTER_FILE) + + # + # HeapAlloc + # + comment = '' marker_topic ='Ruboto HeapAlloc' begin_marker = "// BEGIN #{marker_topic}" end_marker = "// END #{marker_topic}" - unless (heap_alloc = YAML.load(File.read(RUBOTO_CONFIG_FILE))['heap_alloc']) + unless (heap_alloc = ruboto_yml['heap_alloc']) heap_alloc = 13 comment = '// ' end config = <<EOF #{begin_marker} #{comment}@SuppressWarnings("unused") #{comment}byte[] arrayForHeapAllocation = new byte[#{heap_alloc} * 1024 * 1024]; #{comment}arrayForHeapAllocation = null; #{end_marker} EOF - source = File.read(JRUBY_ADAPTER_FILE) - heap_alloc_pattern = %r{^\s*#{begin_marker}\n.*^\s*#{end_marker}\n}m - File.open(JRUBY_ADAPTER_FILE, 'w') { |f| f << source.sub(heap_alloc_pattern, config) } + pattern = %r{^\s*#{begin_marker}\n.*^\s*#{end_marker}\n}m + source = source.sub(pattern, config) + + # + # RubyVersion + # + comment = '' + marker_topic ='Ruboto RubyVersion' + begin_marker = "// BEGIN #{marker_topic}" + end_marker = "// END #{marker_topic}" + unless (ruby_version = ruboto_yml['ruby_version']) + ruby_version = 2.0 + comment = '// ' + end + ruby_version = ruby_version.to_s + ruby_version['.'] = '_' + config = <<EOF + #{begin_marker} + #{comment}System.setProperty("jruby.compat.version", "RUBY#{ruby_version}"); // RUBY1_9 is the default in JRuby 1.7 + #{end_marker} +EOF + pattern = %r{^\s*#{begin_marker}\n.*^\s*#{end_marker}\n}m + source = source.sub(pattern, config) + + File.open(JRUBY_ADAPTER_FILE, 'w') { |f| f << source } end file APK_FILE => APK_DEPENDENCIES do |t| build_apk(t, false) end @@ -363,29 +393,31 @@ file BUNDLE_JAR => [GEM_FILE, GEM_LOCK_FILE] do next unless File.exists? GEM_FILE puts "Generating #{BUNDLE_JAR}" require 'bundler' # FIXME(uwe): Issue #547 https://github.com/ruboto/ruboto/issues/547 - if true || Gem::Version.new(Bundler::VERSION) <= Gem::Version.new('1.5.0') + if true || Gem::Version.new(Bundler::VERSION) <= Gem::Version.new('1.6.3') require 'bundler/vendored_thor' # Store original RubyGems/Bundler environment platforms = Gem.platforms ruby_engine = defined?(RUBY_ENGINE) && RUBY_ENGINE - gem_paths = {'GEM_HOME' => Gem.path, 'GEM_PATH' => Gem.dir} + env_home = ENV['GEM_HOME'] + env_path = ENV['GEM_PATH'] # Override RUBY_ENGINE (we can bundle from MRI for JRuby) Gem.platforms = [Gem::Platform::RUBY, Gem::Platform.new("universal-dalvik-#{sdk_level}"), Gem::Platform.new('universal-java')] - Gem.paths = {'GEM_HOME' => BUNDLE_PATH, 'GEM_PATH' => BUNDLE_PATH} + ENV['GEM_HOME'] = BUNDLE_PATH + ENV['GEM_PATH'] = BUNDLE_PATH old_verbose, $VERBOSE = $VERBOSE, nil begin Object.const_set('RUBY_ENGINE', 'jruby') ensure $VERBOSE = old_verbose end - ENV['BUNDLE_GEMFILE'] = GEM_FILE + Bundler.ui = Bundler::UI::Shell.new Bundler.bundle_path = Pathname.new BUNDLE_PATH definition = Bundler.definition definition.validate_ruby! Bundler::Installer.install(Bundler.root, definition) @@ -400,11 +432,12 @@ Object.const_set('RUBY_ENGINE', ruby_engine) ensure $VERBOSE = old_verbose end Gem.platforms = platforms - Gem.paths = gem_paths['GEM_PATH'] + ENV['GEM_HOME'] = env_home + ENV['GEM_PATH'] = env_path else # Bundler.settings[:platform] = Gem::Platform::DALVIK sh "bundle install --gemfile #{GEM_FILE} --path=#{BUNDLE_PATH} --platform=dalvik#{sdk_level}" end @@ -617,12 +650,14 @@ # Return nil if the package is not installed. def package_installed?(test = false) package_name = "#{package}#{'.tests' if test}" loop do path_line = `adb shell pm path #{package_name}`.chomp + path_line.gsub! /^WARNING:.*$/, '' return nil if $? == 0 && path_line.empty? break if $? == 0 && path_line =~ /^package:(.*)$/ + puts path_line sleep 0.5 end path = $1 o = `adb shell ls -l #{path}`.chomp raise "Unexpected ls output: #{o}" if o !~ APK_FILE_REGEXP @@ -649,12 +684,12 @@ end def build_apk(t, release) apk_file = release ? RELEASE_APK_FILE : APK_FILE if File.exist?(apk_file) - changed_prereqs = t.prerequisites.select do |p| - File.file?(p) && !Dir[p].empty? && Dir[p].map { |f| File.mtime(f) }.max > File.mtime(apk_file) + changed_prereqs = t.prerequisites.select do |pr| + File.file?(pr) && !Dir[pr].empty? && Dir[pr].map { |f| File.mtime(f) }.max >= File.mtime(apk_file) end return false if changed_prereqs.empty? changed_prereqs.each { |f| puts "#{f} changed." } puts "Forcing rebuild of #{apk_file}." end @@ -664,11 +699,21 @@ sh "#{ANT_CMD} debug" end true end +def wait_for_valid_device + while `adb shell echo "ping"`.strip != 'ping' + `adb kill-server` + `adb devices` + sleep 5 + end +end + def install_apk + wait_for_valid_device + failure_pattern = /^Failure \[(.*)\]/ success_pattern = /^Success/ case package_installed? when true puts "Package #{package} already installed." @@ -739,11 +784,12 @@ exit $? end end def update_scripts - `adb shell mkdir -p #{scripts_path}` if !device_path_exists?(scripts_path) + puts(`adb shell mkdir -p #{scripts_path}`) unless device_path_exists?(scripts_path) + raise "Unable to create device scripts dir: #{scripts_path}" unless device_path_exists?(scripts_path) last_update = File.exists?(UPDATE_MARKER_FILE) ? Time.parse(File.read(UPDATE_MARKER_FILE)) : Time.parse('1970-01-01T00:00:00') Dir.chdir('src') do source_files = Dir['**/*.rb'] changed_files = source_files.select { |f| !File.directory?(f) && File.mtime(f) >= last_update && f !~ /~$/ } unless changed_files.empty? @@ -767,11 +813,11 @@ `adb shell am start -a android.intent.action.MAIN -n #{package}/.#{main_activity}` end # Triggers reload of updated scripts and restart of the current activity def reload_scripts(scripts) - s = scripts.map{|s| s.gsub(/[&;]/){|m| "&#{m[0]}"}}.join(';') - cmd = %Q{adb shell am broadcast -a android.intent.action.VIEW -e reload "#{s}"} + s = scripts.map{|s| s.gsub(/[&;]/){|m| "&#{m[0]}"}}.join('\;') + cmd = %Q{adb shell am broadcast -a android.intent.action.VIEW -e reload '#{s}'} puts cmd system cmd end def stop_app