Skip to content

Instantly share code, notes, and snippets.

@iwazer
Last active December 21, 2015 10:29
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save iwazer/6292291 to your computer and use it in GitHub Desktop.
Save iwazer/6292291 to your computer and use it in GitHub Desktop.
#
# This Snippet may do to be able to refer all definitions of libraries
# from RubyMotion REPL, when You paste this Snippet on bottommost of
# your RubyMotion Rakefile. But it is very slow...
#
# Usage:
# rake preload=true # generate preload source file before build simulator
#
# rake preload:clean # delete preload source file
#
namespace :preload do
PRELOAD_FILENAME = '_preload_.rb'
desc "Generate source file for preloading"
task :generate do
file = File.join(App.config.project_dir, 'app', PRELOAD_FILENAME)
next if File.exists?(file)
App.info 'Create', file
bs_files = App.config.frameworks.map{|f| File.join(App.config.datadir, 'BridgeSupport', f + '.bridgesupport')}
bs_files += Dir.glob(File.join(App.config.project_dir, 'vendor', '**{,/*/**}/*.bridgesupport')).uniq
File.open(file, 'w') do |f|
f.puts "class AppDelegate"
f.puts " def _definition_preload_"
bs_files.each do |bs|
App.info '+', bs
f.puts " #### #{File.basename(bs)}"
names(bs).each {|name| f.puts " tmp = #{name}"}
end
f.puts " end"
f.puts " private :_definition_preload_"
f.puts "end"
end
App.config.files << file unless App.config.files.include?(file)
end
desc "Delete auto generated preload file"
task :clean do
file = File.join(App.config.project_dir, 'app', PRELOAD_FILENAME)
if File.exists?(file)
App.info 'Delete', file
File.unlink(file)
App.config.files.delete_if {|s| File.basename(s)==File.basename(file) if s.is_a?(String)}
end
end
def names bs_file
require "rexml/document"
doc = REXML::Document.new(File.new(bs_file))
doc.get_elements('//struct').map{|s| s.attributes['name']} +
doc.get_elements('//constant').map{|s| s.attributes['name']} +
doc.get_elements('//class').map{|s| s.attributes['name']} +
doc.get_elements('//enum').map{|s| s.attributes['name']}
end
end
#Rake::Task.tasks.first.try(:enhance, ['preload:clean'])
unless ENV['preload'].nil?
Rake::Task['build:simulator'].enhance ['preload:generate']
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment