forked from ruby/prism
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Rakefile
115 lines (93 loc) · 2.74 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
# frozen_string_literal: true
require "rake/extensiontask"
require "rake/testtask"
require "rake/clean"
task compile: :make
Rake::ExtensionTask.new(:compile) do |ext|
ext.name = "yarp"
ext.ext_dir = "ext/yarp"
ext.lib_dir = "lib/yarp"
ext.gem_spec = Gem::Specification.load("yarp.gemspec")
end
Rake::TestTask.new(test: :compile) do |t|
t.libs << "test"
t.libs << "lib"
t.test_files = FileList["test/**/*_test.rb"]
end
task default: :test
TEMPLATES = [
"ext/yarp/node.c",
"lib/yarp/node.rb",
"lib/yarp/serialize.rb",
"java/org/yarp/Loader.java",
"java/org/yarp/Nodes.java",
"java/org/yarp/AbstractNodeVisitor.java",
"src/ast.h",
"src/node.c",
"src/node.h",
"src/prettyprint.c",
"src/serialize.c",
"src/token_type.c",
]
desc "Generate all ERB template based files"
task templates: TEMPLATES
task make: :templates do
sh "make"
end
task generate_compilation_database: :templates do
sh "which bear"
abort("Installing bear is required to generate the compilation database") unless $?.success?
sh "bear -- make"
end
# So `rake clobber` will delete generated files
CLOBBER.concat(TEMPLATES)
TEMPLATES.each do |filepath|
desc "Template #{filepath}"
file filepath => ["bin/templates/#{filepath}.erb", "config.yml"] do |t|
require_relative "bin/template"
template(t.name, locals)
end
end
desc "Lex ruby/spec files and compare with lex_compat"
task lex: :compile do
$:.unshift(File.expand_path("lib", __dir__))
require "yarp"
require "ripper"
results = { passing: [], failing: [] }
colorize = ->(code, string) { "\033[#{code}m#{string}\033[0m" }
accepted_encodings = [
Encoding::ASCII_8BIT,
Encoding::ISO_8859_9,
Encoding::US_ASCII,
Encoding::UTF_8
]
filepaths =
if ENV["FILEPATHS"]
Dir[ENV["FILEPATHS"]]
else
Dir["vendor/spec/**/*.rb"]
end
filepaths.each do |filepath|
source = File.read(filepath)
# If this file can't be parsed at all, then don't try to compare it to
# ripper's output.
ripper = Ripper.new(source).tap(&:parse)
next if ripper.error?
# If this file has an encoding that we don't support, then don't try to
# compare it to ripper's output.
unless accepted_encodings.include?(ripper.encoding)
print colorize.call(31, "E")
results[:failing] << filepath
next
end
result =
YARP.lex_ripper(source).zip(YARP.lex_compat(source)).all? do |(ripper, yarp)|
break false if yarp.nil?
ripper[0...-1] == yarp[0...-1]
end
print result ? colorize.call(32, ".") : colorize.call(31, "E")
results[result ? :passing : :failing] << filepath
end
puts "\n\nPASSING=#{results[:passing].length}\nFAILING=#{results[:failing].length}"
puts "\n#{results[:failing].sort.join("\n")}"
end