-
Notifications
You must be signed in to change notification settings - Fork 0
/
Rakefile
112 lines (92 loc) · 2.93 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
# frozen_string_literal: true
$:.unshift File.expand_path('lib', __dir__) # default template dir
require_relative 'lib/rdoc/task'
require 'bundler/gem_tasks'
require 'rake/testtask'
task :test => [:normal_test, :rubygems_test]
PARSER_FILES = %w[
lib/rdoc/rd/block_parser.ry
lib/rdoc/rd/inline_parser.ry
lib/rdoc/markdown.kpeg
lib/rdoc/markdown/literals.kpeg
]
$rdoc_rakefile = true
task :default => :test
task rdoc: :generate
RDoc::Task.new do |doc|
doc.main = 'README.rdoc'
doc.title = "rdoc #{RDoc::VERSION} Documentation"
doc.rdoc_dir = '_site' # for github pages
doc.rdoc_files = FileList.new %w[lib/**/*.rb *.rdoc doc/rdoc/markup_reference.rb] - PARSER_FILES
end
task "coverage" do
cov = []
e = IO.popen([FileUtils::RUBY, "-I./lib", "exe/rdoc", "-C"], &:read)
e.scan(/^ *# in file (?<loc>.*)\n *(?<code>.*)|^ *(?<code>.*\S) *# in file (?<loc>.*)/) do
cov << "%s: %s\n" % $~.values_at(:loc, :code)
end
cov.sort!
puts cov
end
Rake::TestTask.new(:normal_test) do |t|
t.verbose = true
t.deps = :generate
t.libs << "test/lib"
t.ruby_opts << "-rhelper"
t.test_files = FileList["test/**/test_*.rb"].exclude("test/rdoc/test_rdoc_rubygems_hook.rb")
end
Rake::TestTask.new(:rubygems_test) do |t|
t.verbose = true
t.deps = :generate
t.pattern = "test/rdoc/test_rdoc_rubygems_hook.rb"
end
path = "pkg/#{Bundler::GemHelper.gemspec.full_name}"
package_parser_files = PARSER_FILES.map do |parser_file|
name = File.basename(parser_file, File.extname(parser_file))
_path = File.dirname(parser_file)
package_parser_file = "#{path}/#{name}.rb"
parsed_file = "#{_path}/#{name}.rb"
file package_parser_file => parsed_file # ensure copy runs before racc
package_parser_file
end
parsed_files = PARSER_FILES.map do |parser_file|
ext = File.extname(parser_file)
parsed_file = "#{parser_file.chomp(ext)}.rb"
file parsed_file => parser_file do |t|
puts "Generating #{parsed_file}..."
case ext
when '.ry' # need racc
racc = Gem.bin_path 'racc', 'racc'
rb_file = parser_file.gsub(/\.ry\z/, ".rb")
ruby "#{racc} -l -E -o #{rb_file} #{parser_file}"
File.open(rb_file, 'r+') do |f|
newtext = "# frozen_string_literal: true\n#{f.read}"
f.rewind
f.write newtext
end
when '.kpeg' # need kpeg
kpeg = Gem.bin_path 'kpeg', 'kpeg'
rb_file = parser_file.gsub(/\.kpeg\z/, ".rb")
ruby "#{kpeg} -fsv -o #{rb_file} #{parser_file}"
File.write(rb_file, File.read(rb_file).gsub(/ +$/, '')) # remove trailing spaces
end
end
parsed_file
end
task "#{path}.gem" => package_parser_files
desc "Generate all files used racc and kpeg"
task :generate => parsed_files
task :clean do
parsed_files.each do |path|
File.delete(path) if File.exist?(path)
end
end
begin
require 'rubocop/rake_task'
rescue LoadError
else
RuboCop::RakeTask.new(:rubocop) do |t|
t.options = [*parsed_files]
end
task :build => [:generate, "rubocop:autocorrect"]
end