Skip to content

Commit

Permalink
Merge pull request #3385 from MikeMcQuaid/path-fixes-cleanup
Browse files Browse the repository at this point in the history
Fix and cleanup some PATH usage.
  • Loading branch information
MikeMcQuaid committed Nov 3, 2017
2 parents 4eeac6f + 29f8181 commit c6f40d5
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 10 deletions.
15 changes: 8 additions & 7 deletions Library/Homebrew/brew.rb
Original file line number Diff line number Diff line change
Expand Up @@ -50,11 +50,6 @@
path = PATH.new(ENV["PATH"])
homebrew_path = PATH.new(ENV["HOMEBREW_PATH"])

# Add contributed commands to PATH before checking.
tap_cmds = Pathname.glob(Tap::TAP_DIRECTORY/"*/*/cmd")
path.append(tap_cmds)
homebrew_path.append(tap_cmds)

# Add SCM wrappers.
path.append(HOMEBREW_SHIMS_PATH/"scm")
homebrew_path.append(HOMEBREW_SHIMS_PATH/"scm")
Expand Down Expand Up @@ -93,8 +88,14 @@
system(HOMEBREW_BREW_FILE, "uninstall", "--force", "brew-cask")
end

# External commands expect a normal PATH
ENV["PATH"] = homebrew_path unless internal_cmd
unless internal_cmd
# Add contributed commands to PATH before checking.
tap_cmds = Pathname.glob(Tap::TAP_DIRECTORY/"*/*/cmd")
homebrew_path.append(tap_cmds)

# External commands expect a normal PATH
ENV["PATH"] = homebrew_path
end

if internal_cmd
Homebrew.send cmd.to_s.tr("-", "_").downcase
Expand Down
9 changes: 7 additions & 2 deletions Library/Homebrew/requirement.rb
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,11 @@ def default_formula?

def satisfied_result_parent
return unless @satisfied_result.is_a?(Pathname)
@satisfied_result.resolved_path.parent
parent = @satisfied_result.resolved_path.parent
if parent.to_s =~ %r{^#{Regexp.escape(HOMEBREW_CELLAR)}/([\w+-.@]+)/[^/]+/(s?bin)/?$}
parent = HOMEBREW_PREFIX/"opt/#{Regexp.last_match(1)}/#{Regexp.last_match(2)}"
end
parent
end

# Overriding #modify_build_environment is deprecated.
Expand All @@ -94,8 +98,9 @@ def modify_build_environment
# PATH.
parent = satisfied_result_parent
return unless parent
return if ["#{HOMEBREW_PREFIX}/bin", "#{HOMEBREW_PREFIX}/bin"].include?(parent.to_s)
return if PATH.new(ENV["PATH"]).include?(parent.to_s)
ENV.append_path("PATH", parent)
ENV.prepend_path("PATH", parent)
end

def env
Expand Down
2 changes: 1 addition & 1 deletion Library/Homebrew/test/requirement_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,7 @@
end

it "infers path from #satisfy result" do
expect(ENV).to receive(:append_path).with("PATH", Pathname.new("/foo/bar"))
expect(ENV).to receive(:prepend_path).with("PATH", Pathname.new("/foo/bar"))
subject.satisfied?
subject.modify_build_environment
end
Expand Down

0 comments on commit c6f40d5

Please sign in to comment.