Skip to content

Commit 8cff682

Browse files
committed
nits: Split rake rasks
1 parent c32c277 commit 8cff682

File tree

6 files changed

+125
-123
lines changed

6 files changed

+125
-123
lines changed

Rakefile

Lines changed: 4 additions & 123 deletions
Original file line numberDiff line numberDiff line change
@@ -1,130 +1,11 @@
11
# frozen_string_literal: true
22

3-
require "rubocop/rake_task"
4-
5-
RuboCop::RakeTask.new("ruby:rubocop")
6-
7-
namespace :ruby do
8-
namespace :example do
9-
desc "Build ruby/testdata/example/"
10-
task :build do
11-
Dir.chdir(File.join(__dir__, "ruby", "testdata", "example")) do
12-
sh "bundle exec rake all"
13-
end
14-
end
15-
end
16-
17-
namespace :rbs do
18-
desc "`rbs collection install` and `git commit`"
19-
task :install do
20-
sh "rbs collection install"
21-
sh "git add rbs_collection.lock.yaml"
22-
sh "git commit -m 'rbs collection install' || true"
23-
end
24-
end
25-
26-
desc "Check rbs"
27-
task :rbs do
28-
sh "rbs validate"
29-
sh "steep check"
30-
end
31-
32-
desc "Run all build tasks in ruby"
33-
task build_all: %w[example:build rubocop rbs]
3+
# @return [String]
4+
def repo_root
5+
__dir__
346
end
357

36-
# @return [Hash<String, String>]
37-
def env_vars
38-
ldflags = "-L#{RbConfig::CONFIG["libdir"]} -l#{RbConfig::CONFIG["RUBY_SO_NAME"]}"
39-
40-
case `#{RbConfig::CONFIG["CC"]} --version` # rubocop:disable Lint/LiteralAsCondition
41-
when /Free Software Foundation/
42-
ldflags << " -Wl,--unresolved-symbols=ignore-all"
43-
when /clang/
44-
ldflags << " -undefined dynamic_lookup"
45-
end
46-
47-
cflags = "#{RbConfig::CONFIG["CFLAGS"]} -I#{RbConfig::CONFIG["rubyarchhdrdir"]} -I#{RbConfig::CONFIG["rubyhdrdir"]}"
48-
49-
# FIXME: Workaround for GitHub Actions
50-
if ENV["GITHUB_ACTIONS"]
51-
cflags.gsub!("-Wno-self-assign", "")
52-
cflags.gsub!("-Wno-parentheses-equality", "")
53-
cflags.gsub!("-Wno-constant-logical-operand", "")
54-
cflags.gsub!("-Wsuggest-attribute=format", "")
55-
cflags.gsub!("-Wold-style-definition", "")
56-
cflags.gsub!("-Wsuggest-attribute=noreturn", "")
57-
ldflags.gsub!("-Wl,--unresolved-symbols=ignore-all", "")
58-
end
59-
60-
ld_library_path = RbConfig::CONFIG["libdir"]
61-
62-
{
63-
"CGO_CFLAGS" => cflags,
64-
"CGO_LDFLAGS" => ldflags,
65-
"LD_LIBRARY_PATH" => ld_library_path,
66-
}
67-
end
68-
69-
namespace :go do
70-
desc "Run go test"
71-
task :test do
72-
sh env_vars, "go test -mod=readonly -count=1 #{ENV["GO_TEST_ARGS"]} ./..."
73-
end
74-
75-
desc "Run go test -race"
76-
task :testrace do
77-
sh env_vars, "go test -mod=readonly -count=1 #{ENV["GO_TEST_ARGS"]} -race ./..."
78-
end
79-
80-
desc "Run go fmt"
81-
task :fmt do
82-
sh "go fmt ./..."
83-
end
84-
85-
desc "Run golangci-lint"
86-
task :lint do
87-
sh "which golangci-lint" do |ok, _|
88-
raise "golangci-lint isn't installed. See. https://golangci-lint.run/welcome/install/" unless ok
89-
end
90-
sh env_vars, "golangci-lint run"
91-
end
92-
93-
desc "Run all build tasks in go"
94-
task build_all: %i[test fmt lint]
95-
end
96-
97-
namespace :patch_for_go_gem do
98-
desc "Run _tools/patch_for_go_gem test"
99-
task :test do
100-
Dir.chdir(File.join(__dir__, "_tools", "patch_for_go_gem")) do
101-
sh "rspec"
102-
end
103-
end
104-
end
105-
106-
namespace :ruby_h_to_go do
107-
desc "Run _tools/ruby_h_to_go test"
108-
task :test do
109-
Dir.chdir(File.join(__dir__, "_tools", "ruby_h_to_go")) do
110-
sh "rspec"
111-
end
112-
end
113-
end
114-
115-
namespace :go_gem do
116-
desc "Run go_gem test"
117-
task :test do
118-
Dir.chdir(File.join(__dir__, "gem")) do
119-
sh "rspec"
120-
end
121-
end
122-
end
123-
124-
desc "Run _tools/ruby_h_to_go"
125-
task :ruby_h_to_go do
126-
sh "./_tools/ruby_h_to_go/exe/ruby_h_to_go"
127-
end
8+
Dir["#{__dir__}/tasks/*.rake"].each { |f| load f }
1289

