forked from whitequark/parser
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Rakefile
181 lines (144 loc) · 4.87 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
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
# encoding: utf-8
# frozen_string_literal: true
require 'bundler/gem_tasks'
require 'rake/testtask'
require 'rake/clean'
require 'date'
task :default => [:test]
Rake::TestTask.new do |t|
t.libs = %w(test/ lib/)
t.test_files = FileList["test/**/test_*.rb"]
t.warning = true
end
task :test_cov do
ENV['COVERAGE'] = '1'
Rake::Task['test'].invoke
end
task :build => [:generate_release, :changelog]
GENERATED_FILES = %w(lib/parser/lexer-F0.rb
lib/parser/lexer-F1.rb
lib/parser/lexer-strings.rb
lib/parser/ruby18.rb
lib/parser/ruby19.rb
lib/parser/ruby20.rb
lib/parser/ruby21.rb
lib/parser/ruby22.rb
lib/parser/ruby23.rb
lib/parser/ruby24.rb
lib/parser/ruby25.rb
lib/parser/ruby26.rb
lib/parser/ruby27.rb
lib/parser/ruby30.rb
lib/parser/ruby31.rb
lib/parser/ruby32.rb
lib/parser/ruby33.rb
lib/parser/ruby34.rb
lib/parser/macruby.rb
lib/parser/rubymotion.rb)
CLEAN.include(GENERATED_FILES)
ENCODING_COMMENT = "# -*- encoding:utf-8; warn-indent:false; frozen_string_literal: true -*-\n"
desc 'Generate the Ragel lexer and Racc parser.'
task :generate => GENERATED_FILES do
Rake::Task[:ragel_check].invoke
GENERATED_FILES.each do |filename|
content = File.read(filename)
content = ENCODING_COMMENT + content unless content.start_with?(ENCODING_COMMENT)
File.open(filename, 'w') do |io|
io.write content
end
end
end
task :regenerate => [:clean, :generate]
desc 'Generate the Ragel lexer and Racc parser in release mode.'
task :generate_release => [:clean_env, :regenerate]
task :clean_env do
ENV.delete 'RACC_DEBUG'
end
task :ragel_check do
require 'cliver'
Cliver.assert('ragel', '~> 6.7')
end
desc 'Generate YARD documentation'
task :yard => :generate do
sh('yard doc')
end
PAGES_REPO = 'git@github.com:whitequark/parser'
desc "Build and deploy documentation to GitHub pages"
task :pages do
system "git clone #{PAGES_REPO} gh-temp/ -b gh-pages; rm gh-temp/* -rf; touch gh-temp/.nojekyll" or abort
system "yardoc -o gh-temp/;" or abort
system "cd gh-temp/; git add -A; git commit -m 'Updated pages.'; git push -f origin gh-pages" or abort
FileUtils.rm_rf 'gh-temp'
end
desc 'Generate Changelog'
task :changelog do
fs = "\u{fffd}"
format = "%d#{fs}%s#{fs}%an#{fs}%ai"
# Format: version => { commit-class => changes }
changelog = Hash.new do |hash, version|
hash[version] = Hash.new do |hash, klass|
hash[klass] = []
end
end
branch = `git describe HEAD --all`.strip.gsub(/.+\/([^\/]+)$/, '\1')
IO.popen("git log --pretty='#{format}' " \
"remotes/origin/2.0 remotes/origin/2.1 remotes/origin/2.2 #{branch}", 'r') do |io|
current_version = nil
io.each_line do |line|
version, message, author, date = line.
match(/^(?: \((.*)\))?#{fs}(.*)#{fs}(.*)#{fs}(.*)$/o).captures
date = Date.parse(date)
current_version = "#{$1} (#{date})" if version =~ /(v[\d\w.]+)/
current_version = "Not released (#{date})" \
if version =~ /(^| |\/)#{Regexp.escape branch}$/ && !branch.start_with?('v')
next if current_version.nil?
changelog[current_version] # add a hash
next if message !~ /^[+*-]/
changelog[current_version][message[0]] << "#{message[1..-1]} (#{author})"
end
end
commit_classes = {
'*' => 'API modifications:',
'+' => 'Features implemented:',
'-' => 'Bugs fixed:',
}
File.open('CHANGELOG.md', 'w') do |io|
io.puts 'Changelog'
io.puts '========='
io.puts
changelog.each do |version, commits|
next if commits.empty?
io.puts version
io.puts '-' * version.length
io.puts
commit_classes.each do |sigil, description|
next unless commits[sigil].any?
io.puts description
commits[sigil].uniq.each do |commit|
io.puts " * #{commit.gsub('<', '\<').lstrip}"
end
io.puts
end
end
end
sh('git commit CHANGELOG.md -m "Update changelog." || true')
end
file 'lib/parser/lexer-F1.rb' => 'lib/parser/lexer.rl' do |t|
sh "ragel -F1 -R #{t.source} -o #{t.name}"
end
file 'lib/parser/lexer-F0.rb' => 'lib/parser/lexer.rl' do |t|
sh "ragel -F0 -R #{t.source} -o #{t.name}"
end
file 'lib/parser/lexer-strings.rb' => 'lib/parser/lexer-strings.rl' do |t|
sh "ragel -F0 -R #{t.source} -o #{t.name}"
end
rule '.rb' => '.y' do |t|
opts = [ "--superclass=Parser::Base",
t.source,
"-o", t.name
]
opts << "--no-line-convert" unless ENV['RACC_DEBUG']
opts << "--debug" if ENV['RACC_DEBUG']
sh "racc", *opts
end
task :test => [:generate]