diff options
| author | Mike McQuaid | 2017-11-03 17:45:57 +0000 |
|---|---|---|
| committer | GitHub | 2017-11-03 17:45:57 +0000 |
| commit | c6f40d58642149b0ccbe1282554c6b05a744a3dc (patch) | |
| tree | b17185c555804a773eb350fe0fd59f133502a724 /Library | |
| parent | 4eeac6f884a72bd16ddbab03db22f293e18f02bc (diff) | |
| parent | 29f81812ccf78c85ddac931dcfea9bfc88af82db (diff) | |
| download | brew-c6f40d58642149b0ccbe1282554c6b05a744a3dc.tar.bz2 | |
Merge pull request #3385 from MikeMcQuaid/path-fixes-cleanup
Fix and cleanup some PATH usage.
Diffstat (limited to 'Library')
| -rw-r--r-- | Library/Homebrew/brew.rb | 15 | ||||
| -rw-r--r-- | Library/Homebrew/requirement.rb | 9 | ||||
| -rw-r--r-- | Library/Homebrew/test/requirement_spec.rb | 2 |
3 files changed, 16 insertions, 10 deletions
diff --git a/Library/Homebrew/brew.rb b/Library/Homebrew/brew.rb index 2cc339a83..e21e0bbd4 100644 --- a/Library/Homebrew/brew.rb +++ b/Library/Homebrew/brew.rb @@ -50,11 +50,6 @@ begin 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") @@ -93,8 +88,14 @@ begin 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 diff --git a/Library/Homebrew/requirement.rb b/Library/Homebrew/requirement.rb index a69c68466..95807d5ae 100644 --- a/Library/Homebrew/requirement.rb +++ b/Library/Homebrew/requirement.rb @@ -77,7 +77,11 @@ class Requirement 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. @@ -94,8 +98,9 @@ class Requirement # 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 diff --git a/Library/Homebrew/test/requirement_spec.rb b/Library/Homebrew/test/requirement_spec.rb index 11a3da8f4..2d0d86c86 100644 --- a/Library/Homebrew/test/requirement_spec.rb +++ b/Library/Homebrew/test/requirement_spec.rb @@ -138,7 +138,7 @@ describe Requirement do 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 |
