Repository navigation
Expand file tree
/
Copy pathRakefile
More file actions
104 lines (82 loc) · 2.86 KB
/
Copy pathRakefile
File metadata and controls
104 lines (82 loc) · 2.86 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
# frozen_string_literal: true
require "json"
require "open3"
require "bundler/gem_tasks"
require "rubocop/rake_task"
require "rake/extensiontask"
require "rake/testtask"
require "rdoc/task"
GEMSPEC = Gem::Specification.load("rubydex.gemspec")
Rake::ExtensionTask.new("rubydex", GEMSPEC) do |ext|
ext.lib_dir = "lib/rubydex"
end
test_config = lambda do |t|
t.libs << "test"
t.libs << "lib"
t.ruby_opts << ["--enable=frozen_string_literal"]
t.test_files = FileList["test/**/*_test.rb"]
end
Rake::TestTask.new(ruby_test: :compile, &test_config)
begin
require "ruby_memcheck"
namespace(:ruby_test) do
RubyMemcheck::TestTask.new(valgrind: :compile) do |task|
test_config.call(task)
task.test_files = FileList["test/**/*_test.rb"].exclude("test/integration/**/*_test.rb", "test/cli_test.rb")
end
end
rescue LoadError
# ruby_memcheck is not available on Windows
end
RuboCop::RakeTask.new
RDoc::Task.new do |doc|
doc.rdoc_dir = "_site"
end
task :lint do
puts "******** Linting ********\n"
Rake::Task["rubocop"].invoke
Rake::Task["lint_rust"].invoke
end
task :format do
puts "******** Formatting ********\n"
Rake::Task["rubocop:autocorrect"].invoke
Rake::Task["format_rust"].invoke
end
# Enhance the clean task to also clean Rust artifacts
Rake::Task[:clean].enhance([:clean_rust])
desc "Generate the Ruby classes for the graph's built-in rules"
task :generate_rules do
sh "cargo run --quiet --bin generate_ruby_rules", chdir: "rust"
end
task compile: :generate_rules
task compile_release: :clean do
ENV["RELEASE"] = "true"
Rake::Task[:compile].invoke
end
desc "Sync the gem version and crate dependency with the Cargo workspace version"
task :sync_versions do
metadata, status = Open3.capture2(
"cargo", "metadata", "--no-deps", "--offline", "--format-version=1", "--manifest-path=rust/Cargo.toml"
)
abort "Could not read the Cargo workspace version" unless status.success?
packages = JSON.parse(metadata).fetch("packages")
rubydex_package = packages.find { |package| package.fetch("name") == "rubydex" }
abort "Could not find rubydex in Cargo metadata" unless rubydex_package
cargo_version = rubydex_package.fetch("version")
gem_version = cargo_version.sub(/-beta\.(\d+)\z/) { ".beta#{Regexp.last_match(1)}" }
replacements = {
"lib/rubydex/version.rb" => [/^ VERSION = "[^"]+"$/, " VERSION = #{gem_version.inspect}"],
"rust/rubydex-sys/Cargo.toml" => [/^rubydex = \{ version = "[^"]+"/, "rubydex = { version = \"=#{cargo_version}\""],
}
updated_files = replacements.to_h do |path, (pattern, replacement)|
contents = File.read(path)
abort("Could not find the version in #{path}") unless contents.sub!(pattern, replacement)
[path, contents]
end
updated_files.each do |path, contents|
File.write(path, contents)
end
end
task test: [:cargo_test, :ruby_test]
task check: [:lint, :test]
task default: :check