-
-
Notifications
You must be signed in to change notification settings - Fork 80
Expand file tree
/
Copy pathRakefile
More file actions
262 lines (207 loc) · 6.68 KB
/
Rakefile
File metadata and controls
262 lines (207 loc) · 6.68 KB
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
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
# frozen_string_literal: true
require "English"
require "bundler/gem_tasks"
require "rake/testtask"
Rake::TestTask.new(:test) do |t|
t.libs << "test"
t.libs << "lib"
t.test_files = FileList["test/**/*_test.rb"].exclude("test/engine/**/*_test.rb", "test/integration/**/*_test.rb")
end
task :test_tip do
puts "TIP: This only runs core tests. Other test tasks available:"
puts " rake test:all"
puts " rake test:engine"
puts " rake test:integration"
puts
end
Rake::Task[:test].enhance([:test_tip])
Rake::TestTask.new("test:engine") do |t|
t.libs << "test"
t.libs << "lib"
t.test_files = FileList["test/engine/**/*_test.rb"]
end
Rake::TestTask.new("test:integration") do |t|
t.libs << "test"
t.libs << "lib"
t.test_files = FileList["test/integration/**/*_test.rb"]
end
Rake::TestTask.new("test:all") do |t|
t.libs << "test"
t.libs << "lib"
t.test_files = FileList["test/**/*_test.rb"]
end
task "make" do
puts "Running make..."
IO.popen("make") do |output|
output.each_line do |line|
puts line
end
end
end
begin
require "rake/extensiontask"
PLATFORMS = [
"aarch64-linux-gnu",
"aarch64-linux-musl",
"arm-linux-gnu",
"arm-linux-musl",
"arm64-darwin",
"x86_64-darwin",
"x86_64-linux-gnu",
"x86_64-linux-musl",
"x86-linux-gnu",
"x86-linux-musl"
].freeze
exttask = Rake::ExtensionTask.new do |ext|
ext.name = "herb"
ext.source_pattern = "*.{c,h}"
ext.ext_dir = "ext/herb"
ext.lib_dir = "lib/herb"
ext.gem_spec = Gem::Specification.load("herb.gemspec")
ext.cross_compile = true
ext.cross_platform = PLATFORMS
end
Rake::Task[:compile].enhance do
raise "src/* could not be compiled #{$CHILD_STATUS.exitstatus}" if $CHILD_STATUS.exitstatus != 0
end
Rake::Task[:clean].enhance do
IO.popen("make clean") do |output|
output.each_line do |line|
puts line
end
end
end
task "gem:native" do
require "rake_compiler_dock"
sh "bundle config set cache_all true"
PLATFORMS.each do |platform|
RakeCompilerDock.sh "bundle --local && rake native:#{platform} gem", platform: platform
end
RakeCompilerDock.sh "bundle --local && rake java gem", rubyvm: :jruby
rescue LoadError
abort "rake_compiler_dock is required to build native gems"
end
namespace "gem" do
task "prepare" do
require "rake_compiler_dock"
require "io/console"
sh "bundle config set cache_all true"
sh "cp ~/.gem/gem-*.pem build/gem/ || true"
gemspec_path = File.expand_path("./herb.gemspec", __dir__)
spec = eval(File.read(gemspec_path), binding, gemspec_path)
RakeCompilerDock.set_ruby_cc_version(spec.required_ruby_version.as_list)
# ENV["GEM_PRIVATE_KEY_PASSPHRASE"] = STDIN.getpass("Enter passphrase of gem signature key: ")
rescue LoadError
abort "rake_compiler_dock is required for this task"
end
exttask.cross_platform.each do |platform|
desc "Build all native binary gems in parallel"
multitask "native" => platform
desc "Build the native gem for #{platform}"
task platform => "prepare" do
RakeCompilerDock.sh(
"bundle --local && rake native:#{platform} gem RUBY_CC_VERSION='#{ENV.fetch("RUBY_CC_VERSION", nil)}'",
platform: platform
)
end
end
end
rescue LoadError => e
desc "Compile task not available (rake-compiler not installed)"
task :compile do
puts e
abort <<~MESSAGE
"rake-compiler is required for this task.
Are you running `rake` using `bundle exec rake`?
Otherwise
* try to run bundle install
* add it to your Gemfile
* or install it with: gem install rake-compiler
MESSAGE
end
end
desc "Render out template files"
task :templates do
require_relative "lib/herb/bootstrap"
Herb::Bootstrap.generate_templates
end
namespace :prism do
desc "Setup and vendor Prism"
task :vendor do
require_relative "lib/herb/bootstrap"
Rake::Task["prism:clean"].execute
prism_bundle_path = `bundle show prism`.chomp
if prism_bundle_path.empty?
puts "Make sure to run `bundle install` in the herb project directory first"
exit 1
end
puts prism_bundle_path
Herb::Bootstrap.vendor_prism(prism_gem_path: prism_bundle_path)
end
desc "Clean vendored Prism in vendor/prism/"
task :clean do
require_relative "lib/herb/bootstrap"
prism_vendor_path = Herb::Bootstrap::PRISM_VENDOR_DIR
puts "Cleaning up vendored Prism at #{prism_vendor_path}..."
begin
FileUtils.rm_r(prism_vendor_path)
puts "Cleaned up vendored Prism."
rescue Errno::ENOENT
puts "Vendored prism at: #{prism_vendor_path} didn't exist. Skipping."
end
end
end
namespace :templates do
desc "Watch template files and regenerate on changes"
task :watch do
require "listen"
Rake::Task[:templates].execute
puts
puts "Watching config.yml and templates/**/*.erb for changes..."
ignore = Dir.glob("*/").map { |dir| Regexp.escape(dir.chomp("/")) }.map { |dir| %r{^#{dir}/} }
config_listener = Listen.to(".", only: /config\.yml$/, ignore: ignore) do
puts
puts "#{Time.now.strftime("[%Y-%m-%d %H:%M:%S]")} config.yml changed, regenerating all templates ..."
puts
Rake::Task[:templates].execute
end
template_listener = Listen.to("templates", only: /\.erb$/) do |modified, added, removed|
puts
(added + modified).each do |template|
template_file = template.delete_prefix("#{__dir__}/")
puts "#{Time.now.strftime("[%Y-%m-%d %H:%M:%S]")} Detected change, regenerating #{template_file} ..."
Herb::Template.render(template_file)
end
removed.each do |template|
puts
puts "#{template} was removed. Make sure to also remove the generated file."
end
end
config_listener.start
template_listener.start
sleep
rescue LoadError
abort "listen gem is required for this task. Add it to your Gemfile or install it with: gem install listen"
end
end
namespace :parse do
desc "Parse ERB files in a project directory"
task :project, [:path, :output_file] do |_t, args|
require_relative "lib/herb"
Herb::Project.new(args[:path], output_file: args[:output_file]).parse!
end
end
task rbs_inline: :templates do
require "open3"
command = "bundle exec rbs-inline --opt-out --output=sig/ lib/"
_stdout, stderr, status = Open3.capture3(command)
puts "Running `#{command}`"
if stderr.strip == "🎉 Generated 0 RBS files under sig/"
puts "RBS files in sig/ are up to date"
exit status.exitstatus
else
puts "RBS files in sig/ are not up to date"
exit 1
end
end
task default: [:templates, "prism:vendor", :make, :compile, :test]