-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathRakefile
88 lines (73 loc) · 2.09 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
# -*- ruby -*-
require "bundler/gem_tasks"
require 'rdoc/task'
RDoc::Task.new(:docs) do |rd|
spec = Gem::Specification.load("racc.gemspec")
rd.main = "README.en.rdoc"
rd.rdoc_files.include(spec.files.find_all { |file_name|
file_name =~ /^(bin|lib|ext)/ || file_name !~ /\//
})
title = "#{spec.name}-#{spec.version} Documentation"
rd.options << "-t #{title}"
end
require 'rake/testtask'
Rake::TestTask.new(:test) do |t|
t.libs << "test/lib"
t.ruby_opts << "-rhelper"
t.test_files = FileList["test/**/test_*.rb"]
if RUBY_VERSION >= "2.6"
t.ruby_opts << "--enable-frozen-string-literal"
t.ruby_opts << "--debug=frozen-string-literal" if RUBY_ENGINE != "truffleruby"
end
end
gem 'rake-compiler', '>= 0.4.1'
def java?
/java/ === RUBY_PLATFORM
end
def jruby?
Object.const_defined?(:RUBY_ENGINE) and 'jruby' == RUBY_ENGINE
end
file 'lib/racc/parser-text.rb' => ['lib/racc/parser.rb'] do |t|
source = 'lib/racc/parser.rb'
text = File.read(source)
text.gsub!(/^require '(.*)'$/) do
%[unless $".find {|p| p.end_with?('/#$1.rb')}\n$".push '#$1.rb'\n#{File.read("lib/#{$1}.rb")}\nend\n]
rescue
$&
end
open(t.name, 'wb') { |io|
io.write(<<-eorb)
module Racc
PARSER_TEXT = <<'__end_of_file__'
#{text}
__end_of_file__
end
eorb
}
end
if jruby?
# JRUBY
require "rake/javaextensiontask"
Rake::JavaExtensionTask.new("cparse") do |ext|
jruby_home = RbConfig::CONFIG['prefix']
ext.lib_dir = File.join 'lib', 'racc'
ext.ext_dir = File.join 'ext', 'racc'
# source/target jvm
ext.source_version = '1.7'
ext.target_version = '1.7'
jars = ["#{jruby_home}/lib/jruby.jar"] + FileList['lib/*.jar']
ext.classpath = jars.map { |x| File.expand_path x }.join( ':' )
ext.name = 'cparse-jruby'
end
task :compile => ['lib/racc/parser-text.rb']
else
# MRI
require "rake/extensiontask"
Rake::ExtensionTask.new "cparse" do |ext|
ext.lib_dir = File.join 'lib', 'racc'
ext.ext_dir = File.join 'ext', 'racc', 'cparse'
end
task :compile => 'lib/racc/parser-text.rb'
end
task :build => "lib/racc/parser-text.rb"
task :test => :compile