Class: Homebrew::DevCmd::GenerateFormulaApi Private
- Inherits:
-
AbstractCommand
- Object
- AbstractCommand
- Homebrew::DevCmd::GenerateFormulaApi
- Defined in:
- dev-cmd/generate-formula-api.rb,
sorbet/rbi/dsl/homebrew/dev_cmd/generate_formula_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
Constant Summary collapse
- FORMULA_JSON_TEMPLATE =
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.
<<~EOS --- layout: formula_json --- {{ content }} EOS
Instance Method Summary collapse
- #args ⇒ Homebrew::DevCmd::GenerateFormulaApi::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_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::GenerateFormulaApi::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_formula_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.
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 |
# File 'dev-cmd/generate-formula-api.rb', line 36 def run tap = CoreTap.instance raise TapUnavailableError, tap.name unless tap.installed? unless args.dry_run? directories = ["_data/formula", "api/formula", "formula", "api/internal"] FileUtils.rm_rf directories + ["_data/formula_canonical.json"] FileUtils.mkdir_p directories 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 # An advisory-database or network failure must not break the API build; # the `vulnerabilities` field is omitted and the build proceeds. advisories = begin Homebrew::Vulns::AdvisoryDatabase.load rescue Homebrew::Vulns::CachedFeed::Error, ErrorDuringExecution => e opoo "Skipping vulnerabilities field: #{e..lines.first&.strip}" nil end Homebrew::API.with_no_api_env do tap_migrations_json = JSON.dump(tap.tap_migrations) File.write("api/formula_tap_migrations.json", tap_migrations_json) unless args.dry_run? Formulary.enable_factory_cache! Formula. all_formulae = {} latest_macos = MacOSVersion.new((HOMEBREW_MACOS_NEWEST_UNSUPPORTED.to_i - 1).to_s).to_sym Homebrew::SimulateSystem.with(os: latest_macos, arch: :arm) do tap.formula_names.each do |name| formula = Formulary.factory(name) name = formula.name all_formulae[name] = formula.to_hash_with_variations all_formulae[name]["executables"] = executables[name] if executables.key?(name) if (vulns = advisories&.status_for(name, formula.pkg_version)) all_formulae[name]["vulnerabilities"] = vulns end unless args.dry_run? File.write("_data/formula/#{name.tr("+", "_")}.json", "#{JSON.pretty_generate(all_formulae[name])}\n") File.write("api/formula/#{name}.json", FORMULA_JSON_TEMPLATE) File.write("formula/#{name}.html", <<~EOS) --- title: '#{name}' layout: formula redirect_from: /formula-linux/#{name} --- {{ content }} EOS end rescue onoe "Error while generating data for formula '#{name}'." raise end end canonical_json = JSON.pretty_generate(tap.formula_renames.merge(tap.alias_table)) File.write("_data/formula_canonical.json", "#{canonical_json}\n") unless args.dry_run? unless args.dry_run? Utils::Analytics.write_api( "security", "current", Utils::Analytics::Vulnerabilities.catalogue(all_formulae, available: !advisories.nil?, revision: tap.git_head) ) 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 json_contents = { formulae:, aliases: tap.alias_table, renames: tap.formula_renames, tap_git_head: tap.git_head, tap_migrations: tap.tap_migrations, } File.write("api/internal/formula.#{bottle_tag}.json", JSON.generate(json_contents)) unless args.dry_run? end end end |