/
Rakefile
133 lines (106 loc) · 3.15 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
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
# -*- ruby -*-
require 'rake'
require 'rake/testtask'
require 'rake/rdoctask'
def run(name)
Task[name].execute
end
def task(args, &block)
case args
when Symbol
Rake::Task.define_task(args, &block)
when Hash
args.each_pair do |k,v|
Rake::Task.define_task(k => v, &block)
end
when Array
args.each do |subtask|
Rake::Task.define_task(subtask, &block)
end
end
end
# class => file
CLASSES = {
"TrueClass" => "true_class",
"FalseClass" => "false_class",
"NilClass" => "nil_class",
"Time" => "newtime",
"Array" => "array",
"Range" => "range",
"Hash" => "hash",
"String" => "string",
"Comparable" => "comparable",
"Exception" => "exception",
"FileTest" => "file_test",
"Struct" => "struct",
}
C_FILES = CLASSES.values.map { |c| "#{c}.c" }
task :default => C_FILES
task :clean do |t|
rm %w(*~ *.c *.o *.$(SHLIB_EXT) ~/.ruby_inline *.a *.pass *.cache).map { |pat| Dir[pat] }.flatten
end
RUBY2C = File.expand_path "../../ruby_to_c/dev"
BFTS = File.expand_path "../../bfts/dev"
inc = %w(ruby_to_c/dev/lib ParseTree/dev/lib RubyInline/dev/lib bfts/dev).map { |p| File.expand_path "../../#{p}" }
RUBY_FLAGS = %(-w -Ilib:bin:#{inc.join(':')})
task :test => [ :clean, :default ]
rule '.pass' => ['.rb'] do |t|
Dir.chdir BFTS do
ruby %(-I../../metaruby/dev:../../RubyInline/dev/lib -r#{t.source} test_#{t.source} #{ENV['FILTER']})
end
touch t.name
end
rule '.c' => ['.pass'] do |t|
rb_file = File.basename(t.source, '.pass') + '.rb'
ruby %(#{RUBY_FLAGS} #{RUBY2C}/bin/ruby_to_c_translate -c=#{File.basename t.name, '.c'} ./#{rb_file} > #{t.name})
end
# so you can type `make Time` to just run Time tests
# makefile version -- so clean:
# $(CLASSES):
# (cd $(BFTS); $(RUBY) -I../../../metaruby/dev:.. -r$@ Test$@.rb $(FILTER))
# initial cut, and I think the "right way" to do it in rake:
# CLASSES.each do |file,klass|
# task klass do |t|
# Dir.chdir BFTS do
# ruby %(-I../../metaruby/dev -r#{file} test_#{file}.rb)
# end
# end
# end
# with new task method above
# task CLASSES.keys do |t|
# Dir.chdir BFTS do
# ruby %(-I../../metaruby/dev -r#{CLASSES[t.name]} test_#{CLASSES[t.name]}.rb #{ENV['FILTER']})
# end
# end
# instead of:
# CLASSES.each do |k,n|
# task k => n
# end
# do this:
task CLASSES # maps TrueClass -> true_class
task CLASSES.values do |t|
Dir.chdir BFTS do
ruby %(-I../../metaruby/dev -r#{t.name} test_#{t.name}.rb #{ENV['FILTER']})
end
end
task :sort do
Dir["**/*.rb"].each do |f|
sh %(grep "^ *def " #{f} | grep -v "def self" > x; sort x > y; echo; echo #{f}; echo; diff x y; true)
end
rm %w(x y)
end
# AUDITFILES = $(patsubst %,%.audit.rb,$(CLASSES))
# OFILES = $(patsubst %,%.o,$(CLASSES))
# SHLIB_EXT = $(shell ruby -rrbconfig -e 'puts Config::CONFIG["DLEXT"]')
# LINKER = $(shell ruby -rrbconfig -e 'puts Config::CONFIG["LDSHARED"]')
# %.audit.rb: %.rb bfts/Test%.rb Makefile
# $(RUBY) ../../ZenTest/dev/ZenTest.rb $*.rb bfts/Test$*.rb
# metaruby: metaruby.$(SHLIB_EXT)
# metaruby.$(SHLIB_EXT): $(OFILES)
# $(LINKER) $^ -o $@
# libmetaruby.a: $(OFILES)
# rm $@; ar r $@ $^ && ranlib $@
# FORCE:
# doc: FORCE
# rm -rf doc ; rdoc -x bfts .
# audit: $(AUDITFILES)