[macruby-changes] [2968] MacRuby/trunk/bin/ruby_deploy

source_changes at macosforge.org source_changes at macosforge.org
Fri Nov 6 17:01:43 PST 2009


Revision: 2968
          http://trac.macosforge.org/projects/ruby/changeset/2968
Author:   lsansonetti at apple.com
Date:     2009-11-06 17:01:41 -0800 (Fri, 06 Nov 2009)
Log Message:
-----------
added --compile option to macruby_deploy that AOT compiles a given .app source code

Modified Paths:
--------------
    MacRuby/trunk/bin/ruby_deploy

Modified: MacRuby/trunk/bin/ruby_deploy
===================================================================
--- MacRuby/trunk/bin/ruby_deploy	2009-11-06 21:54:10 UTC (rev 2967)
+++ MacRuby/trunk/bin/ruby_deploy	2009-11-07 01:01:41 UTC (rev 2968)
@@ -17,9 +17,9 @@
   def initialize(argv)
     OptionParser.new do |opts|
       opts.banner = "Usage: #{NAME} [options] application-bundle"
-      opts.on('--no-stdlib', "Do not include the standard library") do
-        @no_stdlib = true
-      end
+      opts.on('--compile', 'Compile the bundle source code') { @compile = true }
+      opts.on('--embed', 'Embed MacRuby inside the bundle') { @embed = true }
+      opts.on('--no-stdlib', "Do not embed the standard library") { @no_stdlib = true }
       opts.on('-v', '--version', 'Display the version') do
         puts RUBY_DESCRIPTION
         exit 1
@@ -51,6 +51,27 @@
   end
 
   def run
+    die "Nothing to do, please specify --compile or --embed" if !@compile and !@embed
+    die "--no-stdlib can only be used with --embed" if @no_stdlib and !@embed
+    compile if @compile
+    embed if @embed
+  end
+
+  private
+
+  def compile
+    Dir.glob(File.join(@app_bundle, 'Contents/Resources/*.rb')).each do |source|
+      base = File.basename(source, '.rb')
+      next if base == 'rb_main'
+      obj = File.join(File.dirname(source), base + '.rbo')
+      if !File.exist?(obj) or File.mtime(source) > File.mtime(obj)
+        die "Can't compile \"#{source}\"" unless system("macrubyc -C \"#{source}\" -o \"#{obj}\"")
+        FileUtils.rm_f(source)
+      end
+    end
+  end
+
+  def embed
     # Copy MacRuby.framework inside MyApp.app/Contents/Frameworks.
     app_frameworks = File.join(@app_bundle, 'Contents/Frameworks')
     mkdir_p(app_frameworks)
@@ -86,8 +107,6 @@
     end
   end
 
-  private
-
   def execute(line)
     ret = `#{line}`
     die "Error when executing `#{line}'" unless $?.success?
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.macosforge.org/pipermail/macruby-changes/attachments/20091106/be42e9f4/attachment.html>


More information about the macruby-changes mailing list