1
0
Fork 0
mirror of https://github.com/ruby/ruby.git synced 2022-11-09 12:17:21 -05:00

Workaround an encoding problem in run_without_tabs

It's to be fixed properly later. But this should be able to avoid the failure.

https://travis-ci.org/github/ruby/ruby/jobs/665580361
https://rubyci.org/logs/rubyci.s3.amazonaws.com/solaris10-gcc/ruby-master/log/20200322T190003Z.fail.html.gz
This commit is contained in:
Takashi Kokubun 2020-03-22 12:18:46 -07:00
parent 9ebf74fd78
commit dec0f582e4
No known key found for this signature in database
GPG key ID: 6FFC433B12EE23DD

View file

@ -21,27 +21,36 @@ targets = Dir.glob(File.join(srcdir, 'vm*.*')) - SKIPPED_FILES.map { |f| File.jo
sources = {} sources = {}
mtimes = {} mtimes = {}
if skip = targets.any? { |target| !File.writable?(target) } targets.each do |target|
puts "tool/run_without_tabs.rb: srcdir has non-writable files. Skipping tab expansion." unless File.writable?(target)
puts "tool/run_without_tabs.rb: Skipping #{target.dump} as it's not writable."
next
end
source = File.read(target)
begin
expanded = source.gsub(/^\t+/) { |tab| ' ' * 8 * tab.length }
rescue ArgumentError # invalid byte sequence in UTF-8 (Travis, RubyCI)
puts "tool/run_without_tabs.rb: Skipping #{target.dump} as the encoding is #{source.encoding}."
next
end end
targets.each do |target| sources[target] = source
sources[target] = File.read(target)
mtimes[target] = File.mtime(target) mtimes[target] = File.mtime(target)
expanded = sources[target].force_encoding('UTF-8').gsub(/^\t+/) { |tab| ' ' * 8 * tab.length }
if sources[target] == expanded if sources[target] == expanded
puts "#{target.dump} has no hard tab indentation. This should be ignored in tool/run_without_tabs.rb." puts "#{target.dump} has no hard tab indentation. This should be ignored in tool/run_without_tabs.rb."
end end
File.write(target, expanded) File.write(target, expanded)
FileUtils.touch(target, mtime: mtimes[target]) FileUtils.touch(target, mtime: mtimes[target])
end unless skip end
result = system(*ARGV) result = system(*ARGV)
targets.each do |target| targets.each do |target|
File.write(target, sources.fetch(target)) if sources.key?(target)
File.write(target, sources[target])
FileUtils.touch(target, mtime: mtimes.fetch(target)) FileUtils.touch(target, mtime: mtimes.fetch(target))
end unless skip end
end
exit result exit result