-
Notifications
You must be signed in to change notification settings - Fork 88
/
Rakefile
105 lines (88 loc) · 2.7 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
# -*- ruby -*-
require "bundler/gem_tasks"
require 'rdoc/task'
spec = Gem::Specification.load("racc.gemspec")
RDoc::Task.new(:docs) do |rd|
rd.main = "README.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
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', 'lib/racc/info.rb', __FILE__] do |t|
source = 'lib/racc/parser.rb'
text = File.read(source)
text.sub!(/\A# *frozen[-_]string[-_]literal:.*\n/, '')
text.gsub!(/^require '(.*)'$/) do
lib = $1
code = File.read("lib/#{lib}.rb")
code.sub!(/\A(?:#.*\n)+/, '')
%[unless $".find {|p| p.end_with?('/#{lib}.rb')}\n$".push "\#{__dir__}/#{lib}.rb"\n#{code}\nend\n]
rescue
$&
end
File.open(t.name, 'wb') { |io|
io.write(<<-eorb)
module Racc
PARSER_TEXT = <<'__end_of_file__'
#{text}
__end_of_file__
end
eorb
}
end
javasrc, = Dir.glob('ext/racc/**/Cparse.java')
task :compile => javasrc do
code = File.binread(javasrc)
if code.sub!(/RACC_VERSION\s*=\s*"\K([^"]*)(?=")/) {|v| break if v == spec.version; spec.version}
File.binwrite(javasrc, code)
end
end
lib_dir = nil # for dummy rake/extensiontask.rb at ruby test-bundled-gems
if jruby?
# JRUBY
require "rake/javaextensiontask"
extask = Rake::JavaExtensionTask.new("cparse") do |ext|
jruby_home = RbConfig::CONFIG['prefix']
lib_dir = (ext.lib_dir << "/#{ext.platform}/racc")
ext.ext_dir = 'ext/racc'
# source/target jvm
ext.source_version = '1.8'
ext.target_version = '1.8'
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 :build => "#{extask.lib_dir}/#{extask.name}.jar"
else
# MRI
require "rake/extensiontask"
extask = Rake::ExtensionTask.new "cparse" do |ext|
lib_dir = (ext.lib_dir << "/#{RUBY_VERSION}/#{ext.platform}/racc")
ext.ext_dir = 'ext/racc/cparse'
end
end
desc 'Make autogenerated sources'
task :srcs => ['lib/racc/parser-text.rb']
task :compile => :srcs
task :build => :srcs
task :test => :compile
require 'rake/testtask'
Rake::TestTask.new(:test) do |t|
t.libs << lib_dir if lib_dir
t.libs << "test/lib"
ENV["RUBYOPT"] = "-I" + t.libs.join(File::PATH_SEPARATOR)
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