[macruby-changes] [3337] MacRuby/trunk/rakelib/builder.rake

source_changes at macosforge.org source_changes at macosforge.org
Tue Jan 26 02:42:47 PST 2010


Revision: 3337
          http://trac.macosforge.org/projects/ruby/changeset/3337
Author:   eloy.de.enige at gmail.com
Date:     2010-01-26 02:42:46 -0800 (Tue, 26 Jan 2010)
Log Message:
-----------
Add a simple way to execute commands in parallel. For the time being it's only used for stdlib:build. Use the `j' ENV variable to set the amount of jobs, eg: rake stdlib:build j=8

Modified Paths:
--------------
    MacRuby/trunk/rakelib/builder.rake

Modified: MacRuby/trunk/rakelib/builder.rake
===================================================================
--- MacRuby/trunk/rakelib/builder.rake	2010-01-26 00:39:08 UTC (rev 3336)
+++ MacRuby/trunk/rakelib/builder.rake	2010-01-26 10:42:46 UTC (rev 3337)
@@ -399,17 +399,33 @@
   'lib/yaml/rubytypes.rb',
 ]
 namespace :stdlib do
+  # Runs the given array of +commands+ in parallel. The amount of spawned
+  # simultaneous jobs is determined by the `j' env variable and defaults to 1.
+  def parallel_execute(commands)
+    @jobs ||= ENV['j'] ? ENV['j'].to_i : 1
+    commands = commands.dup
+    
+    Array.new(@jobs) do
+      Thread.new do
+        while command = commands.shift
+          sh command
+        end
+      end
+    end.each { |t| t.join }
+  end
+  
   desc "AOT compile the stdlib"
   task :build => [:miniruby, 'macruby:dylib'] do
-    AOT_STDLIB.each do |pat|
-      Dir.glob(pat).each do |path|
+    archf = ARCHS.map { |x| "--arch #{x}" }.join(' ')
+    commands = AOT_STDLIB.map do |pattern|
+      Dir.glob(pattern).map do |path|
         out = File.join(File.dirname(path), File.basename(path, '.rb') + '.rbo')
         if !File.exist?(out) or File.mtime(path) > File.mtime(out) or File.mtime('./miniruby') > File.mtime(out)
-          archf = ARCHS.map { |x| "--arch #{x}" }.join(' ')
-          sh "./miniruby -I. -I./lib bin/rubyc --internal #{archf} -C \"#{path}\" -o \"#{out}\""
+          "./miniruby -I. -I./lib bin/rubyc --internal #{archf} -C \"#{path}\" -o \"#{out}\""
         end
       end
-    end
+    end.flatten.compact
+    parallel_execute(commands)
   end
 
   desc "Touch .rbo files to ignore their build"
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.macosforge.org/pipermail/macruby-changes/attachments/20100126/a5ed8b03/attachment.html>


More information about the macruby-changes mailing list