Prefer File class methods to write a string

This commit is contained in:
Nobuyoshi Nakada 2022-08-31 21:53:01 +09:00
parent f3becd73e3
commit 762fca9b12
No known key found for this signature in database
GPG Key ID: 7CD2805BFA3770C6

View File

@ -345,7 +345,7 @@ def package(vcs, rev, destdir, tmp = nil)
v = v[0] v = v[0]
end end
open("#{v}/revision.h", "wb") {|f| File.open("#{v}/revision.h", "wb") {|f|
short = vcs.short_revision(revision) short = vcs.short_revision(revision)
f.puts "#define RUBY_REVISION #{short.inspect}" f.puts "#define RUBY_REVISION #{short.inspect}"
unless short == revision unless short == revision
@ -391,6 +391,7 @@ def package(vcs, rev, destdir, tmp = nil)
return return
end end
def (clean = []).add(n) push(n); n end def (clean = []).add(n) push(n); n end
def clean.create(file, content = "") File.binwrite(add(file), content) end
Dir.chdir(v) do Dir.chdir(v) do
unless File.exist?("ChangeLog") unless File.exist?("ChangeLog")
vcs.export_changelog(url, nil, revision, "ChangeLog") vcs.export_changelog(url, nil, revision, "ChangeLog")
@ -438,14 +439,12 @@ def package(vcs, rev, destdir, tmp = nil)
rescue Errno::ENOENT rescue Errno::ENOENT
# use fallback file # use fallback file
end end
File.open(clean.add("config.status"), "w") {|f| clean.create("config.status", status)
f.print status
}
FileUtils.mkpath(hdrdir = "#{extout}/include/ruby") FileUtils.mkpath(hdrdir = "#{extout}/include/ruby")
File.open("#{hdrdir}/config.h", "w") {} File.binwrite("#{hdrdir}/config.h", "")
FileUtils.mkpath(defaults = "#{extout}/rubygems/defaults") FileUtils.mkpath(defaults = "#{extout}/rubygems/defaults")
File.open("#{defaults}/operating_system.rb", "w") {} File.binwrite("#{defaults}/operating_system.rb", "")
File.open("#{defaults}/ruby.rb", "w") {} File.binwrite("#{defaults}/ruby.rb", "")
miniruby = ENV['MINIRUBY'] + " -I. -I#{extout} -rcross" miniruby = ENV['MINIRUBY'] + " -I. -I#{extout} -rcross"
baseruby = ENV["BASERUBY"] baseruby = ENV["BASERUBY"]
mk = (IO.read("template/Makefile.in") rescue IO.read("Makefile.in")). mk = (IO.read("template/Makefile.in") rescue IO.read("Makefile.in")).
@ -481,11 +480,9 @@ update-gems:
$(UNICODE_SRC_DATA_DIR)/.unicode-tables.time: $(UNICODE_SRC_DATA_DIR)/.unicode-tables.time:
touch-unicode-files: touch-unicode-files:
APPEND APPEND
open(clean.add("Makefile"), "w") do |f| clean.create("Makefile", mk)
f.puts mk clean.create("revision.tmp")
end clean.create(".revision.time")
File.open(clean.add("revision.tmp"), "w") {}
File.open(clean.add(".revision.time"), "w") {}
ENV["CACHE_SAVE"] = "no" ENV["CACHE_SAVE"] = "no"
make = MAKE.new(args) make = MAKE.new(args)
return unless make.run("update-download") return unless make.run("update-download")
@ -619,7 +616,7 @@ revisions.collect {|rev| package(vcs, rev, destdir, tmp)}.flatten.each do |name|
success = false success = false
next next
end end
str = open(name, "rb") {|f| f.read} str = File.binread(name)
pathname = Pathname(name) pathname = Pathname(name)
basename = pathname.basename.to_s basename = pathname.basename.to_s
extname = pathname.extname.sub(/\A\./, '') extname = pathname.extname.sub(/\A\./, '')