summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorNobuyoshi Nakada <nobu@ruby-lang.org>2023-01-18 20:36:31 +0900
committerNobuyoshi Nakada <nobu@ruby-lang.org>2023-01-26 12:50:39 +0900
commit17f5631c6ea118b9ce0e8776dc50c7b1dcdaf596 (patch)
tree93cc91fcdd336690d7d7e3862fa02415f4f4cce1
parent78fcc9847a9db6d42c8c263154ec05903a370b6b (diff)
[Bug #19340] Fix bundle gems with test revision
Build temporary gem package from cloned repository if test revision is set.
Notes
Notes: Merged: https://github.com/ruby/ruby/pull/7146
-rw-r--r--common.mk8
-rw-r--r--defs/gmake.mk15
-rw-r--r--tool/lib/bundled_gem.rb13
3 files changed, 25 insertions, 11 deletions
diff --git a/common.mk b/common.mk
index abd652fe44..5f8d7e3e88 100644
--- a/common.mk
+++ b/common.mk
@@ -1402,10 +1402,10 @@ extract-gems$(gnumake:yes=-sequential): PHONY
-e 'gem, ver, _, rev = *$$F' \
-e 'next if !ver or /^#/=~gem' \
-e 'g = "#{gem}-#{ver}"' \
- -e 'if File.directory?("#{d}/#{g}")' \
- -e 'elsif rev and File.exist?(gs = "gems/src/#{gem}/#{gem}.gemspec")' \
- -e 'BundledGem.copy(gs, ".bundle")' \
- -e 'else' \
+ -e 'unless File.directory?("#{d}/#{g}")' \
+ -e 'if rev and File.exist?(gs = "gems/src/#{gem}/#{gem}.gemspec")' \
+ -e 'BundledGem.build(gs, ver, "gems")' \
+ -e 'end' \
-e 'BundledGem.unpack("gems/#{g}.gem", ".bundle")' \
-e 'end' \
gems/bundled_gems
diff --git a/defs/gmake.mk b/defs/gmake.mk
index 2f0bc8b810..3970409f39 100644
--- a/defs/gmake.mk
+++ b/defs/gmake.mk
@@ -326,27 +326,28 @@ $(srcdir)/.bundle/gems/%: $(srcdir)/gems/%.gem | .bundle/gems
-Itool/lib -rbundled_gem \
-e 'BundledGem.unpack("gems/$(@F).gem", ".bundle")'
-define copy-gem
+define build-gem
$(srcdir)/gems/src/$(1): | $(srcdir)/gems/src
$(ECHO) Cloning $(4)
$(Q) $(GIT) clone $(4) $$(@)
-$(srcdir)/.bundle/gems/$(1)-$(2): | $(srcdir)/gems/src/$(1) .bundle/gems
- $(ECHO) Copying $(1)@$(3) to $$(@F)
+.PHONY: $(srcdir)/gems/$(1)-$(2).gem
+$(srcdir)/gems/$(1)-$(2).gem: | $(srcdir)/gems/src/$(1)
+ $(ECHO) Building $(1)@$(3) to $$(@F)
$(Q) $(CHDIR) "$(srcdir)/gems/src/$(1)" && \
$(GIT) fetch origin $(3) && \
$(GIT) checkout --detach $(3) && \
:
$(Q) $(BASERUBY) -C "$(srcdir)" \
-Itool/lib -rbundled_gem \
- -e 'BundledGem.copy("gems/src/$(1)/$(1).gemspec", ".bundle")'
+ -e 'BundledGem.build("gems/src/$(1)/$(1).gemspec", "$(2)", "gems")'
endef
-define copy-gem-0
-$(eval $(call copy-gem,$(1),$(2),$(3),$(4)))
+define build-gem-0
+$(eval $(call build-gem,$(1),$(2),$(3),$(4)))
endef
-$(call foreach-bundled-gems-rev,copy-gem-0)
+$(call foreach-bundled-gems-rev,build-gem-0)
$(srcdir)/gems/src:
$(MAKEDIRS) $@
diff --git a/tool/lib/bundled_gem.rb b/tool/lib/bundled_gem.rb
index 38c331183d..46183ba06c 100644
--- a/tool/lib/bundled_gem.rb
+++ b/tool/lib/bundled_gem.rb
@@ -14,6 +14,19 @@ module BundledGem
puts "Unpacked #{file}"
end
+ def build(gemspec, version, outdir = ".", validation: true)
+ outdir = File.expand_path(outdir)
+ gemdir, gemfile = File.split(gemspec)
+ Dir.chdir(gemdir) do
+ spec = Gem::Specification.load(gemfile)
+ abort "Failed to load #{gemspec}" unless spec
+ abort "Unexpected version #{spec.version}" unless spec.version == Gem::Version.new(version)
+ output = File.join(outdir, spec.file_name)
+ FileUtils.rm_rf(output)
+ Gem::Package.build(spec, validation == false, validation, output)
+ end
+ end
+
def copy(path, *rest)
path, n = File.split(path)
spec = Dir.chdir(path) {Gem::Specification.load(n)} or raise "Cannot load #{path}"