build system: fix compatibility with Ruby 3.2.0

Several deprecated functions were removed: `Dir.exists?`,
`File.exists?` & `FileTest.exists?`.  Instead of those
`FileTest.exist?` must be used (without the `s`). See the release
notes for Ruby 3.2.0 as well as the issue for removing the functions:

https://www.ruby-lang.org/en/news/2022/12/25/ruby-3-2-0-released/
https://bugs.ruby-lang.org/issues/17391
This commit is contained in:
Moritz Bunkus 2023-01-02 22:27:27 +01:00
parent 63ebac6a56
commit ab6455f68c
No known key found for this signature in database
GPG Key ID: 74AF00ADF2E32C85
16 changed files with 41 additions and 32 deletions

View File

@ -1,3 +1,12 @@
# Version ?
## Bug fixes
* build system: fixed compatibility with Ruby 3.2.0 by using `FileTest.exist?`
instead of `File.exists?`, `Dir.exists?` & `FileTest.exists?` which were
removed in that release.
# Version 73.0.0 "25 or 6 to 4" 2023-01-02
## New features and enhancements

View File

@ -277,7 +277,7 @@ def define_default_task
targets << ($run_unit_tests ? 'tests:run_unit' : 'tests:unit') if $have_gtest
# The tags file -- but only if it exists already
if File.exists?("TAGS")
if FileTest.exist?("TAGS")
targets << "TAGS" if !c(:ETAGS).empty?
targets << "BROWSE" if !c(:EBROWSE).empty?
end
@ -454,7 +454,7 @@ end
rule '.1' => '.xml' do |t|
filter = lambda do |code, lines|
if (0 == code) && lines.any? { |line| /^error|parser error/i.match(line) }
File.unlink(t.name) if File.exists?(t.name)
File.unlink(t.name) if FileTest.exist?(t.name)
result = 1
puts lines.join('')
@ -668,7 +668,7 @@ EOT
if $po4a_cfg
desc "Update the man pages' translation files"
task :manpages do
FileUtils.touch($po4a_pot) if !FileTest.exists?($po4a_pot)
FileUtils.touch($po4a_pot) if !FileTest.exist?($po4a_pot)
runq "po4a", "#{$po4a_cfg} (update PO/POT)", "#{c(:PO4A)} #{$flags[:po4a]} --no-translations ${po4a_cfg}"
$all_man_po_files.each do |po_file|
@ -822,8 +822,8 @@ if $po4a_cfg
po4a_sources += $available_languages[:manpages].map { |language| "doc/man/po4a/po/#{language}.po" }
file $po4a_stamp => po4a_sources do |t|
File.unlink($po4a_stamp) if FileTest.exists?($po4a_stamp)
FileUtils.touch($po4a_pot) if !FileTest.exists?($po4a_pot)
File.unlink($po4a_stamp) if FileTest.exist?($po4a_stamp)
FileUtils.touch($po4a_pot) if !FileTest.exist?($po4a_pot)
runq "po4a", "#{$po4a_cfg}", "#{c(:PO4A)} #{$flags[:po4a]} #{$po4a_cfg}", :filter_output => po4a_output_filter
runq_touch $po4a_stamp
@ -1054,7 +1054,7 @@ task :clean do
remove_files_by_patterns patterns
if Dir.exists? $dependency_dir
if FileTest.exist? $dependency_dir
puts_vaction "rm -rf", :target => "#{$dependency_dir}"
FileUtils.rm_rf $dependency_dir
end

View File

@ -7,7 +7,7 @@ fail "Missing file list name" if ARGV.empty?
config = read_config
file_name = ARGV[0]
file_name = "#{config['file_list_dir']}/#{file_name}.txt" if !FileTest.exists?(file_name)
file_name = "#{config['file_list_dir']}/#{file_name}.txt" if !FileTest.exist?(file_name)
files = IO.readlines(file_name).map { |file| file.chomp.gsub(%r{^\.}, '').gsub(%r{^/}, '').gsub(%r{/}, '\\') }
dirs = {}

View File

