diff options
| author | Nobuyoshi Nakada <nobu@ruby-lang.org> | 2026-04-16 17:07:55 +0900 |
|---|---|---|
| committer | Nobuyoshi Nakada <nobu@ruby-lang.org> | 2026-05-13 11:55:57 +0900 |
| commit | 68e768391ae575fb71e3cc78163104e28450b94f (patch) | |
| tree | c124828e2119284012ee380791f02fe2fc53fb23 | |
| parent | 27487598893613820e6f5d2156b9fc212710af75 (diff) | |
Move update-default-gemspecs code to bundled_gem.rb
| -rw-r--r-- | common.mk | 25 | ||||
| -rw-r--r-- | tool/lib/bundled_gem.rb | 26 | ||||
| -rw-r--r-- | tool/lib/output.rb | 12 |
3 files changed, 36 insertions, 27 deletions
@@ -1579,27 +1579,10 @@ no-test-bundled-gems-precheck: yes-update-default-gemspecs no-update-default-gemspecs: update-default-gemspecs update-default-gemspecs: $(PREP) @$(MAKEDIRS) $(srcdir)/.bundle/specifications - $(Q)$(MINIRUBY) -W0 -C "$(srcdir)" -rrubygems \ - -e "destdir = ARGV.shift" \ - -e "ARGV.each do |basedir|" \ - -e "Dir.glob(basedir+'/**/*.gemspec') do |g|" \ - -e "dir, base = File.split(g)" \ - -e "spec = Dir.chdir(dir) {Gem::Specification.load(base)} ||" \ - -e "Gem::Specification.load(g)" \ - -e "unless spec" \ - -e "puts %[Ignoring #{g}]" \ - -e "next" \ - -e "end" \ - -e "spec.files.clear" \ - -e "spec.extensions.clear" \ - -e "src = spec.to_ruby" \ - -e "src.sub!(/^$$/) {" \ - -e "%[# default: #{g} #{File.mtime(g).strftime(%[%s.%N])}\n]" \ - -e "}" \ - -e "File.binwrite(File.join(destdir, spec.full_name+'.gemspec'), src)" \ - -e "end" \ - -e "end" \ - -- .bundle/specifications lib ext + $(Q)$(MINIRUBY) -W0 -C "$(srcdir)" -I tool/lib -roptparse -routput -rbundled_gem \ + -e "(out = Output.new).def_options(ARGV.options)" \ + -e "BundledGem.update_default_gemspecs(ARGV.parse!, out, quiet: $(V).zero?)" \ + -- -c -o .bundle/specifications lib ext install-for-test-bundled-gems: $(TEST_RUNNABLE)-install-for-test-bundled-gems no-install-for-test-bundled-gems: no-update-default-gemspecs diff --git a/tool/lib/bundled_gem.rb b/tool/lib/bundled_gem.rb index 22d03112ed..6cfdb8d425 100644 --- a/tool/lib/bundled_gem.rb +++ b/tool/lib/bundled_gem.rb @@ -130,4 +130,30 @@ module BundledGem command = "#{git} checkout --detach #{rev}" system(command, chdir: gemdir) or raise "failed: #{command}" end + + def load_gemspec(g) + dir, base = File.split(g) + spec = Dir.chdir(dir) {Gem::Specification.load(base)} || Gem::Specification.load(g) or + return false + spec.files.clear + spec.extensions.clear + src = spec.to_ruby + src.sub!(/^$$/) { + %[# default: #{g} #{File.mtime(g).strftime(%[%s.%N])}\n] + } + return spec.full_name+'.gemspec', src + end + + def update_default_gemspecs(basedirs, out, quiet: true) + basedirs.each do |basedir| + Dir.glob(basedir+'/**/*.gemspec') do |g| + name, src = BundledGem.load_gemspec(g) + unless src + puts "Ignoring #{g}" unless quiet + next + end + out.write(src, name: name, quiet: quiet) + end + end + end end diff --git a/tool/lib/output.rb b/tool/lib/output.rb index 8cb426ae4a..db59b6ed4e 100644 --- a/tool/lib/output.rb +++ b/tool/lib/output.rb @@ -31,8 +31,8 @@ class Output @vpath.def_options(opt) end - def write(data, overwrite: @overwrite, create_only: @create_only) - unless @path + def write(data, overwrite: @overwrite, create_only: @create_only, name: nil, quiet: false) + unless (name = name ? (@path ? File.join(@path, name) : name) : @path) $stdout.print data return true end @@ -41,20 +41,20 @@ class Output updated = color.fail("updated") outpath = nil - if (@ifchange or overwrite or create_only) and (@vpath.open(@path, "rb") {|f| + if (@ifchange or overwrite or create_only) and (@vpath.open(name, "rb") {|f| outpath = f.path if @ifchange or create_only original = f.read (@ifchange and original == data) or (create_only and !original.empty?) end } rescue false) - puts "#{outpath} #{unchanged}" + puts "#{outpath} #{unchanged}" unless quiet written = false else unless overwrite and outpath and (File.binwrite(outpath, data) rescue nil) - File.binwrite(outpath = @path, data) + File.binwrite(outpath = name, data) end - puts "#{outpath} #{updated}" + puts "#{outpath} #{updated}" unless quiet written = true end if timestamp = @timestamp |
