From 0e33644c44653c7a0470d1be698a691057adb6e2 Mon Sep 17 00:00:00 2001 From: Douglas Eichelberger Date: Sun, 14 Jun 2026 04:47:20 -0700 Subject: [PATCH] Remove dead Formula methods and annotate public DSL Removes Formula methods with no callers in Homebrew or the official taps: specified_name, installed_specified_name, full_formulae, prefix_linked?, core_alias_files, internal_dependencies_hash and allow_network_access! (also dropped from FORMULA_COMPONENT_PRECEDENCE_LIST and the generated DSL RBI), along with their now-dead specs. Annotates the formula DSL methods that the official taps rely on but which lacked an `@api` tag as `@api public`: pypi_packages, test_fixtures, xcodebuild and deny_network_access!. --- Library/Homebrew/formula.rb | 60 +++++---------------------- Library/Homebrew/test/formula_spec.rb | 32 -------------- 2 files changed, 11 insertions(+), 81 deletions(-) diff --git a/Library/Homebrew/formula.rb b/Library/Homebrew/formula.rb index 28477df135c16..cc33bae46c50c 100644 --- a/Library/Homebrew/formula.rb +++ b/Library/Homebrew/formula.rb @@ -517,12 +517,6 @@ def full_specified_name full_alias_name || full_name end - # The name specified to install this formula. - sig { returns(String) } - def installed_specified_name - installed_alias_name || name - end - # The name (including tap) specified to install this formula. sig { returns(String) } def full_installed_specified_name @@ -748,16 +742,6 @@ def full_formulae_names formula_names_for_glob("#{sibling_name}.rb") end - # Returns sibling `-full` or non-`-full` Formula objects for any Formula. - sig { returns(T::Array[Formula]) } - def full_formulae - full_formulae_names.filter_map do |formula_name| - Formula[formula_name] - rescue FormulaUnavailableError - nil - end.sort_by(&:version).reverse - end - sig { returns(T.nilable(String)) } def link_overwrite_reason installed_overwrite_formulae = link_overwrite_formulae.select(&:any_version_installed?) @@ -1068,14 +1052,6 @@ def linked? = linked_keg.exist? sig { returns(T::Boolean) } def optlinked? = opt_prefix.symlink? - # If a formula's linked keg points to the prefix. - sig { params(version: T.any(String, PkgVersion)).returns(T::Boolean) } - def prefix_linked?(version = pkg_version) - return false unless linked? - - linked_keg.resolved_path == versioned_prefix(version) - end - # {PkgVersion} of the linked keg for the formula. sig { returns(T.nilable(PkgVersion)) } def linked_version @@ -2627,12 +2603,6 @@ def self.installed_with_alias_path(alias_path) installed.select { |f| f.installed_alias_path == alias_path } end - # An array of all alias files of core {Formula}e. - sig { returns(T::Array[Pathname]) } - def self.core_alias_files - CoreTap.instance.alias_files - end - # An array of all core aliases. sig { returns(T::Array[String]) } def self.core_aliases @@ -3247,25 +3217,6 @@ def dependencies_hash hash end - sig { params(spec_symbol: Symbol).returns(T.nilable(T::Hash[String, T.untyped])) } - def internal_dependencies_hash(spec_symbol) - raise ArgumentError, "Unsupported spec: #{spec_symbol}" unless [:stable, :head].include?(spec_symbol) - return unless (spec = public_send(spec_symbol)) - - spec.declared_deps.each_with_object({}) do |dep, dep_hash| - # Implicit dependencies are only needed when installing from source - # since they are only used to download and unpack source files. - # @see DependencyCollector - next if dep.implicit? - - metadata_hash = {} - metadata_hash[:tags] = dep.tags if dep.tags.present? - metadata_hash[:uses_from_macos] = dep.bounds.presence if dep.uses_from_macos? - - dep_hash[dep.name] = metadata_hash.presence - end - end - sig { returns(T.nilable(T::Boolean)) } def on_system_blocks_exist? self.class.on_system_blocks_exist? || @on_system_blocks_exist @@ -3333,6 +3284,9 @@ def test_defined? } def test; end + # Returns the path to a fixture file for use in formula tests. + # + # @api public sig { params(file: T.any(Pathname, String)).returns(Pathname) } def test_fixtures(file) HOMEBREW_LIBRARY_PATH/"test/support/fixtures"/file @@ -3665,6 +3619,8 @@ def mkdir(name, &block) end # Runs `xcodebuild` without Homebrew's compiler environment variables set. + # + # @api public sig { params(args: T.any(String, Integer, Pathname, Symbol)).void } def xcodebuild(*args) removed = ENV.remove_cc_etc @@ -3969,6 +3925,8 @@ def license(args = nil) # ```ruby # allow_network_access! [:build, :test] # ``` + # + # @api public sig { params(phases: T.any(Symbol, T::Array[Symbol])).void } def allow_network_access!(phases = []) phases_array = Array(phases) @@ -4001,6 +3959,8 @@ def allow_network_access!(phases = []) # ```ruby # deny_network_access! [:build, :test] # ``` + # + # @api public sig { params(phases: T.any(Symbol, T::Array[Symbol])).void } def deny_network_access!(phases = []) phases_array = Array(phases) @@ -4371,6 +4331,8 @@ def head(val = nil, specs = {}, &block) # # Special case: empty `package_name` allows to skip resource updates for non-extra packages # pypi_packages package_name: "", extra_packages: "setuptools" # ``` + # + # @api public sig { params( package_name: T.nilable(String), diff --git a/Library/Homebrew/test/formula_spec.rb b/Library/Homebrew/test/formula_spec.rb index 7663e3492aa56..55cc169dc5cf0 100644 --- a/Library/Homebrew/test/formula_spec.rb +++ b/Library/Homebrew/test/formula_spec.rb @@ -261,34 +261,6 @@ end end - describe "#full_formulae" do - let(:f) do - formula "foo" do - T.bind(self, T.class_of(Formula)) - url "foo-1.0" - end - end - - let(:f_full) do - formula "foo-full" do - T.bind(self, T.class_of(Formula)) - url "foo-full-1.0" - end - end - - before do - allow(Formulary).to receive(:load_formula_from_path).with(f_full.name, f_full.path).and_return(f_full) - allow(Formulary).to receive(:factory).with(f_full.name).and_return(f_full) - allow(f).to receive(:full_formulae_names).and_return([f_full.name]) - end - - it "returns array with sibling full formulae" do - FileUtils.touch f.path - FileUtils.touch f_full.path - expect(f.full_formulae).to eq [f_full] - end - end - describe "#unversioned_formula_name" do let(:f) do formula "foo" do @@ -565,7 +537,6 @@ expect(f.installed_alias_path).to be_nil expect(f.installed_alias_name).to be_nil expect(f.full_installed_alias_name).to be_nil - expect(f.installed_specified_name).to eq(f.name) expect(f.full_installed_specified_name).to eq(f.name) end @@ -579,7 +550,6 @@ expect(f.installed_alias_path).to eq(alias_path) expect(f.installed_alias_name).to eq(alias_name) expect(f.full_installed_alias_name).to eq(alias_name) - expect(f.installed_specified_name).to eq(alias_name) expect(f.full_installed_specified_name).to eq(alias_name) end @@ -601,7 +571,6 @@ expect(f.installed_alias_path).to be_nil expect(f.installed_alias_name).to be_nil expect(f.full_installed_alias_name).to be_nil - expect(f.installed_specified_name).to eq(f.name) expect(f.full_installed_specified_name).to eq(f.full_name) end @@ -616,7 +585,6 @@ expect(f.installed_alias_path).to eq(alias_path) expect(f.installed_alias_name).to eq(alias_name) expect(f.full_installed_alias_name).to eq(full_alias_name) - expect(f.installed_specified_name).to eq(alias_name) expect(f.full_installed_specified_name).to eq(full_alias_name) FileUtils.rm_rf HOMEBREW_LIBRARY/"Taps/user"