@ -8,7 +8,7 @@ module Mtx
end
def self.read
return {} unless FileTest.exists?(@file_name)
return {} unless FileTest.exist?(@file_name)
Hash[
*JSON.parse(IO.readlines(@file_name).join("")).
@ -19,7 +19,7 @@ module Mtx
def self.write
return if @compilation_commands.empty?
return if !FileTest.exists?(@file_name) && !c?(:BUILD_COMPILATION_DATABASE)
return if !FileTest.exist?(@file_name) && !c?(:BUILD_COMPILATION_DATABASE)
entries = self.read.merge(@compilation_commands).values.sort_by { |e| e["file"] }
File.open(@file_name, "w") do |f|

View File

@ -13,10 +13,10 @@ end
def read_build_config
dir = File.dirname(__FILE__) + '/..'
fail "build-config not found: please run ./configure" unless File.exists?("#{dir}/build-config")
fail "build-config not found: please run ./configure" unless FileTest.exist?("#{dir}/build-config")
config = read_config_file("#{dir}/build-config")
config = config.merge(read_config_file("#{dir}/build-config.local")) if File.exists?("#{dir}/build-config.local")
config = config.merge(read_config_file("#{dir}/build-config.local")) if FileTest.exist?("#{dir}/build-config.local")
config
end

View File

@ -181,7 +181,7 @@ def import_dependencies
Dir.glob("#{$dependency_dir}/*.dep").each do |file_name|
lines = IO.readlines(file_name).collect(&:chomp)
target = lines.shift
file target => lines.select { |dep_name| File.exists? dep_name }
file target => lines.select { |dep_name| FileTest.exist? dep_name }
end
end
@ -211,7 +211,7 @@ def install_data(destination, *files)
end
def remove_files_by_patterns patterns
patterns.collect { |pattern| FileList[pattern].to_a }.flatten.uniq.select { |file_name| File.exists? file_name }.each do |file_name|
patterns.collect { |pattern| FileList[pattern].to_a }.flatten.uniq.select { |file_name| FileTest.exist? file_name }.each do |file_name|
puts_vaction "rm", :target => file_name
File.unlink file_name
end
@ -254,7 +254,7 @@ def check_version required, actual
end
def ensure_file file_name, content = ""
if FileTest.exists?(file_name)
if FileTest.exist?(file_name)
current_content = IO.readlines(file_name).join("\n")
return if current_content == content
end
@ -267,7 +267,7 @@ def update_version_number_include
current_version = nil
wanted_version = c(:PACKAGE_VERSION)
if FileTest.exists?($version_header_name)
if FileTest.exist?($version_header_name)
lines = IO.readlines($version_header_name)
if !lines.empty? && %r{#define.*?"([0-9.]+)"}.match(lines[0])
@ -352,7 +352,7 @@ def update_qrc_worker qrc
double_size = size * 2
double_file = "share/icons/#{double_size}x#{double_size}/#{base_name}.png"
next unless FileTest.exists?(double_file)
next unless FileTest.exist?(double_file)
add_node.call(double_file, 'alias' => name_alias)
seen[file.gsub(%r{.*/icons}, 'icons')] = true

View File

@ -9,7 +9,7 @@ module Mtx::OnlineFile
file_name ||= url.gsub(%r{.*/}, '')
file_name = "tmp/#{file_name}"
if !FileTest.exists?(file_name)
if !FileTest.exist?(file_name)
@@to_unlink << file_name
runq "wget", url, "wget --quiet -O #{file_name} #{url}"
@ -30,7 +30,7 @@ module Mtx::OnlineFile
return if c?(:KEEP_DOWNLOADED_FILES)
@@to_unlink.
select { |fn| FileTest.exists? fn }.
select { |fn| FileTest.exist? fn }.
each { |fn| File.unlink fn }
end
end

View File

@ -1,6 +1,6 @@
def create_source_tarball suffix = ""
tarball = "#{Dir.pwd}/../mkvtoolnix-#{c(:PACKAGE_VERSION)}#{suffix}.tar.xz"
fail "#{tarball} does already exist" if FileTest.exists?(tarball)
fail "#{tarball} does already exist" if FileTest.exist?(tarball)
Dir.mktmpdir do |dir|
clone_dir = "#{dir}/mkvtoolnix-#{c(:PACKAGE_VERSION)}"

View File

@ -7,7 +7,7 @@ avi = "data/avi/v-h264-aac.avi"
chapters = "data/text/chapters-v-h264-aac.txt"
def hash_results max
( (1..max).collect { |i| hash_file(sprintf("%s-%02d", tmp, i)) } + [ File.exists?(sprintf("%s-%02d", tmp, max + 1)) ? 'bad' : 'ok' ]).join '+'
( (1..max).collect { |i| hash_file(sprintf("%s-%02d", tmp, i)) } + [ FileTest.exist?(sprintf("%s-%02d", tmp, max + 1)) ? 'bad' : 'ok' ]).join '+'
end
test "chapters-in-mkv: numbers 1 & 7" do

View File

@ -5,7 +5,7 @@ file = "data/avi/v-h264-aac.avi"
describe "mkvmerge / generate chapter »when-appending«"
def hash_results max
( (1..max).collect { |i| hash_file(sprintf("%s-%02d", tmp, i)) } + [ File.exists?(sprintf("%s-%02d", tmp, max + 1)) ? 'bad' : 'ok' ]).join '+'
( (1..max).collect { |i| hash_file(sprintf("%s-%02d", tmp, i)) } + [ FileTest.exist?(sprintf("%s-%02d", tmp, max + 1)) ? 'bad' : 'ok' ]).join '+'
end
test_merge "#{file} + #{file} + #{file}", :args => "--generate-chapters when-appending"

View File

@ -5,7 +5,7 @@ file = "data/avi/v-h264-aac.avi"
describe "mkvmerge / generate chapter »interval«"
def hash_results max
( (1..max).collect { |i| hash_file(sprintf("%s-%02d", tmp, i)) } + [ File.exists?(sprintf("%s-%02d", tmp, max + 1)) ? 'bad' : 'ok' ]).join '+'
( (1..max).collect { |i| hash_file(sprintf("%s-%02d", tmp, i)) } + [ FileTest.exist?(sprintf("%s-%02d", tmp, max + 1)) ? 'bad' : 'ok' ]).join '+'
end
test_merge "#{file} + #{file} + #{file}", :args => "--generate-chapters interval:30s"

View File

@ -5,7 +5,7 @@ file = "data/simple/v.mp3"
describe "mkvmerge / generate chapter »when-appending« without video tracks"
def hash_results max
( (1..max).collect { |i| hash_file(sprintf("%s-%02d", tmp, i)) } + [ File.exists?(sprintf("%s-%02d", tmp, max + 1)) ? 'bad' : 'ok' ]).join '+'
( (1..max).collect { |i| hash_file(sprintf("%s-%02d", tmp, i)) } + [ FileTest.exist?(sprintf("%s-%02d", tmp, max + 1)) ? 'bad' : 'ok' ]).join '+'
end
test_merge "#{file} + #{file} + #{file}", :args => "--generate-chapters when-appending"

View File

@ -5,7 +5,7 @@ file = "data/simple/v.mp3"
describe "mkvmerge / generate chapter »interval« without video tracks"
def hash_results max
( (1..max).collect { |i| hash_file(sprintf("%s-%02d", tmp, i)) } + [ File.exists?(sprintf("%s-%02d", tmp, max + 1)) ? 'bad' : 'ok' ]).join '+'
( (1..max).collect { |i| hash_file(sprintf("%s-%02d", tmp, i)) } + [ FileTest.exist?(sprintf("%s-%02d", tmp, max + 1)) ? 'bad' : 'ok' ]).join '+'
end
test_merge "#{file} + #{file} + #{file}", :args => "--generate-chapters interval:30s"

View File

@ -85,7 +85,7 @@ class SimpleTest
end
def clean_tmp
File.unlink(@tmp) if @tmp && File.exists?(@tmp) && !ENV["KEEP_TMPFILES"].nil? && (ENV["KEEP_TMPFILES"] != "1")
File.unlink(@tmp) if @tmp && FileTest.exist?(@tmp) && !ENV["KEEP_TMPFILES"].nil? && (ENV["KEEP_TMPFILES"] != "1")
@tmp = nil
end
@ -106,7 +106,7 @@ class SimpleTest
re = %r{^#{self.tmp_name_prefix}}
Dir.entries($temp_dir).each do |entry|
file = "#{$temp_dir}/#{entry}"
File.unlink(file) if re.match(file) and File.exists?(file)
File.unlink(file) if re.match(file) and FileTest.exist?(file)
end
end
@ -326,7 +326,7 @@ class SimpleTest
command = "../src/mkvpropedit --engage no_variable_data #{file_name} #{args.first}"
*result = self.sys command, :exit_code => options[:exit_code], :no_result => options[:no_result]
self.sys "../src/tools/ebml_validator -M #{file_name}", dont_record_command: true if FileTest.exists?("../src/tools/ebml_validator")
self.sys "../src/tools/ebml_validator -M #{file_name}", dont_record_command: true if FileTest.exist?("../src/tools/ebml_validator")
return *result
end

View File

@ -25,7 +25,7 @@ class Test
re = /^#{self.tmp_name_prefix}/
Dir.entries($temp_dir).each do |entry|
file = "#{$temp_dir}/#{entry}"
File.unlink(file) if re.match(file) and File.exists?(file)
File.unlink(file) if re.match(file) and FileTest.exist?(file)
end
end
@ -84,7 +84,7 @@ class Test
output = hash_file @tmp
if erase
File.unlink(@tmp) if File.exists?(@tmp) && (ENV["KEEP_TMPFILES"] != "1")
File.unlink(@tmp) if FileTest.exist?(@tmp) && (ENV["KEEP_TMPFILES"] != "1")
@debug_commands << "rm #{@tmp}"
@tmp = nil
end
@ -111,7 +111,7 @@ class Test
command = "../src/mkvpropedit --engage no_variable_data #{file_name} #{args.shift}"
*result = sys command, retcode
sys "../src/tools/ebml_validator -M #{file_name}", :dont_record_command => true if FileTest.exists?("../src/tools/ebml_validator")
sys "../src/tools/ebml_validator -M #{file_name}", :dont_record_command => true if FileTest.exist?("../src/tools/ebml_validator")
return *result
end

View File

@ -106,11 +106,11 @@ module AddPo
base ||= ''
target = "#{$po_dir}/qt/qt#{base}_#{language}.ts"
if !FileTest.exists?(target) && /^([a-z]+)_[a-z]+/i.match(language)
if !FileTest.exist?(target) && /^([a-z]+)_[a-z]+/i.match(language)
target = "#{$po_dir}/qt/qt#{base}_#{$1}.ts"
end
fail "target file does not exist yet: #{target} (wrong language?)" if !FileTest.exists?(target)
fail "target file does not exist yet: #{target} (wrong language?)" if !FileTest.exist?(target)
File.open(target, "w") { |file| file.puts content.map(&:chomp).join("\n") }
File.unlink file_name