Skip to content

Commit 2bf7df4

Browse files
authored
Merge pull request #196 from ruby-go-gem/split/tasks
nits: Split to rake rasks
2 parents c32c277 + 40bef76 commit 2bf7df4

File tree

6 files changed

+135
-123
lines changed

6 files changed

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

tasks/go_gem.rake

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

tasks/patch_for_go_gem.rake

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

tasks/ruby.rake

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
# frozen_string_literal: true
2+
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(repo_root, "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]
34+
end

tasks/ruby_h_to_go.rake

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

0 commit comments

Comments
 (0)