@@ -31,6 +31,7 @@ def perform
31
31
create_go_mod
32
32
update_gem_name_c
33
33
update_extconf_rb
34
+ update_gemspec
34
35
end
35
36
36
37
private
@@ -125,65 +126,45 @@ def update_gem_name_c
125
126
save_file ( file_path : gem_name_c_path , content :)
126
127
end
127
128
128
- def update_extconf_rb # rubocop:disable Metrics/MethodLength
129
+ def update_extconf_rb
129
130
extconf_rb_path = File . join ( ext_dir , "extconf.rb" )
130
131
131
132
content = File . read ( extconf_rb_path )
132
133
133
- unless content . include? ( <<~RUBY )
134
- require "mkmf"
135
-
136
- find_executable("go")
137
- RUBY
138
-
134
+ unless content . include? ( %(require "go_gem/mkmf") )
139
135
content . gsub! ( <<~RUBY , <<~RUBY )
140
136
require "mkmf"
141
137
RUBY
142
138
require "mkmf"
143
-
144
- find_executable("go")
145
-
146
- # rubocop:disable Style/GlobalVars
147
- $objs = []
148
- def $objs.empty?; false; end
149
- # rubocop:enable Style/GlobalVars
150
-
139
+ require "go_gem/mkmf"
151
140
RUBY
152
141
end
153
142
154
- unless content . include? ( <<~RUBY )
155
- create_makefile("#{ gem_name } /#{ gem_name } ")
156
-
157
- case `\# {CONFIG["CC"]} --version` # rubocop:disable Lint/LiteralAsCondition
158
- RUBY
159
-
143
+ unless content . include? ( %(create_go_makefile("#{ gem_name } /#{ gem_name } ")) )
160
144
content . gsub! ( <<~RUBY , <<~RUBY )
161
145
create_makefile("#{ gem_name } /#{ gem_name } ")
162
146
RUBY
163
- create_makefile("#{ gem_name } /#{ gem_name } ")
147
+ create_go_makefile("#{ gem_name } /#{ gem_name } ")
148
+ RUBY
149
+ end
164
150
165
- case `\# {CONFIG["CC"]} --version` # rubocop:disable Lint/LiteralAsCondition
166
- when /Free Software Foundation/
167
- ldflags = "-Wl,--unresolved-symbols=ignore-all"
168
- when /clang/
169
- ldflags = "-undefined dynamic_lookup"
170
- end
151
+ save_file ( file_path : extconf_rb_path , content :)
152
+ end
171
153
172
- current_dir = File.expand_path(".")
154
+ def update_gemspec
155
+ content = File . read ( gemspec_file )
173
156
174
- File.open("Makefile", "a") do |f|
175
- f.write <<~MAKEFILE.gsub(/^ {8}/, "\t ")
176
- $(DLLIB): Makefile $(srcdir)/*.go
177
- cd $(srcdir); \
178
- CGO_CFLAGS='$(INCFLAGS)' CGO_LDFLAGS='\# {ldflags}' \\
179
- go build -p 4 -buildmode=c-shared -o \# {current_dir}/$(DLLIB)
180
- MAKEFILE
181
- end
157
+ return if content . include? ( %(.add_dependency "go_gem") ) || content . include? ( %(.add_runtime_dependency "go_gem") )
182
158
183
- RUBY
184
- end
159
+ content =~ /Gem::Specification \. new \s +do \s + \| (.+) \| /
160
+ spec_var_name = :: Regexp . last_match ( 1 )
185
161
186
- save_file ( file_path : extconf_rb_path , content :)
162
+ content . gsub! ( /^end\n / , <<~RUBY )
163
+ #{ spec_var_name } .add_dependency "go_gem"
164
+ end
165
+ RUBY
166
+
167
+ save_file ( file_path : gemspec_file , content :)
187
168
end
188
169
189
170
# @param file_path [String]
0 commit comments