Skip to content

Commit f914309

Browse files
committed
Add target_dir
1 parent 3d22bdf commit f914309

File tree

3 files changed

+17
-5
lines changed

3 files changed

+17
-5
lines changed

_gem/README.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,7 @@ GoGem::RakeTask.new("gem_name") do |config|
5858
config.task_namespace = "go5"
5959
config.go_bin_path = "/path/to/go"
6060
config.go_test_args = "#{GoGem::RakeTask::DEFAULT_GO_TEST_ARGS} -race"
61+
config.target_dir = "/dir/to/go-mod/"
6162
end
6263
```
6364

@@ -70,6 +71,7 @@ Following tasks are generated
7071
* `task_namespace` : task namespace (default: `:go`)
7172
* `go_bin_path` : path to go binary (default: `"go"`)
7273
* `go_test_args` : argument passed to `go test` (default: `"-mod=readonly -count=1"`)
74+
* `target_dir` : directory when executing go commands. (default: `"ext/#{gem_name}"`)
7375

7476
## Development
7577

_gem/lib/go_gem/rake_task.rb

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ module GoGem
2020
# config.task_namespace = "go5"
2121
# config.go_bin_path = "/path/to/go"
2222
# config.go_test_args = "#{GoGem::RakeTask::DEFAULT_GO_TEST_ARGS} -race"
23+
# config.target_dir = "/dir/to/go-mod/"
2324
# end
2425
class RakeTask < ::Rake::TaskLib
2526
DEFAULT_TASK_NAMESPACE = :go
@@ -44,6 +45,10 @@ class RakeTask < ::Rake::TaskLib
4445
# @return [String] argument passed to `go test` (default: `"-mod=readonly -count=1"`)
4546
attr_accessor :go_test_args
4647

48+
# @!attribute cwd
49+
# @return [String] directory when executing go commands. (default: `"ext/#{gem_name}"`)
50+
attr_accessor :target_dir
51+
4752
# @param gem_name [String]
4853
# @yield configuration of {RakeTask}
4954
# @yieldparam config [RakeTask]
@@ -55,20 +60,21 @@ def initialize(gem_name)
5560
@task_namespace = DEFAULT_TASK_NAMESPACE
5661
@go_bin_path = DEFAULT_GO_BIN_PATH
5762
@go_test_args = DEFAULT_GO_TEST_ARGS
63+
@target_dir = ext_dir
5864

5965
yield(self) if block_given?
6066

6167
namespace(task_namespace) do
6268
desc "Run go test"
6369
task(:test) do
64-
within_ext_dir do
70+
within_target_dir do
6571
sh RakeTask.build_env_vars, "#{go_bin_path} test #{go_test_args} ./..."
6672
end
6773
end
6874

6975
desc "Run go test -race"
7076
task(:testrace) do
71-
within_ext_dir do
77+
within_target_dir do
7278
sh RakeTask.build_env_vars, "#{go_bin_path} test #{go_test_args} -race ./..."
7379
end
7480
end
@@ -117,8 +123,8 @@ def self.build_env_vars
117123
private
118124

119125
# @yield
120-
def within_ext_dir
121-
Dir.chdir(ext_dir) do # rubocop:disable Style/ExplicitBlockArgument
126+
def within_target_dir
127+
Dir.chdir(target_dir) do # rubocop:disable Style/ExplicitBlockArgument
122128
yield
123129
end
124130
end

_gem/sig/go_gem/rake_task.rbs

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,8 @@ module GoGem
88

99
@go_test_args: String
1010

11+
@target_dir: String
12+
1113
DEFAULT_TASK_NAMESPACE: Symbol
1214

1315
DEFAULT_GO_BIN_PATH: String
@@ -22,13 +24,15 @@ module GoGem
2224

2325
attr_accessor go_test_args: String
2426

27+
attr_accessor target_dir: String
28+
2529
def initialize: (String gem_name) ?{ (RakeTask) -> void } -> void
2630

2731
def self.build_env_vars: () -> { "CGO_CFLAGS" => String, "CGO_LDFLAGS" => String, "LD_LIBRARY_PATH" => String }
2832

2933
private
3034

31-
def within_ext_dir: () { () -> void } -> void
35+
def within_target_dir: () { () -> void } -> void
3236

3337
def ext_dir: () -> String
3438
end

0 commit comments

Comments
 (0)