Class: Homebrew::DevCmd::GenerateFormulaApi Private

Inherits:
AbstractCommand show all
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

Methods inherited from AbstractCommand

command, command_name, dev_cmd?, #initialize, parser, ruby_cmd?

Constructor Details

This class inherits a constructor from Homebrew::AbstractCommand

Instance Method Details

#argsHomebrew::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

#runvoid

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.



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
# File 'dev-cmd/generate-formula-api.rb', line 30

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

  Homebrew.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.generating_hash!

    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
        json = JSON.pretty_generate(all_formulae[name])
        html_template_name = html_template(name)

        unless args.dry_run?
          File.write("_data/formula/#{name.tr("+", "_")}.json", "#{json}\n")
          File.write("api/formula/#{name}.json", FORMULA_JSON_TEMPLATE)
          File.write("formula/#{name}.html", html_template_name)
        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?

    OnSystem::VALID_OS_ARCH_TAGS.each do |bottle_tag|
      variation_formulae = all_formulae.to_h do |name, formula|
        formula = Homebrew::API.merge_variations(formula, bottle_tag:)

        version = Version.new(formula.dig("versions", "stable"))
        pkg_version = PkgVersion.new(version, formula["revision"])
        rebuild = formula.dig("bottle", "stable", "rebuild") || 0

        bottle_collector = Utils::Bottles::Collector.new
        formula.dig("bottle", "stable", "files")&.each do |tag, data|
          tag = Utils::Bottles::Tag.from_symbol(tag)
          bottle_collector.add tag, checksum: Checksum.new(data["sha256"]), cellar: :any
        end

        sha256 = bottle_collector.specification_for(bottle_tag)&.checksum&.to_s

        [name, [pkg_version.to_s, rebuild, sha256]]
      end

      unless args.dry_run?
        File.write("api/internal/formula.#{bottle_tag}.json", JSON.generate(variation_formulae))
      end
    end
  end
end