-
Notifications
You must be signed in to change notification settings - Fork 111
/
Rakefile
282 lines (238 loc) Β· 7.29 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
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
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
# frozen_string_literal: true
require 'open-uri'
require 'shellwords'
require 'bundler/audit/task'
require 'rubocop/rake_task'
require 'tomlrb'
task default: %i[format lint]
desc 'Lint sources'
task lint: %i[lint:clippy lint:rubocop:autocorrect]
namespace :lint do
RuboCop::RakeTask.new(:rubocop)
desc 'Lint Rust sources with Clippy'
task :clippy do
sh 'cargo clippy --workspace --all-features --all-targets'
Dir.chdir('spec-runner') do
sh 'cargo clippy --workspace --all-features --all-targets'
end
Dir.chdir('ui-tests') do
sh 'cargo clippy --workspace --all-features --all-targets'
end
end
desc 'Lint Rust sources with Clippy restriction pass (unenforced lints)'
task :'clippy:restriction' do
lints = [
'clippy::dbg_macro',
'clippy::get_unwrap',
'clippy::indexing_slicing',
'clippy::panic',
'clippy::print_stdout',
'clippy::expect_used',
'clippy::unwrap_used',
'clippy::todo',
'clippy::unimplemented',
'clippy::unreachable'
]
command = ['cargo', 'clippy', '--'] + lints.flat_map { |lint| ['-W', lint] }
sh command.shelljoin
end
end
desc 'Format sources'
task format: %i[format:rust format:text format:c]
namespace :format do
desc 'Format Rust sources with rustfmt'
task :rust do
sh 'rustup run --install nightly cargo fmt -- --color=auto'
Dir.chdir('spec-runner') do
sh 'rustup run --install nightly cargo fmt -- --color=auto'
end
Dir.chdir('ui-tests') do
sh 'rustup run --install nightly cargo fmt -- --color=auto'
end
end
desc 'Format text, YAML, and Markdown sources with prettier'
task :text do
sh 'npm run fmt'
end
desc 'Format .c and .h sources with clang-format'
task :c do
sh 'npm run fmt:c'
end
end
desc 'Format sources'
task fmt: %i[fmt:rust fmt:text fmt:c]
namespace :fmt do
desc 'Format Rust sources with rustfmt'
task :rust do
sh 'rustup run --install nightly cargo fmt -- --color=auto'
Dir.chdir('spec-runner') do
sh 'rustup run --install nightly cargo fmt -- --color=auto'
end
Dir.chdir('ui-tests') do
sh 'rustup run --install nightly cargo fmt -- --color=auto'
end
end
desc 'Format text, YAML, and Markdown sources with prettier'
task :text do
sh 'npm run fmt'
end
desc 'Format .c and .h sources with clang-format'
task :c do
sh 'npm run fmt:c'
end
end
desc 'Build Rust workspace'
task :build do
sh 'cargo build --workspace'
end
desc 'Build Rust workspace and sub-workspaces'
task :'build:all' do
sh 'cargo build --workspace'
Dir.chdir('fuzz') do
sh 'cargo build --workspace'
end
Dir.chdir('spec-runner') do
sh 'cargo build --workspace'
end
Dir.chdir('ui-tests') do
sh 'cargo build --workspace'
end
end
desc 'Generate Rust API documentation'
task :doc do
ENV['RUSTDOCFLAGS'] = '-D warnings -D rustdoc::broken_intra_doc_links --cfg docsrs'
sh 'rustup run --install nightly cargo doc --workspace'
end
desc 'Generate Rust API documentation and open it in a web browser'
task :'doc:open' do
ENV['RUSTDOCFLAGS'] = '-D warnings -D rustdoc::broken_intra_doc_links --cfg docsrs'
sh 'rustup run --install nightly cargo doc --workspace --open'
end
desc 'Run enforced ruby/spec suite'
task :spec do
Dir.chdir('spec-runner') do
sh 'cargo run -q -- enforced-specs.toml'
end
end
desc 'Run Artichoke unit tests'
task test: %i[test:unit]
namespace :test do
# TODO: Add fuzz into all list when tests work
desc 'Run all tests'
task all: %i[unit ui]
desc 'Run fuzz tests (Fuzz the interpreter for crashes with arbitrary input)'
task :fuzz do
Dir.chdir('fuzz') do
sh 'cargo test --workspace'
end
end
desc 'Run ui tests (check exact stdout/stderr of Artichoke binaries)'
task :ui do
sh 'cargo build'
Dir.chdir('ui-tests') do
sh 'cargo test --workspace'
end
end
desc 'Run unit tests'
task :unit do
sh 'cargo test --workspace'
end
end
desc 'Run Artichoke with LeakSanitizer'
task :'sanitizer:leak' do
ENV['RUSTFLAGS'] = '-Z sanitizer=leak'
ENV['RUST_BACKTRACE'] = '1'
host = `rustc -vV | grep host | cut -d' ' -f2`.chomp
command = ['rustup', 'run', '--install', 'nightly', 'cargo', 'test', '--workspace', '--all-features', '--target', host]
sh command.shelljoin
end
Bundler::Audit::Task.new
namespace :release do
link_check_files = FileList.new('**/*.md') do |f|
f.exclude('node_modules/**/*')
f.exclude('**/target/**/*')
f.exclude('**/vendor/*/**/*')
f.include('*.md')
f.include('**/vendor/*.md')
end
link_check_files.uniq.sort.each do |markdown|
desc 'Check for broken links in markdown files'
task markdown_link_check: markdown do
command = ['npx', 'markdown-link-check', '--config', '.github/markdown-link-check.json', markdown]
sh command.shelljoin
sleep(rand(1..5))
end
end
end
namespace :toolchain do
desc 'Sync Rust toolchain to all sources'
task sync: %i[sync:manifests sync:ci]
rust_toolchain = Tomlrb.load_file('rust-toolchain.toml', symbolize_keys: true)
toolchain_version = rust_toolchain[:toolchain][:channel]
namespace :sync do
desc 'Sync the root rust-toolchain version to all crate manifests'
task :manifests do
regexp = /^rust-version = "(.*)"$/
next_rust_version = "rust-version = \"#{toolchain_version}\""
pkg_files = FileList.new(['Cargo.toml', 'fuzz/Cargo.toml', 'spec-runner/Cargo.toml', 'ui-tests/Cargo.toml'])
failures = pkg_files.map do |file|
contents = File.read(file)
if (existing_version = contents.match(regexp))
File.write(file, contents.gsub(regexp, next_rust_version)) if existing_version != next_rust_version
next
end
puts "Failed to update #{file}, ensure there is a rust-version specified" if Rake.verbose
file
end.compact
raise 'Failed to update some rust-versions' if failures.any?
end
desc 'Sync the root rust-toolchain version to CI jobs'
task :ci do
workflow_files = FileList.new('.github/workflows/*.yaml')
workflow_files.each do |file|
contents = File.read(file)
contents = contents.gsub(/(toolchain: "?)\d+\.\d+\.\d+("?)/, "\\1#{toolchain_version}\\2")
File.write(file, contents)
end
end
end
end
KNOWN_WORKSPACE_PREFIXES = %w[
artichoke
mezzaluna
scolapasta
spinoso
].freeze
KNOWN_FIRST_PARTY = %w[
focaccia
intaglio
known-folders
posix-space
qed
rand_mt
raw-parts
roe
strftime-ruby
sysdir
].freeze
namespace :deps do
desc 'List first-party crate dependencies'
task :firstparty do
deps = File.readlines('Cargo.lock', chomp: true)
.select { |line| line.start_with?('name = ') }
.map { |line| line.delete_prefix('name = "') }
.map { |line| line.delete_suffix('"') }
.select { |dep| KNOWN_FIRST_PARTY.include?(dep) || KNOWN_WORKSPACE_PREFIXES.any? { |prefix| dep.include?(prefix) } }
puts deps
end
desc 'List third-party crate dependencies'
task :thirdparty do
deps = File.readlines('Cargo.lock', chomp: true)
.select { |line| line.start_with?('name = ') }
.map { |line| line.delete_prefix('name = "') }
.map { |line| line.delete_suffix('"') }
.reject { |dep| KNOWN_FIRST_PARTY.include?(dep) }
.reject { |dep| KNOWN_WORKSPACE_PREFIXES.any? { |prefix| dep.include?(prefix) } }
puts deps
end
end