Skip to content

Commit b190a96

Browse files
committed
Improvements to HOMEBREW_USE_INTERNAL_API
1 parent 4486245 commit b190a96

File tree

8 files changed

+39
-12
lines changed

8 files changed

+39
-12
lines changed

Library/Homebrew/attestation.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -98,7 +98,7 @@ def self.gh_executable
9898
# @api private
9999
sig { params(formulae: T::Array[Formula]).returns(T::Array[Formula]) }
100100
def self.sort_formulae_for_install(formulae)
101-
if formulae.include?(Formula["gh"])
101+
if formulae.map(&:full_name).include?("gh")
102102
[Formula["gh"]] | formulae
103103
else
104104
Homebrew::Attestation.gh_executable

Library/Homebrew/cli/named_args.rb

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -364,8 +364,7 @@ def load_formula_or_cask(name, only: nil, method: nil, warn: false)
364364
begin
365365
case method
366366
when nil, :factory
367-
Formulary.factory(name, *@override_spec,
368-
warn:, force_bottle: @force_bottle, flags: @flags, prefer_stub: true)
367+
Formulary.factory_stub(name, *@override_spec, warn:, force_bottle: @force_bottle, flags: @flags)
369368
when :resolve
370369
resolve_formula(name)
371370
when :latest_kegs

Library/Homebrew/cli/parser.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -733,7 +733,7 @@ def formulae(argv)
733733
next if arg.match?(HOMEBREW_CASK_TAP_CASK_REGEX)
734734

735735
begin
736-
Formulary.factory(arg, spec, flags: argv.select { |a| a.start_with?("--") }, prefer_stub: true)
736+
Formulary.factory_stub(arg, spec, flags: argv.select { |a| a.start_with?("--") })
737737
rescue FormulaUnavailableError, FormulaSpecificationError
738738
nil
739739
end

Library/Homebrew/extend/kernel.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -201,7 +201,7 @@ def ensure_executable!(name, formula_name = nil, reason: "", latest: false)
201201
return executable if executable.exist?
202202

203203
require "formula"
204-
Formula[formula_name].ensure_installed!(reason:, latest:).opt_bin/name
204+
Formulary.factory_stub(formula_name).ensure_installed!(reason:, latest:).opt_bin/name
205205
end
206206

207207
sig { params(size_in_bytes: T.any(Integer, Float)).returns(String) }

Library/Homebrew/extend/os/mac/pkgconf.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ def macos_sdk_mismatch
1111
return if OS::Mac.version.prerelease? || OS::Mac.version.outdated_release?
1212

1313
pkgconf = begin
14-
::Formula["pkgconf"]
14+
::Formulary.factory_stub("pkgconf")
1515
rescue FormulaUnavailableError
1616
nil
1717
end

Library/Homebrew/extend/pathname.rb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -474,8 +474,8 @@ def which_install_info
474474
@which_install_info ||=
475475
if File.executable?("/usr/bin/install-info")
476476
"/usr/bin/install-info"
477-
elsif Formula["texinfo"].any_version_installed?
478-
(Formula["texinfo"].opt_bin/"install-info").to_s
477+
elsif Formulary.factory_stub("texinfo").any_version_installed?
478+
(Formulary.factory_stub("texinfo").opt_bin/"install-info").to_s
479479
end
480480
end
481481
end

Library/Homebrew/formulary.rb

Lines changed: 29 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -546,7 +546,7 @@ def self.resolve(
546546
prefer_stub: false
547547
)
548548
if name.include?("/") || File.exist?(name)
549-
f = factory(name, *spec, force_bottle:, flags:, prefer_stub:)
549+
f = factory_stub(name, *spec, force_bottle:, flags:, prefer_stub:)
550550
if f.any_version_installed?
551551
tab = Tab.for_formula(f)
552552
resolved_spec = spec || tab.spec
@@ -1172,6 +1172,34 @@ def self.factory(
11721172
formula
11731173
end
11741174

1175+
# A shortcut for calling `factory`` with `prefer_stub: true`.
1176+
# @see .factory
1177+
# @api internal
1178+
sig {
1179+
params(
1180+
ref: T.any(Pathname, String),
1181+
spec: Symbol,
1182+
alias_path: T.nilable(T.any(Pathname, String)),
1183+
from: T.nilable(Symbol),
1184+
warn: T::Boolean,
1185+
force_bottle: T::Boolean,
1186+
flags: T::Array[String],
1187+
ignore_errors: T::Boolean,
1188+
).returns(Formula)
1189+
}
1190+
def self.factory_stub(
1191+
ref,
1192+
spec = :stable,
1193+
alias_path: nil,
1194+
from: nil,
1195+
warn: false,
1196+
force_bottle: false,
1197+
flags: [],
1198+
ignore_errors: false
1199+
)
1200+
factory(ref, spec, alias_path:, from:, warn:, force_bottle:, flags:, ignore_errors:, prefer_stub: true)
1201+
end
1202+
11751203
# Return a {Formula} instance for the given rack.
11761204
#
11771205
# @param spec when nil, will auto resolve the formula's spec.

Library/Homebrew/style.rb

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -327,20 +327,20 @@ def self.github_workflow_files
327327

328328
def self.shellcheck
329329
require "formula"
330-
shellcheck_stub = Formulary.factory("shellcheck", prefer_stub: true)
330+
shellcheck_stub = Formulary.factory_stub("shellcheck")
331331
shellcheck_stub.ensure_installed!(latest: true, reason: "shell style checks").opt_bin/"shellcheck"
332332
end
333333

334334
def self.shfmt
335335
require "formula"
336-
shfmt_stub = Formulary.factory("shfmt", prefer_stub: true)
336+
shfmt_stub = Formulary.factory_stub("shfmt")
337337
shfmt_stub.ensure_installed!(latest: true, reason: "formatting shell scripts")
338338
HOMEBREW_LIBRARY/"Homebrew/utils/shfmt.sh"
339339
end
340340

341341
def self.actionlint
342342
require "formula"
343-
actionlint_stub = Formulary.factory("actionlint", prefer_stub: true)
343+
actionlint_stub = Formulary.factory_stub("actionlint")
344344
actionlint_stub.ensure_installed!(latest: true, reason: "GitHub Actions checks").opt_bin/"actionlint"
345345
end
346346

0 commit comments

Comments
 (0)