rakefile.rb in rhodes-1.4.2 vs rakefile.rb in rhodes-1.5.0

- old
+ new

@@ -1,8 +1,10 @@ require 'find' require 'erb' require 'rake/rdoctask' +require 'digest/sha2' +require 'rexml/document' #Look, another big fat hack. Make it so we can remove tasks from rake -T by setting comment to nil module Rake class Task attr_accessor :comment @@ -18,10 +20,19 @@ load 'platform/android/build/android.rake' load 'platform/iphone/rbuild/iphone.rake' load 'platform/wm/build/wm.rake' load 'platform/linux/tasks/linux.rake' +def get_dir_hash(dir, init = nil) + hash = init + hash = Digest::SHA2.new if hash.nil? + Dir.glob(dir + "/**/*").each do |f| + hash << f + hash.file(f) if File.file? f + end + hash +end namespace "framework" do task :spec do loadpath = $LOAD_PATH.inject("") { |load_path,pe| load_path += " -I" + pe } @@ -41,11 +52,10 @@ namespace "config" do task :common do $startdir = File.dirname(__FILE__) - $binextensions = [] buildyml = 'rhobuild.yml' buildyml = ENV["RHOBUILD"] unless ENV["RHOBUILD"].nil? $config = Jake.config(File.open(buildyml)) if RUBY_PLATFORM =~ /(win|w)32$/ @@ -59,11 +69,11 @@ $app_path = $config["env"]["app"] unless File.exists? $app_path puts "Could not find rhodes application. Please verify your application setting in #{File.dirname(__FILE__)}/rhobuild.yml" exit 1 end - $app_config = YAML::load_file($app_path + "/build.yml") + $app_config = Jake.config(File.open(File.join($app_path, "build.yml"))) end Jake.set_bbver($app_config["bbver"].to_s) end @@ -77,30 +87,10 @@ cp_r asset + "/.", dest, :remove_destination => true end -def check_extension_file - extfile = "" - File.open($startdir + "/platform/shared/ruby/ext/rho/extensions.c","r") do |f| - f.each_line do |line| - if line !~ /;/ - extfile << line - else - loaded = false - $binextensions.each { |loadedext| loaded = line.include? loadedext; break if loaded } - extfile << line if loaded - - end - - end - end - if extfile != "" - File.open($startdir + "/platform/shared/ruby/ext/rho/extensions.c","w") { |f| f.write extfile } - end -end - def clear_linker_settings if $config["platform"] == "iphone" # outfile = "" # IO.read($startdir + "/platform/iphone/rhorunner.xcodeproj/project.pbxproj").each_line do |line| # if line =~ /EXTENSIONS_LDFLAGS = / @@ -161,81 +151,11 @@ start = pwd chdir path if File.directory?(path) Dir.glob("*").each { |f| cp_r f,dest unless f =~ /^ext(\/|(\.yml)?$)/ } - if File.exist? "ext.yml" - extension_config = YAML::load_file("ext.yml") - - if extension_config["entry"] and extension_config["entry"] != "" - extfile = "" - File.open($startdir + "/platform/shared/ruby/ext/rho/extensions.c","r") do |f| - externstart = false - externwritten = false - callstart = false - callwritten = false - - f.each_line do |line| - # puts line - #are we starting a replacement area? - externstart = true if line =~ /EXTERNS/ - callstart = true if line =~ /CALLS/ - - - #if we arent in our replacement area, just copy the line - unless externstart or callstart - extfile << line - else - #always write an end marker - extfile << line if line =~ /END/ - #did we just start the extern replacement area? - if externstart and not externwritten - #write marker and our new extension - extfile << line - extfile << "extern void #{extension_config["entry"]}(void);\n" - externwritten = true - end - - #same for calls - if callstart and not callwritten - extfile << line - extfile << "#{extension_config["entry"]}();\n" - callwritten = true - end - - #did we leave a replacement area - externstart = false if externstart and line =~ /END/ - callstart = false if callstart and line =~ /END/ - - #if we are in a replacement area, check for lines that are there - #that we have marked as loaded and copy those over - #this is to make sure we are only loading things we explicitly marked - #leaving out lines that came from a previous run - if externstart or callstart - loaded = false - $binextensions.each { |loadedext| loaded = line.include? loadedext; break if loaded } - extfile << line if loaded - end - end - - end - $binextensions << extension_config["entry"] - end - - if extfile != "" - File.open($startdir + "/platform/shared/ruby/ext/rho/extensions.c","w") { |f| f.write extfile } - end - - end - - if extension_config["libraries"] and extension_config["libraries"].is_a? Array - extension_config["libraries"].each { |lib| add_linker_library(lib) } - end - end - chdir start - end def common_bundle_start(startdir, dest) app = $app_path rhodeslib = "lib/framework" @@ -264,11 +184,13 @@ extensions += $app_config["extensions"] if $app_config["extensions"] and $app_config["extensions"].is_a? Array extensions += $app_config[$config["platform"]["extensions"]] if $config["platform"] and $config["platform"]["extensions"] and $config["platform"]["extensions"].is_a? Array $app_config["extensions"] = extensions - + + extentries = [] + extlibs = [] $app_config["extensions"].each do |extname| rhoextpath = "lib/extensions/" + extname appextpath = $app_path + "/extensions/" + extname extpath = nil @@ -278,15 +200,47 @@ extpath = rhoextpath end unless extpath.nil? add_extension(extpath, dest) + + extyml = File.join(extpath, "ext.yml") + if File.file? extyml + extconf = Jake.config(File.open(extyml)) + entry = extconf["entry"] + extentries << entry unless entry.nil? + libs = extconf["libraries"] + extlibs += libs if !libs.nil? and libs.is_a? Array + end end end - check_extension_file + exts = File.join($startdir, "platform", "shared", "ruby", "ext", "rho", "extensions.c") + exists = [] + File.new(exts, "r").read.split("\n").each do |line| + next if line !~ /^\s*extern\s+void\s+([A-Za-z_][A-Za-z0-9_]*)/ + exists << $1 + end + + if exists.sort! != extentries.sort! + File.open(exts, "w") do |f| + f.puts "// WARNING! THIS FILE IS GENERATED AUTOMATICALLY! DO NOT EDIT IT MANUALLY!" + f.puts "// Generated #{Time.now.to_s}" + extentries.each do |entry| + f.puts "extern void #{entry}(void);" + end + f.puts "void Init_Extensions(void) {" + extentries.each do |entry| + f.puts " #{entry}();" + end + f.puts "}" + end + end + + extlibs.each { |lib| add_linker_library(lib) } + set_linker_flags unless $app_config["constants"].nil? File.open("rhobuild.rb","w") do |file| file << "module RhoBuild\n" @@ -316,10 +270,12 @@ Dir.glob("**/*.wm.*").each { |f| rm f } Dir.glob("**/*.iphone.*").each { |f| rm f } Dir.glob("**/*.bb.*").each { |f| rm f } Dir.glob("**/*.android.*").each { |f| rm f } + Dir.glob("**/.svn").each { |f| rm_rf f } + Dir.glob("**/cvs").each { |f| rm_rf f } end def create_manifest dir = File.join($srcdir, 'apps') @@ -475,23 +431,23 @@ # run "rake -T" to see list of available tasks #desc "Get versions" task :get_version do - genver = "unknown" + #genver = "unknown" iphonever = "unknown" #symver = "unknown" wmver = "unknown" androidver = "unknown" - File.open("res/generators/templates/application/build.yml","r") do |f| - file = f.read - if file.match(/version: (\d+\.\d+\.\d+)/) - genver = $1 - end - end + # File.open("res/generators/templates/application/build.yml","r") do |f| + # file = f.read + # if file.match(/version: (\d+\.\d+\.\d+)/) + # genver = $1 + # end + # end File.open("platform/iphone/Info.plist","r") do |f| file = f.read if file.match(/CFBundleVersion<\/key>\s+<string>(\d+\.\d+\.*\d*)<\/string>/) iphonever = $1 @@ -550,11 +506,11 @@ end puts "Versions:" - puts " Generator: " + genver + #puts " Generator: " + genver puts " iPhone: " + iphonever #puts " Symbian: " + symver #puts " WinMo: " + wmver puts " Android: " + androidver puts " Gem: " + gemver @@ -573,19 +529,19 @@ throw "Invalid version format. Must be in the format of: major.minor.build" if major.nil? or minor.nil? or build.nil? verstring = major+"."+minor+"."+build origfile = "" - File.open("res/generators/templates/application/build.yml","r") { |f| origfile = f.read } - File.open("res/generators/templates/application/build.yml","w") do |f| - f.write origfile.gsub(/version: (\d+\.\d+\.\d+)/, "version: #{verstring}") - end + # File.open("res/generators/templates/application/build.yml","r") { |f| origfile = f.read } + # File.open("res/generators/templates/application/build.yml","w") do |f| + # f.write origfile.gsub(/version: (\d+\.\d+\.\d+)/, "version: #{verstring}") + # end File.open("platform/iphone/Info.plist","r") { |f| origfile = f.read } File.open("platform/iphone/Info.plist","w") do |f| - f.write origfile.gsub(/CFBundleVersion<\/key>(\s+)<string>(\d+\.\d+\.*\d*)<\/string>/, "CFBundleVersion</key>\n <string>#{verstring}</string>") + f.write origfile.gsub(/CFBundleVersion<\/key>(\s+)<string>(\d+\.\d+\.*\d*)<\/string>/, "CFBundleVersion</key>\n\t<string>#{verstring}</string>") end # File.open("platform/symbian/build/release.properties","r") { |f| origfile = f.read } # File.open("platform/symbian/build/release.properties","w") do |f| # origfile.gsub!(/release\.major=(\d+)/,"release.major=#{major}") @@ -624,10 +580,10 @@ task :production => "config:common" do $config["env"]["paths"].each do |k,v| if k.to_s =~ /^4/ puts "BUILDING VERSION: #{k}" $app_config["bbver"] = k - Jake.reconfig($config) +# Jake.reconfig($config) #reset all tasks used for building Rake::Task["config:bb"].reenable Rake::Task["build:bb:rhobundle"].reenable Rake::Task["build:bb:rhodes"].reenable