mirror of
https://gitlab.com/mbunkus/mkvtoolnix.git
synced 2025-01-10 20:23:39 +00:00
ab6455f68c
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
37 lines
946 B
Ruby
37 lines
946 B
Ruby
module Mtx
|
|
module CompilationDatabase
|
|
@file_name = "#{$build_dir}/compile_commands.json"
|
|
@compilation_commands = {}
|
|
|
|
def self.database_file_name
|
|
@file_name
|
|
end
|
|
|
|
def self.read
|
|
return {} unless FileTest.exist?(@file_name)
|
|
|
|
Hash[
|
|
*JSON.parse(IO.readlines(@file_name).join("")).
|
|
map { |entry| [ entry["file"], entry ] }.
|
|
flatten
|
|
]
|
|
end
|
|
|
|
def self.write
|
|
return if @compilation_commands.empty?
|
|
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|
|
|
f.write(JSON.generate(entries, :indent => " ", :object_nl => "\n", :array_nl => "\n"))
|
|
end
|
|
end
|
|
|
|
def self.add entry
|
|
@compilation_commands[entry["file"]] = entry
|
|
end
|
|
end
|
|
end
|
|
|
|
at_exit { Mtx::CompilationDatabase.write }
|