Skip to content

Handle preperly comments in middle of lines in gems/bundled_gems #14178

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Aug 12, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 7 additions & 5 deletions common.mk
Original file line number Diff line number Diff line change
Expand Up @@ -1539,12 +1539,14 @@ prepare-gems: $(HAVE_BASERUBY:yes=update-gems) $(HAVE_BASERUBY:yes=extract-gems)
extract-gems: $(HAVE_BASERUBY:yes=update-gems) $(HAVE_BASERUBY:yes=outdate-bundled-gems)
update-gems: $(HAVE_BASERUBY:yes=outdate-bundled-gems)

split_option = -F"\s+|$(HASH_SIGN).*"

update-gems$(sequential): PHONY
$(ECHO) Downloading bundled gem files...
$(Q) $(BASERUBY) -C "$(srcdir)" \
-I./tool -rdownloader -answ \
-I./tool -rdownloader $(split_option) -answ \
-e 'gem, ver = *$$F' \
-e 'next if !ver or /^#/=~gem' \
-e 'next if !ver' \
-e 'old = Dir.glob("gems/#{gem}-*.gem")' \
-e 'gem = "#{gem}-#{ver}.gem"' \
-e 'Downloader::RubyGems.download(gem, "gems", nil) and' \
Expand All @@ -1556,10 +1558,10 @@ update-gems$(sequential): PHONY
extract-gems$(sequential): PHONY
$(ECHO) Extracting bundled gem files...
$(Q) $(BASERUBY) -C "$(srcdir)" \
-Itool/lib -rfileutils -rbundled_gem -answ \
-Itool/lib -rfileutils -rbundled_gem $(split_option) -answ \
-e 'BEGIN {d = ".bundle/gems"}' \
-e 'gem, ver, _, rev = *$$F' \
-e 'next if !ver or /^#/=~gem' \
-e 'next if !ver' \
-e 'g = "#{gem}-#{ver}"' \
-e 'unless File.directory?("#{d}/#{g}")' \
-e 'if rev and File.exist?(gs = "gems/src/#{gem}/#{gem}.gemspec")' \
Expand Down Expand Up @@ -1623,7 +1625,7 @@ yes-install-for-test-bundled-gems: yes-update-default-gemspecs
test-bundled-gems-fetch: yes-test-bundled-gems-fetch
yes-test-bundled-gems-fetch: clone-bundled-gems-src
clone-bundled-gems-src: PHONY
$(Q) $(BASERUBY) -C $(srcdir)/gems ../tool/fetch-bundled_gems.rb BUNDLED_GEMS="$(BUNDLED_GEMS)" src bundled_gems
$(Q) $(BASERUBY) -C $(srcdir) tool/fetch-bundled_gems.rb BUNDLED_GEMS="$(BUNDLED_GEMS)" gems/src gems/bundled_gems
no-test-bundled-gems-fetch:

test-bundled-gems-prepare: $(TEST_RUNNABLE)-test-bundled-gems-prepare
Expand Down
2 changes: 1 addition & 1 deletion defs/gmake.mk
Original file line number Diff line number Diff line change
Expand Up @@ -309,7 +309,7 @@ HELP_EXTRA_TASKS = \
# 4. "gem x.y.z URL" -> "gem-x.y.z"
bundled-gems := $(shell sed \
-e 's/[ ][ ]*/ /g' \
-e 's/^ //;/\#/d;s/ *$$//;/^$$/d' \
-e 's/^ //;s/\#.*//;s/ *$$//;/^$$/d' \
$(if $(filter yes,$(HAVE_GIT)), \
-e 's/^\(.*\) \(.*\) \(.*\) \(.*\)/\1|\2|\4|\3/' \
) \
Expand Down
2 changes: 2 additions & 0 deletions template/Makefile.in
Original file line number Diff line number Diff line change
Expand Up @@ -289,6 +289,8 @@ ABI_VERSION_HDR = $(hdrdir)/ruby/internal/abi.h

CAT_DEPEND = sed -e 's/{\$$([^(){}]*)[^{}]*}//g' -e /AUTOGENERATED/q

HASH_SIGN = \#

.SUFFIXES: .inc .h .c .y .i .$(ASMEXT) .$(DTRACE_EXT)

all:
Expand Down
3 changes: 1 addition & 2 deletions tool/fetch-bundled_gems.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#!ruby -an
#!ruby -alnF\s+|#.*
BEGIN {
require 'fileutils'
require_relative 'lib/colorize'
Expand All @@ -21,7 +21,6 @@
n, v, u, r = $F

next unless n
next if n =~ /^#/
next if bundled_gems&.all? {|pat| !File.fnmatch?(pat, n)}

unless File.exist?("#{n}/.git")
Expand Down
2 changes: 1 addition & 1 deletion tool/outdate-bundled-gems.rb
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,7 @@ def each_directory
curdir = !srcdir.base || File.identical?(srcdir.base, ".") ? srcdir : Removal.new

bundled = File.readlines("#{srcdir.base}gems/bundled_gems").
grep(/^(\w\S+)\s+\S+(?:\s+\S+\s+(\S+))?/) {$~.captures}.to_h rescue nil
grep(/^(\w[^\#\s]+)\s+[^\#\s]+(?:\s+[^\#\s]+\s+([^\#\s]+))?/) {$~.captures}.to_h rescue nil

srcdir.glob(".bundle/gems/*/") do |dir|
base = File.basename(dir)
Expand Down
3 changes: 1 addition & 2 deletions tool/test-bundled-gems.rb
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,7 @@
ruby = ENV['RUBY'] || RbConfig.ruby
failed = []
File.foreach("#{gem_dir}/bundled_gems") do |line|
next if /^\s*(?:#|$)/ =~ line
gem = line.split.first
next unless gem = line[/^[^\s\#]+/]
next unless bundled_gems.empty? || bundled_gems.split(",").include?(gem)
next unless File.directory?("#{gem_dir}/src/#{gem}/test")

Expand Down
4 changes: 2 additions & 2 deletions tool/update-bundled_gems.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#!ruby -pla
#!ruby -alpF\s+|#.*
BEGIN {
require 'rubygems'
date = nil
Expand All @@ -9,7 +9,7 @@
END {
output.print date.strftime("latest_date=%F") if date
}
unless /^[^#]/ !~ (gem = $F[0])
if gem = $F[0]
ver = Gem::Version.new($F[1])
(gem, src), = Gem::SpecFetcher.fetcher.detect(:latest) {|s|
s.platform == "ruby" && s.name == gem
Expand Down
1 change: 1 addition & 0 deletions win32/Makefile.sub
Original file line number Diff line number Diff line change
Expand Up @@ -464,6 +464,7 @@ ASMEXT = asm

INSTALLED_LIST= .installed.list

HASH_SIGN = ^#
SRC_FILE = $(<:\=/)
OS_SRC_FILE = $(<:/=\)
DEST_FILE = $(@:\=/)
Expand Down
Loading