Browse files

Added spec/spec_helper.rb from MacRuby, updated some load paths. Spec…

…s not functional yet.
  • Loading branch information...
1 parent a19f19f commit b57f656af86a740f65e0279df1c0ab1337ccf33d @gunn committed Dec 10, 2010
Showing with 69 additions and 11 deletions.
  1. +1 −1 examples/dispatch_methods.sh
  2. +3 −0 lib/dispatch.rb
  3. +1 −2 spec/enumerable_spec.rb
  4. +1 −2 spec/job_spec.rb
  5. +1 −2 spec/proxy_spec.rb
  6. +1 −2 spec/queue_spec.rb
  7. +1 −2 spec/source_spec.rb
  8. +60 −0 spec/spec_helper.rb
View
2 examples/dispatch_methods.sh
@@ -1,5 +1,5 @@
#!/bin/sh
-DISPATCH=../../../lib/dispatch
+DISPATCH=../
/bin/echo -n "#!"
which macruby
grep " " $DISPATCH/README.rdoc | sed "s/ //" | grep -v '\$ '
View
3 lib/dispatch.rb
@@ -12,6 +12,9 @@
# This library provides higher-level services and convenience methods
# to make it easier for traditional Ruby programmers to add multicore support.
+libdir = File.expand_path(File.dirname(__FILE__))
+$LOAD_PATH.unshift(libdir) unless $LOAD_PATH.include?(libdir)
+
require 'dispatch/source'
require 'dispatch/queue'
require 'dispatch/proxy'
View
3 spec/enumerable_spec.rb
@@ -1,5 +1,4 @@
-require File.dirname(__FILE__) + "/../../spec_helper"
-require 'dispatch'
+require "spec_helper"
if MACOSX_VERSION >= 10.6
describe "parallel loop" do
View
3 spec/job_spec.rb
@@ -1,5 +1,4 @@
-require File.dirname(__FILE__) + "/../../spec_helper"
-require 'dispatch'
+require "spec_helper"
if MACOSX_VERSION >= 10.6
describe "Dispatch::Job" do
View
3 spec/proxy_spec.rb
@@ -1,5 +1,4 @@
-require File.dirname(__FILE__) + "/../../spec_helper"
-require 'dispatch'
+require "spec_helper"
if MACOSX_VERSION >= 10.6
View
3 spec/queue_spec.rb
@@ -1,5 +1,4 @@
-require File.dirname(__FILE__) + "/../../spec_helper"
-require 'dispatch'
+require "spec_helper"
if MACOSX_VERSION >= 10.6
View
3 spec/source_spec.rb
@@ -1,5 +1,4 @@
-require File.dirname(__FILE__) + "/../../spec_helper"
-require 'dispatch'
+require "spec_helper"
if MACOSX_VERSION >= 10.6
View
60 spec/spec_helper.rb
@@ -0,0 +1,60 @@
+require File.join(File.dirname(__FILE__), "../lib/dispatch")
+
+framework 'Cocoa'
+
+SPEC_ROOT = File.dirname(__FILE__)
+FIXTURES = File.join(SPEC_ROOT, "fixtures")
+
+class FixtureCompiler
+ def self.require!(fixture)
+ new(fixture).require!
+ end
+
+ FRAMEWORKS = %w{ Foundation }
+ ARCHS = %w{ i386 x86_64 }
+ OPTIONS = %w{ -g -dynamiclib -fobjc-gc -Wl,-undefined,dynamic_lookup }
+ GCC = "/usr/bin/gcc"
+
+ attr_reader :gcc, :frameworks, :archs, :options
+ attr_reader :fixture, :bundle, :bridge_support
+
+ def initialize(fixture)
+ @fixture = File.join(FIXTURES, "#{fixture}.m")
+ @bundle = File.join("/tmp", "#{fixture}.bundle")
+ @bridge_support = File.join(FIXTURES, "#{fixture}.bridgesupport")
+
+ @gcc, @frameworks, @archs, @options = [GCC, FRAMEWORKS, ARCHS, OPTIONS].map { |x| x.dup }
+ end
+
+ def require!
+ compile!
+ load!
+ end
+
+ private
+
+ def needs_update?
+ !File.exist?(bundle) or File.mtime(fixture) > File.mtime(bundle)
+ end
+
+ def compile!
+ if needs_update?
+ puts "[!] Compiling fixture `#{fixture}'"
+
+ a = archs.map { |a| "-arch #{a}" }.join(' ')
+ o = options.join(' ')
+ f = frameworks.map { |f| "-framework #{f}" }.join(' ')
+
+ `#{gcc} #{fixture} -o #{bundle} #{f} #{o} #{a}`
+ end
+ end
+
+ def load!
+ require bundle[0..-8]
+ if File.exist? bridge_support
+ load_bridge_support_file bridge_support
+ end
+ end
+end
+
+MACOSX_VERSION = `sw_vers -productVersion`.to_f

0 comments on commit b57f656

Please sign in to comment.