Skip to content

Commit

Permalink
outdate-bundled-gems.rb: Pass platform and version explicitly
Browse files Browse the repository at this point in the history
For different version baseruby, use the target platform and version
instead of the info of baseruby.
  • Loading branch information
nobu committed Jan 9, 2024
1 parent 8f61617 commit 963131a
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 10 deletions.
4 changes: 3 additions & 1 deletion common.mk
Expand Up @@ -1533,7 +1533,9 @@ clone-bundled-gems-src: PHONY
gems/bundled_gems

outdate-bundled-gems: PHONY
$(Q) $(BASERUBY) $(tooldir)/$@.rb --make="$(MAKE)" --mflags="$(MFLAGS)" "$(srcdir)"
$(Q) $(BASERUBY) $(tooldir)/$@.rb --make="$(MAKE)" --mflags="$(MFLAGS)" \
--ruby-platform=$(arch) --ruby-version=$(ruby_version) \
"$(srcdir)"

update-bundled_gems: PHONY
$(Q) $(RUNRUBY) -rrubygems \
Expand Down
27 changes: 18 additions & 9 deletions tool/outdate-bundled-gems.rb
Expand Up @@ -14,6 +14,14 @@
# just to run when `make -n`
when /\A--mflags=(.*)/
fu = FileUtils::DryRun if /\A-\S*n/ =~ $1
when /\A--gem[-_]platform=(.*)/im
gem_platform = $1
ruby_platform = nil
when /\A--ruby[-_]platform=(.*)/im
ruby_platform = $1
gem_platform = nil
when /\A--ruby[-_]version=(.*)/im
ruby_version = $1
when /\A-/
raise "#{$0}: unknown option: #{ARGV.first}"
else
Expand All @@ -22,6 +30,9 @@
ARGV.shift
end

gem_platform ||= (ruby_platform ? Gem::Platform.new(ruby_platform) : Gem::Platform.local).to_s
ruby_version ||= RbConfig::CONFIG['ruby_version'] # This may not have "-static"

class Removal
attr_reader :base

Expand Down Expand Up @@ -104,29 +115,27 @@ def each_directory
end
end

platform = Gem::Platform.local.to_s
curdir.glob(".bundle/{extensions,.timestamp}/*/") do |dir|
unless File.basename(dir) == platform
unless File.fnmatch?(gem_platform, File.basename(dir))
curdir.rmdir(dir)
end
end

baseruby_version = RbConfig::CONFIG['ruby_version'] # This may not have "-static"
curdir.glob(".bundle/{extensions,.timestamp}/#{platform}/*/") do |dir|
version = File.basename(dir).split('-', 2).first # Remove "-static" if exists
unless version == baseruby_version
curdir.glob(".bundle/{extensions,.timestamp}/#{gem_platform}/*/") do |dir|
unless File.fnmatch?(ruby_version, File.basename(dir, '-static'))
curdir.rmdir(dir)
end
end

curdir.glob(".bundle/extensions/#{platform}/#{baseruby_version}/*/") do |dir|
curdir.glob(".bundle/extensions/#{gem_platform}/#{ruby_version}/*/") do |dir|
unless curdir.exist?(".bundle/specifications/#{File.basename(dir)}.gemspec")
curdir.rmdir(dir)
end
end

curdir.glob(".bundle/.timestamp/#{platform}/#{baseruby_version}/.*.time") do |stamp|
unless curdir.directory?(File.join(".bundle", stamp[%r[/\.([^/]+)\.time\z], 1].gsub('.-.', '/')))
curdir.glob(".bundle/.timestamp/#{gem_platform}/#{ruby_version}/.*.time") do |stamp|
dir = stamp[%r[/\.([^/]+)\.time\z], 1].gsub('.-.', '/')[%r[\A[^/]+/[^/]+]]
unless curdir.directory?(File.join(".bundle", dir))
curdir.unlink(stamp)
end
end
Expand Down

0 comments on commit 963131a

Please sign in to comment.