12910
desc "Release package"
13011
task :release do

tasks/go.rake

Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
# @return [Hash<String, String>]
2+
def env_vars
3+
ldflags = "-L#{RbConfig::CONFIG["libdir"]} -l#{RbConfig::CONFIG["RUBY_SO_NAME"]}"
4+
5+
case `#{RbConfig::CONFIG["CC"]} --version` # rubocop:disable Lint/LiteralAsCondition
6+
when /Free Software Foundation/
7+
ldflags << " -Wl,--unresolved-symbols=ignore-all"
8+
when /clang/
9+
ldflags << " -undefined dynamic_lookup"
10+
end
11+
12+
cflags = "#{RbConfig::CONFIG["CFLAGS"]} -I#{RbConfig::CONFIG["rubyarchhdrdir"]} -I#{RbConfig::CONFIG["rubyhdrdir"]}"
13+
14+
# FIXME: Workaround for GitHub Actions
15+
if ENV["GITHUB_ACTIONS"]
16+
cflags.gsub!("-Wno-self-assign", "")
17+
cflags.gsub!("-Wno-parentheses-equality", "")
18+
cflags.gsub!("-Wno-constant-logical-operand", "")
19+
cflags.gsub!("-Wsuggest-attribute=format", "")
20+
cflags.gsub!("-Wold-style-definition", "")
21+
cflags.gsub!("-Wsuggest-attribute=noreturn", "")
22+
ldflags.gsub!("-Wl,--unresolved-symbols=ignore-all", "")
23+
end
24+
25+
ld_library_path = RbConfig::CONFIG["libdir"]
26+
27+
{
28+
"CGO_CFLAGS" => cflags,
29+
"CGO_LDFLAGS" => ldflags,
30+
"LD_LIBRARY_PATH" => ld_library_path,
31+
}
32+
end
33+
34+
namespace :go do
35+
desc "Run go test"
36+
task :test do
37+
sh env_vars, "go test -mod=readonly -count=1 #{ENV["GO_TEST_ARGS"]} ./..."
38+
end
39+
40+
desc "Run go test -race"
41+
task :testrace do
42+
sh env_vars, "go test -mod=readonly -count=1 #{ENV["GO_TEST_ARGS"]} -race ./..."
43+
end
44+
45+
desc "Run go fmt"
46+
task :fmt do
47+
sh "go fmt ./..."
48+
end
49+
50+
desc "Run golangci-lint"
51+
task :lint do
52+
sh "which golangci-lint" do |ok, _|
53+
raise "golangci-lint isn't installed. See. https://golangci-lint.run/welcome/install/" unless ok
54+
end
55+
sh env_vars, "golangci-lint run"
56+
end
57+
58+
desc "Run all build tasks in go"
59+
task build_all: %i[test fmt lint]
60+
end

tasks/go_gem.rake

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
namespace :go_gem do
2+
desc "Run go_gem test"
3+
task :test do
4+
Dir.chdir(File.join(repo_root, "gem")) do
5+
sh "rspec"
6+
end
7+
end
8+
end

tasks/patch_for_go_gem.rake

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
namespace :patch_for_go_gem do
2+
desc "Run _tools/patch_for_go_gem test"
3+
task :test do
4+
Dir.chdir(File.join(repo_root, "_tools", "patch_for_go_gem")) do
5+
sh "rspec"
6+
end
7+
end
8+
end

tasks/ruby.rake

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
require "rubocop/rake_task"
2+
3+
RuboCop::RakeTask.new("ruby:rubocop")
4+
5+
namespace :ruby do
6+
namespace :example do
7+
desc "Build ruby/testdata/example/"
8+
task :build do
9+
Dir.chdir(File.join(repo_root, "ruby", "testdata", "example")) do
10+
sh "bundle exec rake all"
11+
end
12+
end
13+
end
14+
15+
namespace :rbs do
16+
desc "`rbs collection install` and `git commit`"
17+
task :install do
18+
sh "rbs collection install"
19+
sh "git add rbs_collection.lock.yaml"
20+
sh "git commit -m 'rbs collection install' || true"
21+
end
22+
end
23+
24+
desc "Check rbs"
25+
task :rbs do
26+
sh "rbs validate"
27+
sh "steep check"
28+
end
29+
30+
desc "Run all build tasks in ruby"
31+
task build_all: %w[example:build rubocop rbs]
32+
end

tasks/ruby_h_to_go.rake

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
namespace :ruby_h_to_go do
2+
desc "Run _tools/ruby_h_to_go test"
3+
task :test do
4+
Dir.chdir(File.join(repo_root, "_tools", "ruby_h_to_go")) do
5+
sh "rspec"
6+
end
7+
end
8+
end
9+
10+
desc "Run _tools/ruby_h_to_go"
11+
task :ruby_h_to_go do
12+
sh "./_tools/ruby_h_to_go/exe/ruby_h_to_go"
13+
end

0 commit comments

Comments
 (0)