/
Rakefile
142 lines (109 loc) · 2.94 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
134
135
136
137
138
139
140
141
142
# Author: Chris Wailes <chris.wailes@gmail.com>
# Project: Ruby Language Toolkit
# Date: 2011/04/06
# Description: This is RLTK's Rakefile.
##############
# Rake Tasks #
##############
require 'rake/testtask'
require 'bundler'
require File.expand_path("../lib/rltk/version", __FILE__)
begin
require 'rdoc/task'
RDoc::Task.new do |t|
t.title = 'The Ruby Language Toolkit'
t.main = 'README'
t.rdoc_dir = 'doc'
t.rdoc_files.include('README', 'lib/*.rb', 'lib/rltk/*.rb', 'lib/rltk/**/*.rb')
end
rescue LoadError
warn 'RDoc is not installed.'
end
begin
require 'rcov/rcovtask'
Rcov::RcovTask.new do |t|
t.libs << 'test'
t.rcov_opts << '--exclude gems,ruby'
t.test_files = FileList['test/tc_*.rb']
end
rescue LoadError
warn 'Rcov not installed.'
end
Rake::TestTask.new do |t|
t.libs << 'test'
t.loader = :testrb
t.test_files = FileList['test/ts_rltk.rb']
end
Bundler::GemHelper.install_tasks
task :check_bindings, :verbose do |t, args|
(args = args.to_hash)[:verbose] = (args[:verbose] == 'true')
require 'lib/rltk/cg/bindings'
# Check for objdump.
if not (bin = `which objdump`.chomp)[0,1] == '/'
warn 'objdump binary not found.'
return
end
# Locate the LLVM shared library.
lib_path = nil
paths = ENV['LD_LIBRARY_PATH'].split(/:/).uniq
paths << '/usr/lib/'
paths << '/usr/lib64/'
paths.each do |path|
test_path = File.join(path, "libLLVM-#{RLTK::LLVM_TARGET_VERSION}.so")
if File.exists?(test_path)
lib_path = test_path
end
end
if not lib_path
puts "libLLVM-#{RLTK::LLVM_TARGET_VERSION}.so not found."
return
end
# Grab libLLVM symbols.
lines = `#{bin} -t #{lib_path}`
lsyms = lines.map do |l|
md = l.match(/\s(LLVM\w+)/)
if md then md[1] else nil end
end.compact.uniq
# Grab libLLVM-EB symbols.
lib_path = "ext/libLLVM-ECB-#{RLTK::LLVM_TARGET_VERSION}.so"
if not File.exists?(lib_path)
puts 'Extending Bindings shared library not present.'
return
end
lines = `#{bin} -t #{lib_path}`
lsyms |= lsyms = lines.map do |l|
md = l.match(/\s(LLVM\w+)/)
if md then md[1] else nil end
end.compact.uniq
# Defined symbols.
dsyms = Symbol.all_symbols.map do |sym|
sym = sym.to_s
if sym.match(/^LLVM[a-zA-Z]+/) then sym else nil end
end.compact
# Sort the symbols.
bound = Array.new
unbound = Array.new
unbinds = Array.new
lsyms.each do |sym|
if dsyms.include?(sym) then bound else unbound end << sym
end
dsyms.each do |sym|
if not lsyms.include?(sym) then unbinds << sym end
end
puts "Bound Functions: #{bound.length}"
puts "Unbound Functions: #{unbound.length}"
puts "Bad Bindings: #{unbinds.length}"
puts "Completeness: #{((bound.length / lsyms.length.to_f) * 100).to_i}%"
if args[:verbose]
puts() if unbound.length > 0 and unbinds.length > 0
if unbound.length > 0
puts 'Unbound Functions:'
unbound.sort.each {|sym| puts sym}
puts
end
if unbinds.length > 0
puts 'Bad Bindings:'
unbinds.sort.each {|sym| puts sym}
end
end
end