WARNING: THIS SITE IS A MIRROR OF GITHUB.COM / IT CANNOT LOGIN OR REGISTER ACCOUNTS / THE CONTENTS ARE PROVIDED AS-IS / THIS SITE ASSUMES NO RESPONSIBILITY FOR ANY DISPLAYED CONTENT OR LINKS / IF YOU FOUND SOMETHING MAY NOT GOOD FOR EVERYONE, CONTACT ADMIN AT ilovescratch@foxmail.com
Skip to content

Commit d672f8a

Browse files
committed
Use formula structs in formulary
1 parent 77ee983 commit d672f8a

File tree

2 files changed

+9
-8
lines changed

2 files changed

+9
-8
lines changed

Library/Homebrew/api/formula_hash.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -150,7 +150,7 @@ class FormulaHash < T::Struct
150150
end
151151

152152
sig { params(hash: T::Hash[String, T.untyped], bottle_tag: ::Utils::Bottles::Tag).returns(FormulaHash) }
153-
def self.from_hash(hash, bottle_tag:)
153+
def self.from_hash(hash, bottle_tag: ::Utils::Bottles.tag)
154154
hash = Homebrew::API.merge_variations(hash, bottle_tag: bottle_tag)
155155

156156
hash["bottle"] = begin

Library/Homebrew/formulary.rb

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -216,9 +216,9 @@ def self.load_formula_from_path(name, path, flags:, ignore_errors:)
216216
platform_cache.fetch(:path)[path.to_s] = klass
217217
end
218218

219-
sig { params(name: String, json_formula_with_variations: T::Hash[String, T.untyped], flags: T::Array[String]).returns(T.class_of(Formula)) }
220-
def self.load_formula_from_json!(name, json_formula_with_variations, flags:)
221-
namespace = :"FormulaNamespaceAPI#{namespace_key(json_formula_with_variations.to_json)}"
219+
sig { params(name: String, formula_struct: Homebrew::API::FormulaHash, flags: T::Array[String]).returns(T.class_of(Formula)) }
220+
def self.load_formula_from_formula_struct!(name, formula_struct, flags:)
221+
namespace = :"FormulaNamespaceAPI#{namespace_key(formula_struct.to_json)}"
222222

223223
mod = Module.new
224224
remove_const(namespace) if const_defined?(namespace)
@@ -227,9 +227,8 @@ def self.load_formula_from_json!(name, json_formula_with_variations, flags:)
227227
mod.const_set(:BUILD_FLAGS, flags)
228228

229229
class_name = class_s(name)
230-
json_formula = Homebrew::API.merge_variations(json_formula_with_variations)
231230

232-
caveats_string = (replace_placeholders(json_formula["caveats"]) if json_formula["caveats"])
231+
caveats_string = (replace_placeholders(formula_struct.caveats) if formula_struct.caveats)
233232

234233
uses_from_macos_names = json_formula.fetch("uses_from_macos", []).map do |dep|
235234
next dep unless dep.is_a? Hash
@@ -1079,7 +1078,8 @@ def load_from_api(flags:)
10791078

10801079
raise FormulaUnavailableError, name if json_formula.nil?
10811080

1082-
Formulary.load_formula_from_json!(name, json_formula, flags:)
1081+
formula_struct = Homebrew::API::FormulaHash.from_hash(json_formula)
1082+
Formulary.load_formula_from_formula_struct!(name, formula_struct, flags:)
10831083
end
10841084
end
10851085

@@ -1095,7 +1095,8 @@ def initialize(name, contents, tap: nil, alias_name: nil)
10951095

10961096
sig { override.params(flags: T::Array[String]).void }
10971097
def load_from_api(flags:)
1098-
Formulary.load_formula_from_json!(name, @contents, flags:)
1098+
formula_struct = Homebrew::API::FormulaHash.from_hash(@contents)
1099+
Formulary.load_formula_from_formula_struct!(name, formula_struct, flags:)
10991100
end
11001101
end
11011102

0 commit comments

Comments
 (0)