Skip to content

Commit

Permalink
Address feedback
Browse files Browse the repository at this point in the history
- Move HOMEBREW_TAP_DIRECTORY to startup/config.rb because this file
holds more of the directory constants
- Rename `Commands.cmd_directories` to `Commands.tap_cmd_directories`
to better express that the commands come from taps

This file has the directory constants while the other one has regexes.
Just better organization.
  • Loading branch information
apainintheneck committed Aug 11, 2024
1 parent a3e917a commit 1fe16a5
Show file tree
Hide file tree
Showing 8 changed files with 13 additions and 11 deletions.
2 changes: 1 addition & 1 deletion Library/Homebrew/brew.rb
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@

unless internal_cmd
# Add contributed commands to PATH before checking.
homebrew_path.append(Commands.cmd_directories)
homebrew_path.append(Commands.tap_cmd_directories)

# External commands expect a normal PATH
ENV["PATH"] = homebrew_path.to_s
Expand Down
10 changes: 5 additions & 5 deletions Library/Homebrew/commands.rb
Original file line number Diff line number Diff line change
Expand Up @@ -70,17 +70,17 @@ def self.internal_dev_cmd_path(cmd)

# Ruby commands which can be `require`d without being run.
def self.external_ruby_v2_cmd_path(cmd)
path = which("#{cmd}.rb", 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)
which("brew-#{cmd}.rb", PATH.new(ENV.fetch("PATH")).append(cmd_directories))
which("brew-#{cmd}.rb", PATH.new(ENV.fetch("PATH")).append(tap_cmd_directories))
end

def self.external_cmd_path(cmd)
which("brew-#{cmd}", PATH.new(ENV.fetch("PATH")).append(cmd_directories))
which("brew-#{cmd}", PATH.new(ENV.fetch("PATH")).append(tap_cmd_directories))
end

def self.path(cmd)
Expand All @@ -103,7 +103,7 @@ def self.commands(external: true, aliases: false)

# An array of all tap cmd directory {Pathname}s.
sig { returns(T::Array[Pathname]) }
def self.cmd_directories
def self.tap_cmd_directories
Pathname.glob HOMEBREW_TAP_DIRECTORY/"*/*/cmd"
end

Expand Down Expand Up @@ -144,7 +144,7 @@ def self.find_internal_commands(path)
end

def self.external_commands
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 }
Expand Down
2 changes: 1 addition & 1 deletion Library/Homebrew/diagnostic.rb
Original file line number Diff line number Diff line change
Expand Up @@ -764,7 +764,7 @@ def check_for_unlinked_but_not_keg_only
end

def check_for_external_cmd_name_conflict
cmds = Commands.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|
Expand Down
3 changes: 3 additions & 0 deletions Library/Homebrew/startup/config.rb
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,9 @@
tmp.realpath
end.freeze

# Where installed taps live
HOMEBREW_TAP_DIRECTORY = (HOMEBREW_LIBRARY/"Taps").freeze

Check warning on line 55 in Library/Homebrew/startup/config.rb

View check run for this annotation

Codecov / codecov/patch

Library/Homebrew/startup/config.rb#L55

Added line #L55 was not covered by tests

# The Ruby path and args to use for forked Ruby calls
HOMEBREW_RUBY_EXEC_ARGS = [
RUBY_PATH,
Expand Down
2 changes: 0 additions & 2 deletions Library/Homebrew/tap_constants.rb
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
# typed: strict
# frozen_string_literal: true

HOMEBREW_TAP_DIRECTORY = T.let((HOMEBREW_LIBRARY/"Taps").freeze, Pathname)

# Match a formula name.
HOMEBREW_TAP_FORMULA_NAME_REGEX = T.let(/(?<name>[\w+\-.@]+)/, Regexp)
# Match taps' formulae, e.g. `someuser/sometap/someformula`.
Expand Down
2 changes: 1 addition & 1 deletion Library/Homebrew/test/commands_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@

FileUtils.touch "#{dir}/brew-t4"

allow(described_class).to receive(:cmd_directories).and_return([dir])
allow(described_class).to receive(:tap_cmd_directories).and_return([dir])

cmds = described_class.external_commands

Expand Down
2 changes: 1 addition & 1 deletion Library/Homebrew/test/diagnostic_checks_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@
FileUtils.chmod 0755, cmd
end

allow(Commands).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")
Expand Down
1 change: 1 addition & 0 deletions Library/Homebrew/test/support/lib/startup/config.rb
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@
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"),
Expand Down

0 comments on commit 1fe16a5

Please sign in to comment.