mkvtoolnix/rake.d/config.rb
Moritz Bunkus ab6455f68c
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
2023-01-02 22:57:21 +01:00

35 lines
1.1 KiB
Ruby

def read_config_file file_name
result = Hash[ *IO.readlines(file_name).collect { |line| line.chomp.gsub(/#.*/, "") }.select { |line| !line.empty? }.collect do |line|
parts = line.split(/\s*=\s*/, 2).collect { |part| part.gsub(/^\s+/, '').gsub(/\s+$/, '') }
key = parts[0].gsub(%r{^export\s+}, '').to_sym
value = (parts[1] || '').gsub(%r{^"|"$}, '').gsub(%r{\\"}, '"')
[ key, value ]
end.flatten ]
result.default = ''
result
end
def read_build_config
dir = File.dirname(__FILE__) + '/..'
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 FileTest.exist?("#{dir}/build-config.local")
config
end
def c(idx, default = '')
idx_s = idx.to_s
var = (ENV[idx_s].nil? ? $config[idx.to_sym] : ENV[idx_s]).to_s
var = var.gsub(/\$[\({](.*?)[\)}]/) { c($1) }.gsub(/^\s+/, '').gsub(/\s+$/, '')
var.empty? ? default : var
end
def c?(idx)
c(idx).to_bool
end