diff --git a/Library/Homebrew/brew.rb b/Library/Homebrew/brew.rb index 114f034dd3..c852e15e32 100644 --- a/Library/Homebrew/brew.rb +++ b/Library/Homebrew/brew.rb @@ -65,10 +65,8 @@ begin internal_cmd = Commands.valid_internal_cmd?(cmd) || Commands.valid_internal_dev_cmd?(cmd) if cmd unless internal_cmd - require "tap" - # Add contributed commands to PATH before checking. - homebrew_path.append(Tap.cmd_directories) + homebrew_path.append(Commands.tap_cmd_directories) # External commands expect a normal PATH ENV["PATH"] = homebrew_path.to_s diff --git a/Library/Homebrew/cmd/tap-info.rb b/Library/Homebrew/cmd/tap-info.rb index f354084fa9..f430de8ce0 100644 --- a/Library/Homebrew/cmd/tap-info.rb +++ b/Library/Homebrew/cmd/tap-info.rb @@ -58,7 +58,7 @@ module Homebrew info += ", #{private_count} private" info += ", #{Utils.pluralize("formula", formula_count, plural: "e", include_count: true)}" info += ", #{Utils.pluralize("command", command_count, include_count: true)}" - info += ", #{Tap::TAP_DIRECTORY.dup.abv}" if Tap::TAP_DIRECTORY.directory? + info += ", #{HOMEBREW_TAP_DIRECTORY.dup.abv}" if HOMEBREW_TAP_DIRECTORY.directory? puts info else info = "" diff --git a/Library/Homebrew/commands.rb b/Library/Homebrew/commands.rb index ab4928aa00..e191990082 100644 --- a/Library/Homebrew/commands.rb +++ b/Library/Homebrew/commands.rb @@ -70,23 +70,17 @@ module Commands # Ruby commands which can be `require`d without being run. def self.external_ruby_v2_cmd_path(cmd) - require "tap" - - path = which("#{cmd}.rb", Tap.cmd_directories) + path = which("#{cmd}.rb", tap_cmd_directories) path if require?(path) end # Ruby commands which are run by being `require`d. def self.external_ruby_cmd_path(cmd) - require "tap" - - which("brew-#{cmd}.rb", PATH.new(ENV.fetch("PATH")).append(Tap.cmd_directories)) + which("brew-#{cmd}.rb", PATH.new(ENV.fetch("PATH")).append(tap_cmd_directories)) end def self.external_cmd_path(cmd) - require "tap" - - which("brew-#{cmd}", PATH.new(ENV.fetch("PATH")).append(Tap.cmd_directories)) + which("brew-#{cmd}", PATH.new(ENV.fetch("PATH")).append(tap_cmd_directories)) end def self.path(cmd) @@ -107,6 +101,12 @@ module Commands cmds.sort end + # An array of all tap cmd directory {Pathname}s. + sig { returns(T::Array[Pathname]) } + def self.tap_cmd_directories + Pathname.glob HOMEBREW_TAP_DIRECTORY/"*/*/cmd" + end + def self.internal_commands_paths find_commands HOMEBREW_CMD_PATH end @@ -144,9 +144,7 @@ module Commands end def self.external_commands - require "tap" - - Tap.cmd_directories.flat_map do |path| + tap_cmd_directories.flat_map do |path| find_commands(path).select(&:executable?) .map { basename_without_extension(_1) } .map { |p| p.to_s.delete_prefix("brew-").strip } diff --git a/Library/Homebrew/diagnostic.rb b/Library/Homebrew/diagnostic.rb index dfb04481d7..e67008744c 100644 --- a/Library/Homebrew/diagnostic.rb +++ b/Library/Homebrew/diagnostic.rb @@ -764,7 +764,7 @@ module Homebrew end def check_for_external_cmd_name_conflict - cmds = Tap.cmd_directories.flat_map { |p| Dir["#{p}/brew-*"] }.uniq + cmds = Commands.tap_cmd_directories.flat_map { |p| Dir["#{p}/brew-*"] }.uniq cmds = cmds.select { |cmd| File.file?(cmd) && File.executable?(cmd) } cmd_map = {} cmds.each do |cmd| diff --git a/Library/Homebrew/startup/config.rb b/Library/Homebrew/startup/config.rb index 1a9f80f7b3..7ef65a1eaa 100644 --- a/Library/Homebrew/startup/config.rb +++ b/Library/Homebrew/startup/config.rb @@ -51,6 +51,9 @@ HOMEBREW_TEMP = Pathname(ENV.fetch("HOMEBREW_TEMP")).then do |tmp| tmp.realpath end.freeze +# Where installed taps live +HOMEBREW_TAP_DIRECTORY = (HOMEBREW_LIBRARY/"Taps").freeze + # The Ruby path and args to use for forked Ruby calls HOMEBREW_RUBY_EXEC_ARGS = [ RUBY_PATH, diff --git a/Library/Homebrew/tap.rb b/Library/Homebrew/tap.rb index 97e58ceb99..22871a83ad 100644 --- a/Library/Homebrew/tap.rb +++ b/Library/Homebrew/tap.rb @@ -14,8 +14,6 @@ require "settings" class Tap extend Cachable - TAP_DIRECTORY = (HOMEBREW_LIBRARY/"Taps").freeze - HOMEBREW_TAP_CASK_RENAMES_FILE = "cask_renames.json" private_constant :HOMEBREW_TAP_CASK_RENAMES_FILE HOMEBREW_TAP_FORMULA_RENAMES_FILE = "formula_renames.json" @@ -201,7 +199,7 @@ class Tap @repository = repository @name = "#{@user}/#{@repository}".downcase @full_name = "#{@user}/homebrew-#{@repository}" - @path = TAP_DIRECTORY/@full_name.downcase + @path = HOMEBREW_TAP_DIRECTORY/@full_name.downcase @git_repository = GitRepository.new(@path) end @@ -286,7 +284,7 @@ class Tap sig { returns(String) } def repository_var_suffix @repository_var_suffix ||= path.to_s - .delete_prefix(TAP_DIRECTORY.to_s) + .delete_prefix(HOMEBREW_TAP_DIRECTORY.to_s) .tr("^A-Za-z0-9", "_") .upcase end @@ -1021,8 +1019,8 @@ class Tap # @api public sig { returns(T::Array[Tap]) } def self.installed - cache[:installed] ||= if TAP_DIRECTORY.directory? - TAP_DIRECTORY.subdirs.flat_map(&:subdirs).map { from_path(_1) } + cache[:installed] ||= if HOMEBREW_TAP_DIRECTORY.directory? + HOMEBREW_TAP_DIRECTORY.subdirs.flat_map(&:subdirs).map { from_path(_1) } else [] end @@ -1060,12 +1058,6 @@ class Tap map(&:name).sort end - # An array of all tap cmd directory {Pathname}s. - sig { returns(T::Array[Pathname]) } - def self.cmd_directories - Pathname.glob TAP_DIRECTORY/"*/*/cmd" - end - # An array of official taps that have been manually untapped sig { returns(T::Array[String]) } def self.untapped_official_taps diff --git a/Library/Homebrew/test/api/internal_tap_json/formula_spec.rb b/Library/Homebrew/test/api/internal_tap_json/formula_spec.rb index 0b6f3c04fd..6e79402e99 100644 --- a/Library/Homebrew/test/api/internal_tap_json/formula_spec.rb +++ b/Library/Homebrew/test/api/internal_tap_json/formula_spec.rb @@ -8,10 +8,10 @@ RSpec.describe "Internal Tap JSON -- Formula", type: :system do context "when generating JSON", :needs_macos do before do - cp_r(TEST_FIXTURE_DIR/"internal_tap_json/homebrew-core", Tap::TAP_DIRECTORY/"homebrew") + cp_r(TEST_FIXTURE_DIR/"internal_tap_json/homebrew-core", HOMEBREW_TAP_DIRECTORY/"homebrew") # NOTE: Symlinks can't be copied recursively so we create them manually here. - (Tap::TAP_DIRECTORY/"homebrew/homebrew-core").tap do |core_tap| + (HOMEBREW_TAP_DIRECTORY/"homebrew/homebrew-core").tap do |core_tap| mkdir(core_tap/"Aliases") ln_s(core_tap/"Formula/f/fennel.rb", core_tap/"Aliases/fennel-lang") ln_s(core_tap/"Formula/p/ponyc.rb", core_tap/"Aliases/ponyc-lang") diff --git a/Library/Homebrew/test/commands_spec.rb b/Library/Homebrew/test/commands_spec.rb index cb1a50306e..32c2293e5b 100644 --- a/Library/Homebrew/test/commands_spec.rb +++ b/Library/Homebrew/test/commands_spec.rb @@ -53,7 +53,7 @@ RSpec.describe Commands do FileUtils.touch "#{dir}/brew-t4" - allow(Tap).to receive(:cmd_directories).and_return([dir]) + allow(described_class).to receive(:tap_cmd_directories).and_return([dir]) cmds = described_class.external_commands diff --git a/Library/Homebrew/test/dev-cmd/extract_spec.rb b/Library/Homebrew/test/dev-cmd/extract_spec.rb index f6e6104255..3a7ad97ff4 100644 --- a/Library/Homebrew/test/dev-cmd/extract_spec.rb +++ b/Library/Homebrew/test/dev-cmd/extract_spec.rb @@ -8,7 +8,7 @@ RSpec.describe Homebrew::DevCmd::Extract do context "when extracting a formula" do let!(:target) do - path = Tap::TAP_DIRECTORY/"homebrew/homebrew-foo" + path = HOMEBREW_TAP_DIRECTORY/"homebrew/homebrew-foo" (path/"Formula").mkpath target = Tap.from_path(path) core_tap = CoreTap.instance diff --git a/Library/Homebrew/test/dev-cmd/pr-pull_spec.rb b/Library/Homebrew/test/dev-cmd/pr-pull_spec.rb index 777d4c25b5..a79ed7eb36 100644 --- a/Library/Homebrew/test/dev-cmd/pr-pull_spec.rb +++ b/Library/Homebrew/test/dev-cmd/pr-pull_spec.rb @@ -80,7 +80,7 @@ RSpec.describe Homebrew::DevCmd::PrPull do let(:tap) { Tap.fetch("Homebrew", "foo") } let(:formula_file) { tap.path/"Formula/foo.rb" } let(:cask_file) { tap.cask_dir/"food.rb" } - let(:path) { Pathname(Tap::TAP_DIRECTORY/"homebrew/homebrew-foo") } + let(:path) { Pathname(HOMEBREW_TAP_DIRECTORY/"homebrew/homebrew-foo") } it_behaves_like "parseable arguments" diff --git a/Library/Homebrew/test/diagnostic_checks_spec.rb b/Library/Homebrew/test/diagnostic_checks_spec.rb index 9328198d51..f5fc3b0dc7 100644 --- a/Library/Homebrew/test/diagnostic_checks_spec.rb +++ b/Library/Homebrew/test/diagnostic_checks_spec.rb @@ -101,7 +101,7 @@ RSpec.describe Homebrew::Diagnostic::Checks do FileUtils.chmod 0755, cmd end - allow(Tap).to receive(:cmd_directories).and_return([path1, path2]) + allow(Commands).to receive(:tap_cmd_directories).and_return([path1, path2]) expect(checks.check_for_external_cmd_name_conflict) .to match("brew-foo") diff --git a/Library/Homebrew/test/formula_auditor_spec.rb b/Library/Homebrew/test/formula_auditor_spec.rb index b32615cbf4..e63d5c1e91 100644 --- a/Library/Homebrew/test/formula_auditor_spec.rb +++ b/Library/Homebrew/test/formula_auditor_spec.rb @@ -11,9 +11,9 @@ RSpec.describe Homebrew::FormulaAuditor do @count += 1 end let(:formula_subpath) { "Formula/foo#{foo_version}.rb" } - let(:origin_tap_path) { Tap::TAP_DIRECTORY/"homebrew/homebrew-foo" } + let(:origin_tap_path) { HOMEBREW_TAP_DIRECTORY/"homebrew/homebrew-foo" } let(:origin_formula_path) { origin_tap_path/formula_subpath } - let(:tap_path) { Tap::TAP_DIRECTORY/"homebrew/homebrew-bar" } + let(:tap_path) { HOMEBREW_TAP_DIRECTORY/"homebrew/homebrew-bar" } let(:formula_path) { tap_path/formula_subpath } def formula_auditor(name, text, options = {}) diff --git a/Library/Homebrew/test/formulary_spec.rb b/Library/Homebrew/test/formulary_spec.rb index 30021b08f2..3e344cad5c 100644 --- a/Library/Homebrew/test/formulary_spec.rb +++ b/Library/Homebrew/test/formulary_spec.rb @@ -751,7 +751,7 @@ RSpec.describe Formulary do end after do - FileUtils.rm_rf Tap::TAP_DIRECTORY/"another" + FileUtils.rm_rf HOMEBREW_TAP_DIRECTORY/"another" end # FIXME diff --git a/Library/Homebrew/test/missing_formula_spec.rb b/Library/Homebrew/test/missing_formula_spec.rb index b85a608ce3..d737379fbb 100644 --- a/Library/Homebrew/test/missing_formula_spec.rb +++ b/Library/Homebrew/test/missing_formula_spec.rb @@ -34,7 +34,7 @@ RSpec.describe Homebrew::MissingFormula do subject { described_class.tap_migration_reason(formula) } before do - tap_path = Tap::TAP_DIRECTORY/"homebrew/homebrew-foo" + tap_path = HOMEBREW_TAP_DIRECTORY/"homebrew/homebrew-foo" tap_path.mkpath (tap_path/"tap_migrations.json").write <<~JSON { "migrated-formula": "homebrew/bar" } @@ -58,7 +58,7 @@ RSpec.describe Homebrew::MissingFormula do subject { described_class.deleted_reason(formula, silent: true) } before do - tap_path = Tap::TAP_DIRECTORY/"homebrew/homebrew-foo" + tap_path = HOMEBREW_TAP_DIRECTORY/"homebrew/homebrew-foo" (tap_path/"Formula").mkpath (tap_path/"Formula/deleted-formula.rb").write "placeholder" ENV.delete "GIT_AUTHOR_DATE" diff --git a/Library/Homebrew/test/rubocops/text/make_check_spec.rb b/Library/Homebrew/test/rubocops/text/make_check_spec.rb index 538787b085..274f457600 100644 --- a/Library/Homebrew/test/rubocops/text/make_check_spec.rb +++ b/Library/Homebrew/test/rubocops/text/make_check_spec.rb @@ -5,7 +5,7 @@ require "rubocops/lines" RSpec.describe RuboCop::Cop::FormulaAuditStrict::MakeCheck do subject(:cop) { described_class.new } - let(:path) { Tap::TAP_DIRECTORY/"homebrew/homebrew-core" } + let(:path) { HOMEBREW_TAP_DIRECTORY/"homebrew/homebrew-core" } before do path.mkpath diff --git a/Library/Homebrew/test/support/helper/spec/shared_context/integration_test.rb b/Library/Homebrew/test/support/helper/spec/shared_context/integration_test.rb index 0132ceebb7..21d23905f8 100644 --- a/Library/Homebrew/test/support/helper/spec/shared_context/integration_test.rb +++ b/Library/Homebrew/test/support/helper/spec/shared_context/integration_test.rb @@ -210,7 +210,7 @@ RSpec.shared_context "integration test" do # rubocop:disable RSpec/ContextWordin end def setup_test_tap - path = Tap::TAP_DIRECTORY/"homebrew/homebrew-foo" + path = HOMEBREW_TAP_DIRECTORY/"homebrew/homebrew-foo" path.mkpath path.cd do system "git", "init" diff --git a/Library/Homebrew/test/support/lib/startup/config.rb b/Library/Homebrew/test/support/lib/startup/config.rb index 408aea45c9..8bbba31ea3 100644 --- a/Library/Homebrew/test/support/lib/startup/config.rb +++ b/Library/Homebrew/test/support/lib/startup/config.rb @@ -33,6 +33,7 @@ HOMEBREW_LOCKS = (HOMEBREW_PREFIX.parent/"locks").freeze HOMEBREW_CELLAR = (HOMEBREW_PREFIX.parent/"cellar").freeze HOMEBREW_LOGS = (HOMEBREW_PREFIX.parent/"logs").freeze HOMEBREW_TEMP = (HOMEBREW_PREFIX.parent/"temp").freeze +HOMEBREW_TAP_DIRECTORY = (HOMEBREW_LIBRARY/"Taps").freeze HOMEBREW_RUBY_EXEC_ARGS = [ RUBY_PATH, ENV.fetch("HOMEBREW_RUBY_WARNINGS"), diff --git a/Library/Homebrew/test/tap_spec.rb b/Library/Homebrew/test/tap_spec.rb index 2f85fe9372..25932e6eb7 100644 --- a/Library/Homebrew/test/tap_spec.rb +++ b/Library/Homebrew/test/tap_spec.rb @@ -8,7 +8,7 @@ RSpec.describe Tap do subject(:homebrew_foo_tap) { described_class.fetch("Homebrew", "foo") } - let(:path) { Tap::TAP_DIRECTORY/"homebrew/homebrew-foo" } + let(:path) { HOMEBREW_TAP_DIRECTORY/"homebrew/homebrew-foo" } let(:formula_file) { path/"Formula/foo.rb" } let(:alias_file) { path/"Aliases/bar" } let(:cmd_file) { path/"cmd/brew-tap-cmd.rb" } @@ -172,7 +172,7 @@ RSpec.describe Tap do specify "#issues_url" do t = described_class.fetch("someone", "foo") - path = Tap::TAP_DIRECTORY/"someone/homebrew-foo" + path = HOMEBREW_TAP_DIRECTORY/"someone/homebrew-foo" path.mkpath cd path do system "git", "init" @@ -182,7 +182,7 @@ RSpec.describe Tap do expect(t.issues_url).to eq("https://github.com/someone/homebrew-foo/issues") expect(homebrew_foo_tap.issues_url).to eq("https://github.com/Homebrew/homebrew-foo/issues") - (Tap::TAP_DIRECTORY/"someone/homebrew-no-git").mkpath + (HOMEBREW_TAP_DIRECTORY/"someone/homebrew-no-git").mkpath expect(described_class.fetch("someone", "no-git").issues_url).to be_nil ensure path.parent.rmtree @@ -378,7 +378,7 @@ RSpec.describe Tap do end.to raise_error(ErrorDuringExecution) expect(tap).not_to be_installed - expect(Tap::TAP_DIRECTORY/"user").not_to exist + expect(HOMEBREW_TAP_DIRECTORY/"user").not_to exist end end @@ -652,7 +652,7 @@ RSpec.describe Tap do end specify "files" do - path = Tap::TAP_DIRECTORY/"homebrew/homebrew-core" + path = HOMEBREW_TAP_DIRECTORY/"homebrew/homebrew-core" formula_file = core_tap.formula_dir/"foo.rb" core_tap.formula_dir.mkpath formula_file.write <<~RUBY