Class: Homebrew::ExecutablesDB Private
- Includes:
- Utils::Output::Mixin
- Defined in:
- executables_db.rb
Overview
This class is part of a private API. This class may only be used in the Homebrew/brew repository. Third parties should avoid using this class if possible, as it may be removed or changed without warning.
ExecutablesDB represents a DB associating formulae to the binaries they provide.
Constant Summary collapse
- DB_LINE_REGEX =
This constant is part of a private API. This constant may only be used in the Homebrew/brew repository. Third parties should avoid using this constant if possible, as it may be removed or changed without warning.
/^(?<name>.*?)(?:\([^)]*\))?:(?<exes_line>.*)?$/
Instance Method Summary collapse
-
#initialize(filename) ⇒ void
constructor
private
initialize a new DB with the given filename.
-
#save! ⇒ void
private
save the DB in the underlying file.
- #update!(bottle_json_dir: nil, removed_formulae: []) ⇒ void private
Methods included from Utils::Output::Mixin
#issue_reporting_message, #odebug, #odeprecated, #odie, #odisabled, #ofail, #oh1, #oh1_title, #ohai, #ohai_title, #onoe, #opoo, #opoo_outside_github_actions, #pretty_deprecated, #pretty_disabled, #pretty_duration, #pretty_install_status, #pretty_installed, #pretty_outdated, #pretty_uninstalled, #pretty_upgradable
Constructor Details
#initialize(filename) ⇒ void
This method is part of a private API. This method may only be used in the Homebrew/brew repository. Third parties should avoid using this method if possible, as it may be removed or changed without warning.
initialize a new DB with the given filename. The file will be used to populate the DB if it exists. It'll be created or overridden when saving the DB.
22 23 24 25 26 27 28 29 30 31 32 33 34 |
# File 'executables_db.rb', line 22 def initialize(filename) @filename = filename @exes = T.let({}, T::Hash[String, T::Array[String]]) return unless File.file? @filename File.new(@filename).each do |line| matches = line.match DB_LINE_REGEX next unless matches @exes[matches[:name].to_s] ||= matches[:exes_line]&.split || [] end end |
Instance Method Details
#save! ⇒ void
This method is part of a private API. This method may only be used in the Homebrew/brew repository. Third parties should avoid using this method if possible, as it may be removed or changed without warning.
This method returns an undefined value.
save the DB in the underlying file
76 77 78 79 80 81 82 |
# File 'executables_db.rb', line 76 def save! File.open(@filename, "w") do |f| @exes.sort.each do |formula, binaries| f.write "#{formula}:#{binaries.join(" ")}\n" end end end |
#update!(bottle_json_dir: nil, removed_formulae: []) ⇒ void
This method is part of a private API. This method may only be used in the Homebrew/brew repository. Third parties should avoid using this method if possible, as it may be removed or changed without warning.
This method returns an undefined value.
37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 |
# File 'executables_db.rb', line 37 def update!(bottle_json_dir: nil, removed_formulae: []) if (json_dir = bottle_json_dir.presence) && Pathname(json_dir).directory? Dir[File.join(json_dir, "**", "*.bottle.json")].each do |path| bottle_json = begin T.cast(JSON.parse(File.read(path)), T::Hash[String, T::Hash[String, T.untyped]]) rescue JSON::ParserError => e opoo "Skipping #{path}: #{e.}" next end bottle_json.each do |full_name, hash| = T.cast( hash.dig("bottle", "tags") || {}, T::Hash[String, T::Hash[String, T.untyped]], ).values.select { |tag_hash| tag_hash.key?("path_exec_files") } if .empty? opoo "Skipping #{full_name}: no `path_exec_files` in #{path}" next end @exes[hash.dig("formula", "name").to_s.presence || File.basename(full_name, ".rb")] = .flat_map { |tag_hash| Array(tag_hash["path_exec_files"]) } .map { |file| File.basename(file.to_s) } .uniq .sort end end end removed_formulae.uniq.sort.each do |name| next unless @exes.delete(name) puts "Removed #{name}" end end |