Module: Homebrew::API::Formula Private
- Extended by:
- Cachable
- Defined in:
- api/formula.rb
Overview
This module is part of a private API. This module may only be used in the Homebrew/brew repository. Third parties should avoid using this module if possible, as it may be removed or changed without warning.
Helper functions for using the formula JSON API.
Constant Summary collapse
- DEFAULT_API_FILENAME =
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.
"formula.jws.json"
Class Method Summary collapse
- .all_aliases ⇒ Hash{String => String} private
- .all_formulae ⇒ Hash{String => T.untyped} private
- .all_renames ⇒ Hash{String => String} private
- .cached_json_file_path ⇒ Pathname private
- .fetch_api!(download_queue: nil, stale_seconds: nil) ⇒ Array<([Array<T.untyped>, Hash{String => T.untyped}], Boolean)> private
- .fetch_formula_json!(name, download_queue: nil) ⇒ void private
- .fetch_tap_migrations!(download_queue: nil, stale_seconds: nil) ⇒ Array<([Array<T.untyped>, Hash{String => T.untyped}], Boolean)> private
- .formula_json(name) ⇒ Hash{String => T.untyped} private
- .generate_formula_struct_hash(hash) ⇒ FormulaStruct private
- .source_download(formula, download_queue: nil) ⇒ Homebrew::API::SourceDownload private
- .source_download_formula(formula) ⇒ ::Formula private
- .tap_migrations ⇒ Hash{String => T.untyped} private
- .write_names_and_aliases(regenerate: false) ⇒ void private
Methods included from Cachable
Class Method Details
.all_aliases ⇒ Hash{String => String}
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.
125 126 127 128 129 130 131 132 |
# File 'api/formula.rb', line 125 def self.all_aliases unless cache.key?("aliases") json_updated = download_and_cache_data! write_names_and_aliases(regenerate: json_updated) end cache.fetch("aliases") end |
.all_formulae ⇒ Hash{String => T.untyped}
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.
115 116 117 118 119 120 121 122 |
# File 'api/formula.rb', line 115 def self.all_formulae unless cache.key?("formulae") json_updated = download_and_cache_data! write_names_and_aliases(regenerate: json_updated) end cache.fetch("formulae") end |
.all_renames ⇒ Hash{String => String}
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.
135 136 137 138 139 140 141 142 |
# File 'api/formula.rb', line 135 def self.all_renames unless cache.key?("renames") json_updated = download_and_cache_data! write_names_and_aliases(regenerate: json_updated) end cache.fetch("renames") end |
.cached_json_file_path ⇒ Pathname
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.
73 74 75 |
# File 'api/formula.rb', line 73 def self.cached_json_file_path HOMEBREW_CACHE_API/DEFAULT_API_FILENAME end |
.fetch_api!(download_queue: nil, stale_seconds: nil) ⇒ Array<([Array<T.untyped>, Hash{String => T.untyped}], Boolean)>
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.
81 82 83 |
# File 'api/formula.rb', line 81 def self.fetch_api!(download_queue: nil, stale_seconds: nil) Homebrew::API.fetch_json_api_file DEFAULT_API_FILENAME, stale_seconds:, download_queue: end |
.fetch_formula_json!(name, download_queue: nil) ⇒ 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.
28 29 30 31 32 33 34 35 36 37 |
# File 'api/formula.rb', line 28 def self.fetch_formula_json!(name, download_queue: nil) endpoint = "formula/#{name}.json" json_formula, updated = Homebrew::API.fetch_json_api_file endpoint, download_queue: download_queue return if download_queue json_formula = JSON.parse((HOMEBREW_CACHE_API/endpoint).read) unless updated cache["formula_json"] ||= {} cache["formula_json"][name] = json_formula end |
.fetch_tap_migrations!(download_queue: nil, stale_seconds: nil) ⇒ Array<([Array<T.untyped>, Hash{String => T.untyped}], Boolean)>
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.
89 90 91 |
# File 'api/formula.rb', line 89 def self.fetch_tap_migrations!(download_queue: nil, stale_seconds: nil) Homebrew::API.fetch_json_api_file "formula_tap_migrations.jws.json", stale_seconds:, download_queue: end |
.formula_json(name) ⇒ Hash{String => T.untyped}
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.
21 22 23 24 25 |
# File 'api/formula.rb', line 21 def self.formula_json(name) fetch_formula_json! name if !cache.key?("formula_json") || !cache.fetch("formula_json").key?(name) cache.fetch("formula_json").fetch(name) end |
.generate_formula_struct_hash(hash) ⇒ FormulaStruct
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.
163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 |
# File 'api/formula.rb', line 163 def self.generate_formula_struct_hash(hash) hash = Homebrew::API.merge_variations(hash).dup if (caveats = hash["caveats"]) hash["caveats"] = Formulary.replace_placeholders(caveats) end hash["bottle_checksums"] = begin files = hash.dig("bottle", "stable", "files") || {} files.map do |tag, bottle_spec| { cellar: Formulary.convert_to_string_or_symbol(bottle_spec.fetch("cellar")), tag.to_sym => bottle_spec.fetch("sha256"), } end end hash["bottle_rebuild"] = hash.dig("bottle", "stable", "rebuild") conflicts_with = hash["conflicts_with"] || [] conflicts_with_reasons = hash["conflicts_with_reasons"] || [] hash["conflicts"] = conflicts_with.zip(conflicts_with_reasons).map do |name, reason| if reason.present? [name, { because: reason }] else [name, {}] end end if (deprecate_args = hash["deprecate_args"]) deprecate_args = deprecate_args.dup.transform_keys(&:to_sym) deprecate_args[:because] = DeprecateDisable.to_reason_string_or_symbol(deprecate_args[:because], type: :formula) hash["deprecate_args"] = deprecate_args end if (disable_args = hash["disable_args"]) disable_args = disable_args.dup.transform_keys(&:to_sym) disable_args[:because] = DeprecateDisable.to_reason_string_or_symbol(disable_args[:because], type: :formula) hash["disable_args"] = disable_args end hash["head_dependency_hash"] = hash["head_dependencies"] hash["head_url_args"] = begin url = hash.dig("urls", "head", "url") specs = { branch: hash.dig("urls", "head", "branch"), using: hash.dig("urls", "head", "using")&.to_sym, }.compact_blank [url, specs] end if (keg_only_hash = hash["keg_only_reason"]) reason = Formulary.convert_to_string_or_symbol(keg_only_hash.fetch("reason")) explanation = keg_only_hash["explanation"] hash["keg_only_args"] = [reason, explanation].compact end hash["license"] = SPDX.string_to_license_expression(hash["license"]) hash["link_overwrite_paths"] = hash["link_overwrite"] if (reason = hash["no_autobump_message"]) reason = reason.to_sym if NO_AUTOBUMP_REASONS_LIST.key?(reason.to_sym) hash["no_autobump_args"] = { because: reason } end if (condition = hash["pour_bottle_only_if"]) hash["pour_bottle_args"] = { only_if: condition.to_sym } end hash["requirements_array"] = hash["requirements"] hash["ruby_source_checksum"] = hash.dig("ruby_source_checksum", "sha256") if (service_hash = hash["service"]) service_hash = Homebrew::Service.from_hash(service_hash) hash["service_run_args"], hash["service_run_kwargs"] = case (run = service_hash[:run]) when Hash [[], run] when Array, String [[run], {}] else [[], {}] end hash["service_name_args"] = service_hash[:name] hash["service_args"] = service_hash.filter_map do |key, arg| [key.to_sym, arg] if key != :name && key != :run end end hash["stable_checksum"] = hash.dig("urls", "stable", "checksum") hash["stable_dependency_hash"] = { "dependencies" => hash["dependencies"] || [], "build_dependencies" => hash["build_dependencies"] || [], "test_dependencies" => hash["test_dependencies"] || [], "recommended_dependencies" => hash["recommended_dependencies"] || [], "optional_dependencies" => hash["optional_dependencies"] || [], "uses_from_macos" => hash["uses_from_macos"] || [], "uses_from_macos_bounds" => hash["uses_from_macos_bounds"] || [], } hash["stable_url_args"] = begin url = hash.dig("urls", "stable", "url") specs = { tag: hash.dig("urls", "stable", "tag"), revision: hash.dig("urls", "stable", "revision"), using: hash.dig("urls", "stable", "using")&.to_sym, }.compact_blank [url, specs] end hash["stable_version"] = hash.dig("versions", "stable") # Should match FormulaStruct::PREDICATES hash["bottle_present"] = hash["bottle"].present? hash["deprecated_present"] = hash["deprecation_date"].present? hash["disabled_present"] = hash["disable_date"].present? hash["head_present"] = hash.dig("urls", "head").present? hash["keg_only_present"] = hash["keg_only_reason"].present? hash["no_autobump_message_present"] = hash["no_autobump_message"].present? hash["pour_bottle_present"] = hash["pour_bottle_only_if"].present? hash["service_present"] = hash["service"].present? hash["service_run_present"] = hash.dig("service", "run").present? hash["service_name_present"] = hash.dig("service", "name").present? hash["stable_present"] = hash.dig("urls", "stable").present? FormulaStruct.from_hash(hash) end |
.source_download(formula, download_queue: nil) ⇒ Homebrew::API::SourceDownload
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.
40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 |
# File 'api/formula.rb', line 40 def self.source_download(formula, download_queue: nil) path = formula.ruby_source_path || "Formula/#{formula.name}.rb" git_head = formula.tap_git_head || "HEAD" tap = formula.tap&.full_name || "Homebrew/homebrew-core" download = Homebrew::API::SourceDownload.new( "https://raw.githubusercontent.com/#{tap}/#{git_head}/#{path}", formula.ruby_source_checksum, cache: HOMEBREW_CACHE_API_SOURCE/"#{tap}/#{git_head}/Formula", ) if download_queue download_queue.enqueue(download) elsif !download.symlink_location.exist? download.fetch end download end |
.source_download_formula(formula) ⇒ ::Formula
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.
61 62 63 64 65 66 67 68 69 70 |
# File 'api/formula.rb', line 61 def self.source_download_formula(formula) download = source_download(formula) with_env(HOMEBREW_INTERNAL_ALLOW_PACKAGES_FROM_PATHS: "1") do Formulary.factory(download.symlink_location, formula.active_spec_sym, alias_path: formula.alias_path, flags: formula.class.build_flags) end end |
.tap_migrations ⇒ Hash{String => T.untyped}
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.
145 146 147 148 149 150 151 152 |
# File 'api/formula.rb', line 145 def self.tap_migrations unless cache.key?("tap_migrations") json_migrations, = fetch_tap_migrations! cache["tap_migrations"] = json_migrations end cache.fetch("tap_migrations") end |
.write_names_and_aliases(regenerate: false) ⇒ 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.
155 156 157 158 159 160 |
# File 'api/formula.rb', line 155 def self.write_names_and_aliases(regenerate: false) download_and_cache_data! unless cache.key?("formulae") Homebrew::API.write_names_file!(all_formulae.keys, "formula", regenerate:) Homebrew::API.write_aliases_file!(all_aliases, "formula", regenerate:) end |