forked from whitequark/parser
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Rakefile
130 lines (100 loc) · 2.97 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
# encoding:utf-8
require 'bundler/gem_tasks'
require 'rake/testtask'
require 'rake/clean'
task :default => [:test]
Rake::TestTask.new do |t|
t.libs = %w(test/ lib/)
t.test_files = FileList["test/**/test_*.rb"]
end
task :build => [:generate_release, :changelog]
GENERATED_FILES = %w(lib/parser/lexer.rb
lib/parser/ruby18.rb
lib/parser/ruby19.rb
lib/parser/ruby20.rb
lib/parser/ruby21.rb)
CLEAN.include(GENERATED_FILES)
desc 'Generate the Ragel lexer and Bison parser.'
task :generate => GENERATED_FILES do
Rake::Task[:ragel_check].invoke
GENERATED_FILES.each do |filename|
content = File.read(filename)
content = "# -*- encoding:utf-8; warn-indent:false -*-\n" + content
File.open(filename, 'w') do |io|
io.write content
end
end
end
task :regenerate => [:clean, :generate]
desc 'Generate the Ragel lexer and Bison 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
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
IO.popen("git log --pretty='#{format}' HEAD", '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 = "v#{Parser::VERSION} (#{date})" if version =~ /HEAD/
next if current_version.nil? || 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|
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].each do |commit|
io.puts " * #{commit.gsub('<', '\<').lstrip}"
end
io.puts
end
end
end
sh('git commit CHANGELOG.md -m "Update changelog."')
end
rule '.rb' => '.rl' do |t|
sh "ragel -R #{t.source} -o #{t.name}"
end
rule '.rb' => '.y' do |t|
opts = [ "--superclass=Parser::Base",
t.source,
"-o", t.name
]
opts << "--debug" if ENV['RACC_DEBUG']
sh "racc", *opts
end
task :test => [:generate]