Skip to content

Commit becf5bb

Browse files
committed
Update default gemspecs at preparing sources if possible
1 parent 713dced commit becf5bb

3 files changed

Lines changed: 38 additions & 28 deletions

File tree

common.mk

Lines changed: 5 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1522,6 +1522,7 @@ refresh-gems: update-bundled_gems prepare-gems
15221522
prepare-gems: $(HAVE_BASERUBY:yes=update-gems) $(HAVE_BASERUBY:yes=extract-gems)
15231523
extract-gems: $(HAVE_BASERUBY:yes=update-gems) $(HAVE_BASERUBY:yes=outdate-bundled-gems)
15241524
update-gems: $(HAVE_BASERUBY:yes=outdate-bundled-gems)
1525+
update-gems: $(HAVE_BASERUBY:yes=update-default-gemspecs)
15251526

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

@@ -1579,27 +1580,10 @@ no-test-bundled-gems-precheck:
15791580
yes-update-default-gemspecs no-update-default-gemspecs: update-default-gemspecs
15801581
update-default-gemspecs: $(PREP)
15811582
@$(MAKEDIRS) $(srcdir)/.bundle/specifications
1582-
$(Q)$(MINIRUBY) -W0 -C "$(srcdir)" -rrubygems \
1583-
-e "destdir = ARGV.shift" \
1584-
-e "ARGV.each do |basedir|" \
1585-
-e "Dir.glob(basedir+'/**/*.gemspec') do |g|" \
1586-
-e "dir, base = File.split(g)" \
1587-
-e "spec = Dir.chdir(dir) {Gem::Specification.load(base)} ||" \
1588-
-e "Gem::Specification.load(g)" \
1589-
-e "unless spec" \
1590-
-e "puts %[Ignoring #{g}]" \
1591-
-e "next" \
1592-
-e "end" \
1593-
-e "spec.files.clear" \
1594-
-e "spec.extensions.clear" \
1595-
-e "src = spec.to_ruby" \
1596-
-e "src.sub!(/^$$/) {" \
1597-
-e "%[# default: #{g} #{File.mtime(g).strftime(%[%s.%N])}\n]" \
1598-
-e "}" \
1599-
-e "File.binwrite(File.join(destdir, spec.full_name+'.gemspec'), src)" \
1600-
-e "end" \
1601-
-e "end" \
1602-
-- .bundle/specifications lib ext
1583+
$(Q)$(MINIRUBY) -W0 -C "$(srcdir)" -I tool/lib -roptparse -routput -rbundled_gem \
1584+
-e "(out = Output.new).def_options(ARGV.options)" \
1585+
-e "BundledGem.update_default_gemspecs(ARGV.parse!, out, quiet: $(V).zero?)" \
1586+
-- -c -o .bundle/specifications lib ext
16031587

16041588
install-for-test-bundled-gems: $(TEST_RUNNABLE)-install-for-test-bundled-gems
16051589
no-install-for-test-bundled-gems: no-update-default-gemspecs

tool/lib/bundled_gem.rb

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -130,4 +130,30 @@ def checkout(gemdir, repo, rev, git: $git)
130130
command = "#{git} checkout --detach #{rev}"
131131
system(command, chdir: gemdir) or raise "failed: #{command}"
132132
end
133+
134+
def load_gemspec(g)
135+
dir, base = File.split(g)
136+
spec = Dir.chdir(dir) {Gem::Specification.load(base)} || Gem::Specification.load(g) or
137+
return false
138+
spec.files.clear
139+
spec.extensions.clear
140+
src = spec.to_ruby
141+
src.sub!(/^$$/) {
142+
%[# default: #{g} #{File.mtime(g).strftime(%[%s.%N])}\n]
143+
}
144+
return spec.full_name+'.gemspec', src
145+
end
146+
147+
def update_default_gemspecs(basedirs, out, quiet: true)
148+
basedirs.each do |basedir|
149+
Dir.glob(basedir+'/**/*.gemspec') do |g|
150+
name, src = BundledGem.load_gemspec(g)
151+
unless src
152+
puts "Ignoring #{g}" unless quiet
153+
next
154+
end
155+
out.write(src, name: name, quiet: quiet)
156+
end
157+
end
158+
end
133159
end

tool/lib/output.rb

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -31,30 +31,30 @@ def def_options(opt)
3131
@vpath.def_options(opt)
3232
end
3333

34-
def write(data, overwrite: @overwrite, create_only: @create_only)
35-
unless @path
34+
def write(data, overwrite: @overwrite, create_only: @create_only, name: nil, quiet: false)
35+
outpath = name ? @path ? File.join(@path, name) : name : @path
36+
unless outpath
3637
$stdout.print data
3738
return true
3839
end
3940
color = Colorize.new(@color)
4041
unchanged = color.pass("unchanged")
4142
updated = color.fail("updated")
42-
outpath = nil
4343

44-
if (@ifchange or overwrite or create_only) and (@vpath.open(@path, "rb") {|f|
44+
if (@ifchange or overwrite or create_only) and (@vpath.open(outpath, "rb") {|f|
4545
outpath = f.path
4646
if @ifchange or create_only
4747
original = f.read
4848
(@ifchange and original == data) or (create_only and !original.empty?)
4949
end
5050
} rescue false)
51-
puts "#{outpath} #{unchanged}"
51+
puts "#{outpath} #{unchanged}" unless quiet
5252
written = false
5353
else
5454
unless overwrite and outpath and (File.binwrite(outpath, data) rescue nil)
55-
File.binwrite(outpath = @path, data)
55+
File.binwrite(outpath, data)
5656
end
57-
puts "#{outpath} #{updated}"
57+
puts "#{outpath} #{updated}" unless quiet
5858
written = true
5959
end
6060
if timestamp = @timestamp

0 commit comments

Comments
 (0)