Skip to content

Commit 768b801

Browse files
committed
Run go mod tidy to create go.sum
1 parent 3536b25 commit 768b801

File tree

2 files changed

+22
-0
lines changed

2 files changed

+22
-0
lines changed

bundler/lib/bundler/cli/gem.rb

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -253,6 +253,10 @@ def run
253253
path.chmod(executable)
254254
end
255255

256+
if extension == "go"
257+
run_go_mod_tidy(target.join("ext/#{name}"))
258+
end
259+
256260
if use_git
257261
IO.popen(%w[git add .], { chdir: target }, &:read)
258262
end
@@ -488,5 +492,22 @@ def go_version
488492

489493
/go version go([.\d]+)/.match(stdout)[1]
490494
end
495+
496+
# Run `go mod tidy` within ext/newgem/
497+
def run_go_mod_tidy(ext_dir)
498+
Dir.chdir(ext_dir) do
499+
_, stderr, status = Open3.capture3("go mod tidy")
500+
501+
if status.success?
502+
Bundler.ui.info "#{ext_dir}/go.sum has been created with `go mod tidy`"
503+
else
504+
Bundler.ui.warn <<~MSG
505+
An error occurred when executing `go mod tidy`.
506+
stderr: #{stderr}
507+
Please run `go mod tidy` later in #{ext_dir} to create `go.sum`.
508+
MSG
509+
end
510+
end
511+
end
491512
end
492513
end

bundler/spec/commands/newgem_spec.rb

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1621,6 +1621,7 @@ def create_temporary_dir(dir)
16211621
expect(bundled_app("#{gem_name}/ext/#{gem_name}/#{gem_name}.h")).to exist
16221622
expect(bundled_app("#{gem_name}/ext/#{gem_name}/extconf.rb")).to exist
16231623
expect(bundled_app("#{gem_name}/ext/#{gem_name}/go.mod")).to exist
1624+
expect(bundled_app("#{gem_name}/ext/#{gem_name}/go.sum")).to exist
16241625
end
16251626

16261627
it "includes extconf.rb in gem_name.gemspec" do

0 commit comments

Comments
 (0)