This repository has been archived by the owner on Aug 18, 2018. It is now read-only.
/
Rakefile
112 lines (90 loc) · 3.18 KB
/
Rakefile
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
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
require "rubygems"
require "hoe"
require 'erb'
require "./lib/johnson/version.rb"
# what sort of extension are we building?
kind = Config::CONFIG["DLEXT"]
GENERATED_NODE = "ext/spidermonkey/immutable_node.c"
Hoe.new("johnson", Johnson::VERSION) do |p|
p.rubyforge_name = "johnson"
p.author = "John Barnette"
p.email = "jbarnette@rubyforge.org"
p.summary = "Johnson wraps JavaScript in a loving Ruby embrace."
p.description = p.paragraphs_of("README.txt", 2..5).join("\n\n")
p.url = p.paragraphs_of("README.txt", 0).first.split(/\n/)[1..-1]
p.changes = p.paragraphs_of("History.txt", 0..1).join("\n\n")
p.clean_globs = [
"lib/johnson/spidermonkey.#{kind}",
"ext/spidermonkey/Makefile",
"ext/spidermonkey/*.{o,so,bundle,log}",
GENERATED_NODE,
"vendor/spidermonkey/**/*.OBJ"]
p.test_globs = ["test/**/*_test.rb"]
p.spec_extras = { :extensions => ["ext/spidermonkey/extconf.rb"] }
end
# make sure the C bits are up-to-date when testing
Rake::Task[:test].prerequisites << :extensions
Rake::Task[:check_manifest].prerequisites << GENERATED_NODE
task :build => :extensions
# gem depends on the native extension actually building
Rake::Task[:gem].prerequisites << :extensions
desc "Our johnson requires extensions."
task :extensions => ["lib/johnson/spidermonkey.#{kind}"]
task :spidermonkey => :submodules do
if ENV['CROSS']
Dir.chdir("vendor/spidermonkey") { sh "make -f Makefile.ref OS_CONFIG=#{ENV['CROSS']}" }
else
Dir.chdir("vendor/spidermonkey") { sh "make -f Makefile.ref" }
end
end
task :spidermonkey => "vendor/spidermonkey/config/#{ENV['CROSS']}.mk" if ENV['CROSS']
file "vendor/spidermonkey/config/MINGW32.mk" => "MINGW32.mk" do |t|
File.copy(t.prerequisites.first, t.name)
end
task :submodules do
sh "git submodule init && git submodule update"
end
file "ext/spidermonkey/spidermonkey.#{kind}" =>
["ext/spidermonkey/Makefile"] + FileList["ext/spidermonkey/*.{c,h}"].to_a do
Dir.chdir("ext/spidermonkey") { sh "make" }
end
# for testing, we toss the SpiderMonkey extension in lib/johnson
file "lib/johnson/spidermonkey.#{kind}" =>
"ext/spidermonkey/spidermonkey.#{kind}" do |t|
File.copy(t.prerequisites.first, t.name)
end
file "ext/spidermonkey/Makefile" =>
[:spidermonkey, GENERATED_NODE, "ext/spidermonkey/extconf.rb"] do
dirs = (ENV['CROSS'] ? [ENV["CROSSLIB"]] : []) + $:
command = ["ruby"] + dirs.map{|dir| "-I#{File.expand_path dir}"} + ["extconf.rb"]
Dir.chdir("ext/spidermonkey") { sh *command }
end
def jsops
ops = []
File.open('vendor/spidermonkey/jsopcode.tbl', 'rb') { |f|
f.each_line do |line|
if line =~ /^OPDEF\((\w+),/
ops << $1
end
end
}
ops
end
def tokens
toks = []
File.open('vendor/spidermonkey/jsscan.h', 'rb') { |f|
f.each_line do |line|
line.scan(/TOK_\w+/).each do |token|
next if token == 'TOK_ERROR'
toks << token
end
end
}
toks.uniq
end
file GENERATED_NODE => ["ext/spidermonkey/immutable_node.c.erb", "vendor/spidermonkey/jsopcode.tbl", "vendor/spidermonkey/jsscan.h"] do |t|
template = ERB.new(File.open(t.prerequisites.first, 'rb') { |x| x.read })
File.open(GENERATED_NODE, 'wb') { |f|
f.write template.result(binding)
}
end