/
spec_helper.rb
58 lines (44 loc) · 1.39 KB
/
spec_helper.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
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