Class: GoGem::RakeTask
- Inherits:
-
Rake::TaskLib
- Object
- Rake::TaskLib
- GoGem::RakeTask
- Defined in:
- _gem/lib/go_gem/rake_task.rb
Overview
Provides rake tasks for go test
with CRuby
Constant Summary collapse
- DEFAULT_TASK_NAMESPACE =
:go
- DEFAULT_GO_BIN_PATH =
"go"
- DEFAULT_GO_TEST_ARGS =
"-mod=readonly -count=1"
Instance Attribute Summary collapse
-
#cwd ⇒ String
Directory when executing go commands.
- #gem_name ⇒ String readonly
-
#go_bin_path ⇒ String
Path to go binary (default:
"go"
). -
#go_test_args ⇒ String
Argument passed to
go test
(default:"-mod=readonly -count=1"
). -
#target_dir ⇒ Object
Returns the value of attribute target_dir.
-
#task_namespace ⇒ Symbol, String
Task namespace (default:
:go
).
Class Method Summary collapse
-
.build_env_vars ⇒ Hash<String, String>
Generate environment variables to build go programs in the Go gem.
Instance Method Summary collapse
- #ext_dir ⇒ String
-
#initialize(gem_name) {|t| ... } ⇒ RakeTask
constructor
A new instance of RakeTask.
- #within_target_dir { ... } ⇒ Object
Constructor Details
#initialize(gem_name) {|t| ... } ⇒ RakeTask
Returns a new instance of RakeTask.
73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 |
# File '_gem/lib/go_gem/rake_task.rb', line 73 def initialize(gem_name) super() @gem_name = gem_name @task_namespace = DEFAULT_TASK_NAMESPACE @go_bin_path = DEFAULT_GO_BIN_PATH @go_test_args = DEFAULT_GO_TEST_ARGS @target_dir = ext_dir yield(self) if block_given? namespace(task_namespace) do define_go_test_task define_go_testrace_task define_go_fmt_task define_go_build_envs_task end end |
Instance Attribute Details
#cwd ⇒ String
Returns directory when executing go commands. (default: "ext/#{gem_name}"
).
68 |
# File '_gem/lib/go_gem/rake_task.rb', line 68 attr_accessor :target_dir |
#gem_name ⇒ String (readonly)
52 53 54 |
# File '_gem/lib/go_gem/rake_task.rb', line 52 def gem_name @gem_name end |
#go_bin_path ⇒ String
Returns path to go binary (default: "go"
).
60 61 62 |
# File '_gem/lib/go_gem/rake_task.rb', line 60 def go_bin_path @go_bin_path end |
#go_test_args ⇒ String
Returns argument passed to go test
(default: "-mod=readonly -count=1"
).
64 65 66 |
# File '_gem/lib/go_gem/rake_task.rb', line 64 def go_test_args @go_test_args end |
#target_dir ⇒ Object
Returns the value of attribute target_dir.
68 69 70 |
# File '_gem/lib/go_gem/rake_task.rb', line 68 def target_dir @target_dir end |
#task_namespace ⇒ Symbol, String
Returns task namespace (default: :go
).
56 57 58 |
# File '_gem/lib/go_gem/rake_task.rb', line 56 def task_namespace @task_namespace end |
Class Method Details
.build_env_vars ⇒ Hash<String, String>
Generate environment variables to build go programs in the Go gem
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 |
# File '_gem/lib/go_gem/rake_task.rb', line 96 def self.build_env_vars ldflags = "-L#{RbConfig::CONFIG["libdir"]} -l#{RbConfig::CONFIG["RUBY_SO_NAME"]}" case `#{RbConfig::CONFIG["CC"]} --version` # rubocop:disable Lint/LiteralAsCondition when /Free Software Foundation/ ldflags << " -Wl,--unresolved-symbols=ignore-all" when /clang/ ldflags << " -undefined dynamic_lookup" end cflags = [ RbConfig::CONFIG["CFLAGS"], "-I#{RbConfig::CONFIG["rubyarchhdrdir"]}", "-I#{RbConfig::CONFIG["rubyhdrdir"]}", ].join(" ") # FIXME: Workaround for Ubuntu (GitHub Actions) if RUBY_PLATFORM =~ /linux/i cflags.gsub!("-Wno-self-assign", "") cflags.gsub!("-Wno-parentheses-equality", "") cflags.gsub!("-Wno-constant-logical-operand", "") cflags.gsub!("-Wsuggest-attribute=format", "") cflags.gsub!("-Wold-style-definition", "") cflags.gsub!("-Wsuggest-attribute=noreturn", "") ldflags.gsub!("-Wl,--unresolved-symbols=ignore-all", "") end ld_library_path = RbConfig::CONFIG["libdir"].to_s { "CGO_CFLAGS" => cflags, "CGO_LDFLAGS" => ldflags, "LD_LIBRARY_PATH" => ld_library_path, } end |
Instance Method Details
#ext_dir ⇒ String
140 141 142 |
# File '_gem/lib/go_gem/rake_task.rb', line 140 def ext_dir File.join("ext", gem_name) end |
#within_target_dir { ... } ⇒ Object
133 134 135 136 137 |
# File '_gem/lib/go_gem/rake_task.rb', line 133 def within_target_dir Dir.chdir(target_dir) do # rubocop:disable Style/ExplicitBlockArgument yield end end |