Class: Homebrew::DevCmd::GenerateInternalApi Private
- Inherits:
-
AbstractCommand
- Object
- AbstractCommand
- Homebrew::DevCmd::GenerateInternalApi
- Defined in:
- dev-cmd/generate-internal-api.rb,
sorbet/rbi/dsl/homebrew/dev_cmd/generate_internal_api.rbi
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.
Defined Under Namespace
Classes: Args
Instance Method Summary collapse
- #args ⇒ Homebrew::DevCmd::GenerateInternalApi::Args private
- #run ⇒ void private
Methods inherited from AbstractCommand
command, command_name, dev_cmd?, #initialize, parser, ruby_cmd?
Methods included from Utils::Output::Mixin
#issue_reporting_message, #odebug, #odeprecated, #odie, #odisabled, #ofail, #oh1, #oh1_title, #ohai, #ohai_title, #onoe, #opoo, #opoo_once, #opoo_outside_github_actions, #opoo_without_github_actions_annotation, #pretty_cannot_install, #pretty_deprecated, #pretty_disabled, #pretty_duration, #pretty_incompatible, #pretty_install_status, #pretty_installed, #pretty_removed, #pretty_uninstalled, #pretty_unmarked, #pretty_upgradable, #pretty_warning
Constructor Details
This class inherits a constructor from Homebrew::AbstractCommand
Instance Method Details
#args ⇒ Homebrew::DevCmd::GenerateInternalApi::Args
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.
10 |
# File 'sorbet/rbi/dsl/homebrew/dev_cmd/generate_internal_api.rbi', line 10 def args; end |
#run ⇒ 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.
29 30 31 32 33 34 35 36 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 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 |
# File 'dev-cmd/generate-internal-api.rb', line 29 def run core_tap = CoreTap.instance cask_tap = CoreCaskTap.instance raise TapUnavailableError, core_tap.name unless core_tap.installed? raise TapUnavailableError, cask_tap.name unless cask_tap.installed? unless args.dry_run? FileUtils.rm_rf "api/internal" FileUtils.mkdir_p "api/internal" end executables_path = Pathname("api/internal/executables.txt") # Use the existing executables database as the API generation source. # It is generated from GitHub Packages metadata, not generated API JSON. if !args.dry_run? && !Homebrew::API.download_executables_file_from_github_packages!(executables_path) odie "Failed to download #{executables_path}" end executables = ExecutablesDB.new(executables_path.to_s).to_hash Homebrew::API.with_no_api_env do Formulary.enable_factory_cache! Formula. Cask::Cask. all_formulae = {} all_casks = {} bottle_manifests = {} latest_macos = MacOSVersion.new(HOMEBREW_MACOS_NEWEST_SUPPORTED).to_sym Homebrew::SimulateSystem.with(os: latest_macos, arch: :arm) do core_tap.formula_names.each do |name| formula = Formulary.factory(name) name = formula.name all_formulae[name] = formula.to_hash_with_variations(include_compiler_variations: true) all_formulae[name]["executables"] = executables[name] if executables.key?(name) bottle_hash = all_formulae[name].dig("bottle", "stable") || {} next unless bottle_hash.key?("manifest_sha256") # Any bottle will do: the block's digest is that of the index listing them all. bottle_tag = Utils::Bottles::Tag.from_symbol(bottle_hash.fetch("files").keys.first) bottle_manifests[name] = formula.bottle_for_tag(bottle_tag)&.github_packages_manifest_resource rescue onoe "Error while generating data for formula '#{name}'." raise end # Clients fetch a bottle's own manifest by the digest its pinned index # lists, so a missing or mismatched index must fail the run. download_queue = Homebrew::DownloadQueue.new bottle_manifests.compact! bottle_manifests.each_value do |manifest| download_queue.enqueue(manifest) unless manifest.downloaded_and_valid? end download_queue.fetch download_queue.shutdown odie "Failed to download bottle manifests." if download_queue.failed_downloads.present? bottle_manifests.each do |name, manifest| manifest_sha256s = manifest.platform_manifest_sha256s all_formulae.fetch(name).dig("bottle", "stable", "files").each do |tag, file| file["manifest_sha256"] = manifest_sha256s.fetch([manifest.image_ref(tag), file.fetch("sha256")]) end end cask_tap.cask_files.each do |path| cask = Cask::CaskLoader.from_path(path) name = cask.token all_casks[name] = cask.to_hash_with_variations rescue onoe "Error while generating data for cask '#{path.stem}'." raise end end OnSystem::VALID_OS_ARCH_TAGS.each do |bottle_tag| formulae = all_formulae.to_h do |name, hash| hash = Homebrew::API::Formula::FormulaStructGenerator.generate_formula_struct_hash(hash, bottle_tag:) .serialize(bottle_tag:) [name, hash] end casks = all_casks.to_h do |token, hash| hash = Homebrew::API::Cask::CaskStructGenerator.generate_cask_struct_hash(hash, bottle_tag:) .serialize [token, hash] end json_contents = { metadata: { homebrew_version: HOMEBREW_VERSION, bottle_tag: bottle_tag.to_s, generated_at: Time.now.to_i, }, formulae:, casks:, formula_aliases: core_tap.alias_table, formula_renames: core_tap.formula_renames, cask_renames: cask_tap.cask_renames, formula_tap_git_head: core_tap.git_head, cask_tap_git_head: cask_tap.git_head, formula_tap_migrations: core_tap.tap_migrations, cask_tap_migrations: cask_tap.tap_migrations, } File.write("api/internal/packages.#{bottle_tag}.json", JSON.generate(json_contents)) unless args.dry_run? end end end |