rhysd/hgrep

Homebrew not working

anhdle14 opened this issue · 15 comments

❯ brew tap "rhysd/hgrep" "https://github.com/rhysd/hgrep"
brew install hgrep
==> Downloading https://github.com/rhysd/hgrep/releases/download/v0.2.1/hgrep-v0.2.1-x86_64-apple-darwin.zip
Already downloaded: /Users/$USER/Library/Caches/Homebrew/downloads/712103ea480f4147dde712234225835a35bc2a2213180120913b81329051bd47--hgrep-v0.2.1-x86_64-apple-darwin.zip
==> Installing hgrep from rhysd/hgrep
Error: Failure while executing; `/Users/$USER/homebrew/Cellar/hgrep/0.2.1/bin/hgrep --generate-completion-script zsh` was terminated by uncaught signal ABRT. Here's the output:
❯ /Users/$USER/homebrew/Cellar/hgrep/0.2.1/bin/hgrep --generate-completion-script zsh
zsh: no such file or directory: /Users/$USER/homebrew/Cellar/hgrep/0.2.1/bin/hgrep

Don't think it is related to OS, but if you need I will share.

rhysd commented

Thank you for reporting this. I'll take a look.

rhysd commented

I guess this is related to where Homebrew is installed. I tried brew install hgrep now and it finished successfully. I installed Hombrew in system global (/usr/local/Cella) but you installed it in user local. It may cause this issue.

rhysd commented

I added workaround for this at 04a2c4c. Would you try brew up && brew install hgrep again?

❯ brew up && brew install hgrep
Updated 2 taps (rhysd/hgrep and homebrew/core).
==> Updated Formulae
git ✔                                                     git-credential-libsecret                                  git-gui                                                   git-svn                                                   halide
...
You have 20 outdated formulae and 2 outdated casks installed.
You can upgrade them with brew upgrade
or list them with brew outdated.
==> Downloading https://github.com/rhysd/hgrep/releases/download/v0.2.1/hgrep-v0.2.1-x86_64-apple-darwin.zip
Already downloaded: /Users/anhdle14/Library/Caches/Homebrew/downloads/712103ea480f4147dde712234225835a35bc2a2213180120913b81329051bd47--hgrep-v0.2.1-x86_64-apple-darwin.zip
==> Installing hgrep from rhysd/hgrep
Error: Failure while executing; `/Users/anhdle14/homebrew/Cellar/hgrep/0.2.1/bin/hgrep --generate-completion-script zsh` was terminated by uncaught signal ABRT. Here's the output:
❯ /Users/anhdle14/homebrew/Cellar/hgrep/0.2.1/bin/hgrep --generate-completion-script zsh
zsh: no such file or directory: /Users/anhdle14/homebrew/Cellar/hgrep/0.2.1/bin/hgrep                                                                                                                                                                                                                                                                        

Still same issue I afraid

rhysd commented

Would you check /Users/anhdle14/homebrew/Homebrew/Library/Taps/rhysd/homebrew-hgrep/HomebrewFormula/hgrep.rb is the same as https://github.com/rhysd/hgrep/blob/main/HomebrewFormula/hgrep.rb ?

rhysd commented

It's weird that (bin/'hgrep').exist? returns true but running the binary through zsh says 'no such file or directory'.

@rhysd Yes it is the same (checked with diff). Let's me try to find hgrep in homebrew directory to see where it is installed.


EDIT 1:

❯ find . -name hgrep*
./var/homebrew/locks/hgrep.formula.lock
./Library/Taps/rhysd/homebrew-hgrep/HomebrewFormula/hgrep.rb
❯ find /usr/local/bin -name hgrep*
# return nothing
❯ find /usr/bin -name hgrep*
# return nothing

EDIT 2:

This work:

  def install
    bin.install 'hgrep'
    # hgrep = bin/'hgrep'
    # Check if hgrep exists to avoid #6
    # if hgrep.exist?
      # output = Utils.safe_popen_read(hgrep, '--generate-completion-script', 'zsh')
      # (zsh_completion/'_hgrep').write output
      # output = Utils.safe_popen_read(hgrep, '--generate-completion-script', 'bash')
      # (bash_completion/'hgrep').write output
      # output = Utils.safe_popen_read(hgrep, '--generate-completion-script', 'fish')
      # (fish_completion/'hgrep.fish').write output
    # end
  end
rhysd commented

Thank you for checking that.

It means that

hgrep = bin/'hgrep'
hgrep.exist?

returns true but

Utils.safe_popen_read(hgrep, '--generate-completion-script', 'zsh')

raises an exception with error zsh: no such file or directory.

Can you add debug print as follows and tell me what is output?

 def install
   bin.install 'hgrep'
   hgrep = bin/'hgrep'
+  pp hgrep
   # ...
 end
rhysd commented

I added the check that hgrep is executable or not at 2b33c38. It might help to avoid this issue.

❯ hgrep
dyld[29369]: Library not loaded: /usr/local/opt/pcre2/lib/libpcre2-8.0.dylib
  Referenced from: /Users/anhdle14/homebrew/Cellar/hgrep/0.2.1/bin/hgrep
  Reason: tried: '/usr/local/opt/pcre2/lib/libpcre2-8.0.dylib' (no such file), '/usr/local/lib/libpcre2-8.0.dylib' (no such file), '/usr/lib/libpcre2-8.0.dylib' (no such file)

Also hgrep is pointing to a fixed location of libpcre2. Fix this temporarily to make sure it is working with ln -s ~/homebrew/opt/pcre2/lib/libpcre2-8.0.dylib /usr/local/opt/pcre2/lib/libpcre2-8.0.dylib. Maybe should be another issue for tracking.

P.S: symlink worked.

And I think the hgrep bin doesn't work at all for me without libpcre. If libpcre is available then the homebrew should work fine.

rhysd commented

I see. Yes, it's another issue. Since the binary was built in macOS worker on GitHub Actions and Homebrew is installed system-global there.

In your case, installing hgrep via cargo would be easier if you have installed Rust toolchain. It installs softwares by building from sources so it should not cause this kind of issues.

cargo install hgrep

@rhysd yeah we can close this issue now. I already installed via cargo after the issue, but it is good to create an issue to find the problem with Homebrew installation.

Anyway thank you for the tool and the support!

rhysd commented

Thank you for letting me know. I didn't notice this because I didn't install Homebrew in user-local. I'll check this when I have time.

rhysd commented

I changed to link pcre2 statically on building release binaries. The dynamic link issue should be solved at the next release.

Thank you for letting me know. I didn't notice this because I didn't install Homebrew in user-local. I'll check this when I have time.

https://github.com/drduh/macOS-Security-and-Privacy-Guide

I did at first, but then I came upon this awesome repo explaining why I should not. Feel free to follow if you have time.