Macchina-CLI / libmacchina

A library providing access to all sorts of system information.
https://crates.io/crates/libmacchina
MIT License
68 stars 20 forks source link

Homebrew packages aren't correctly counted on M1 macs #71

Closed jasonappah closed 3 years ago

jasonappah commented 3 years ago

Hi there! I've been using macchina in my terminal setup for a while and it's been awesome! I noticed that macchina reports the wrong number of installed brew packages on Apple Silicon Macs. macchina displays 0, and I confirmed with brew list that I've got a lot more than that :)

It looks like libmacchina is trying to manually count installed packages in /usr/local/Cellar and /usr/local/Caskroom, but when being run with Apple Silicon CPUs, brew installs ARM packages by default to /opt/homebrew/Caskroom and /opt/homebrew/Cellar, which I'm assuming is to avoid conflicts with any potential x86 packages installed for use under Rosetta.

I think the solution to this should just be to switch the root path based on the current system architecture, but perhaps it'd be better to count packages installed for all architectures and not just the one currently being used? I'm not a huge Rust person but I'd love to help out where I can!

Output of `brew list -1 -l` (I'm just noticing the zero count here too 🤔 ) ``` ==> Formulae total 0 drwxr-xr-x 3 json admin 96 Sep 25 23:37 aom drwxr-xr-x 3 json admin 96 Sep 25 23:32 asciinema drwxr-xr-x 3 json admin 96 Sep 25 23:41 atk drwxr-xr-x 3 json admin 96 Sep 25 23:46 autoconf drwxr-xr-x 3 json admin 96 Sep 25 23:33 bat drwxr-xr-x 4 json admin 128 Sep 29 16:37 bdw-gc drwxr-xr-x 3 json admin 96 Sep 25 23:33 bit-git drwxr-xr-x 3 json admin 96 Sep 25 23:34 brotli drwxr-xr-x 3 json admin 96 Sep 25 23:34 c-ares drwxr-xr-x 3 json admin 96 Sep 25 23:33 caddy drwxr-xr-x 3 json admin 96 Sep 25 23:35 cairo drwxr-xr-x 3 json admin 96 Sep 25 23:33 checkstyle drwxr-xr-x 3 json admin 96 Sep 25 23:33 clang-format drwxr-xr-x 3 json admin 96 Sep 25 23:33 cmake drwxr-xr-x 3 json admin 96 Sep 25 23:34 curl drwxr-xr-x 3 json admin 96 Sep 25 23:37 dav1d drwxr-xr-x 3 json admin 96 Sep 25 23:34 diff-so-fancy drwxr-xr-x 3 json admin 96 Sep 25 23:43 docbook drwxr-xr-x 3 json admin 96 Sep 25 23:43 docbook-xsl drwxr-xr-x 3 json admin 96 Sep 25 23:34 doctl drwxr-xr-x 3 json admin 96 Sep 25 23:34 doxygen drwxr-xr-x 3 json admin 96 Sep 25 23:34 exa drwxr-xr-x 3 json admin 96 Sep 25 23:38 ffmpeg drwxr-xr-x 3 json admin 96 Sep 25 23:47 fgh drwxr-xr-x 3 json admin 96 Sep 25 23:38 flac drwxr-xr-x 3 json admin 96 Sep 29 10:01 flyctl drwxr-xr-x 3 json admin 96 Sep 25 23:35 fontconfig drwxr-xr-x 3 json admin 96 Sep 25 23:35 freetype drwxr-xr-x 3 json admin 96 Sep 25 23:37 frei0r drwxr-xr-x 3 json admin 96 Sep 25 23:35 fribidi drwxr-xr-x 3 json admin 96 Sep 25 23:39 fzf drwxr-xr-x 3 json admin 96 Sep 25 23:39 gcc drwxr-xr-x 3 json admin 96 Sep 25 23:41 gd drwxr-xr-x 3 json admin 96 Sep 25 23:32 gdbm drwxr-xr-x 3 json admin 96 Sep 25 23:39 gdk-pixbuf drwxr-xr-x 3 json admin 96 Sep 25 23:34 gettext drwxr-xr-x 3 json admin 96 Sep 25 23:47 getwindowid drwxr-xr-x 3 json admin 96 Sep 25 23:39 gh drwxr-xr-x 3 json admin 96 Sep 25 23:43 ghostscript drwxr-xr-x 3 json admin 96 Sep 25 23:38 giflib drwxr-xr-x 3 json admin 96 Sep 25 23:39 git drwxr-xr-x 3 json admin 96 Sep 25 23:35 glib drwxr-xr-x 3 json admin 96 Sep 25 23:40 glib-networking drwxr-xr-x 3 json admin 96 Sep 25 23:37 gmp drwxr-xr-x 3 json admin 96 Sep 25 23:43 gnu-getopt drwxr-xr-x 3 json admin 96 Sep 25 23:46 gnu-sed drwxr-xr-x 3 json admin 96 Sep 25 23:40 gnupg drwxr-xr-x 3 json admin 96 Sep 25 23:38 gnutls drwxr-xr-x 3 json admin 96 Sep 25 23:40 go drwxr-xr-x 3 json admin 96 Sep 25 23:35 gobject-introspection drwxr-xr-x 3 json admin 96 Sep 25 23:40 google-java-format drwxr-xr-x 3 json admin 96 Sep 25 23:36 graphite2 drwxr-xr-x 3 json admin 96 Sep 25 23:41 graphviz drwxr-xr-x 3 json admin 96 Sep 25 23:39 gsettings-desktop-schemas drwxr-xr-x 3 json admin 96 Sep 25 23:41 gstreamer drwxr-xr-x 3 json admin 96 Sep 25 23:42 gtk+3 drwxr-xr-x 3 json admin 96 Sep 25 23:41 gts drwxr-xr-x 3 json admin 96 Sep 25 23:37 guile drwxr-xr-x 3 json admin 96 Sep 25 23:36 harfbuzz drwxr-xr-x 3 json admin 96 Sep 25 23:47 heroku drwxr-xr-x 3 json admin 96 Sep 25 23:47 heroku-node drwxr-xr-x 3 json admin 96 Sep 25 23:41 hicolor-icon-theme drwxr-xr-x 3 json admin 96 Sep 25 23:42 htop drwxr-xr-x 3 json admin 96 Sep 25 23:36 icu4c drwxr-xr-x 3 json admin 96 Sep 25 23:43 imagemagick drwxr-xr-x 3 json admin 96 Sep 25 23:43 imath drwxr-xr-x 3 json admin 96 Sep 25 23:39 isl drwxr-xr-x 3 json admin 96 Sep 25 23:41 jasper drwxr-xr-x 3 json admin 96 Sep 25 23:43 jbig2dec drwxr-xr-x 3 json admin 96 Sep 25 23:34 jemalloc drwxr-xr-x 3 json admin 96 Sep 25 23:38 jpeg drwxr-xr-x 3 json admin 96 Sep 25 23:44 jq drwxr-xr-x 3 json admin 96 Sep 29 10:00 kubernetes-cli drwxr-xr-x 3 json admin 96 Sep 25 23:38 lame drwxr-xr-x 3 json admin 96 Sep 30 21:17 leptonica drwxr-xr-x 3 json admin 96 Sep 25 23:36 libass drwxr-xr-x 3 json admin 96 Sep 25 23:40 libassuan drwxr-xr-x 3 json admin 96 Sep 25 23:38 libbluray drwxr-xr-x 3 json admin 96 Sep 25 23:43 libde265 drwxr-xr-x 3 json admin 96 Sep 25 23:41 libepoxy drwxr-xr-x 3 json admin 96 Sep 25 23:34 libev drwxr-xr-x 3 json admin 96 Sep 25 23:38 libevent drwxr-xr-x 3 json admin 96 Sep 25 23:35 libffi drwxr-xr-x 3 json admin 96 Sep 25 23:40 libgcrypt drwxr-xr-x 3 json admin 96 Sep 25 23:40 libgpg-error drwxr-xr-x 3 json admin 96 Sep 25 23:43 libheif drwxr-xr-x 3 json admin 96 Sep 25 23:43 libidn drwxr-xr-x 3 json admin 96 Sep 25 23:34 libidn2 drwxr-xr-x 3 json admin 96 Sep 25 23:40 libksba drwxr-xr-x 3 json admin 96 Sep 25 23:43 liblqr drwxr-xr-x 3 json admin 96 Sep 25 23:39 libmpc drwxr-xr-x 3 json admin 96 Sep 25 23:41 libnice drwxr-xr-x 3 json admin 96 Sep 25 23:38 libogg drwxr-xr-x 3 json admin 96 Sep 25 23:43 libomp drwxr-xr-x 3 json admin 96 Sep 25 23:35 libpng drwxr-xr-x 3 json admin 96 Sep 25 23:42 libpsl drwxr-xr-x 3 json admin 96 Sep 25 23:35 libpthread-stubs drwxr-xr-x 3 json admin 96 Sep 25 23:41 librsvg drwxr-xr-x 3 json admin 96 Sep 25 23:38 libsamplerate drwxr-xr-x 3 json admin 96 Sep 25 23:38 libsndfile drwxr-xr-x 3 json admin 96 Sep 25 23:38 libsodium drwxr-xr-x 3 json admin 96 Sep 25 23:42 libsoup drwxr-xr-x 3 json admin 96 Sep 25 23:38 libsoxr drwxr-xr-x 3 json admin 96 Sep 25 23:34 libssh2 drwxr-xr-x 3 json admin 96 Sep 25 23:38 libtasn1 drwxr-xr-x 3 json admin 96 Sep 25 23:45 libtermkey drwxr-xr-x 3 json admin 96 Sep 25 23:38 libtiff drwxr-xr-x 3 json admin 96 Sep 25 23:37 libtool drwxr-xr-x 3 json admin 96 Sep 25 23:34 libunistring drwxr-xr-x 3 json admin 96 Sep 25 23:40 libusb drwxr-xr-x 3 json admin 96 Sep 25 23:45 libuv drwxr-xr-x 3 json admin 96 Sep 25 23:38 libvidstab drwxr-xr-x 3 json admin 96 Sep 25 23:38 libvorbis drwxr-xr-x 3 json admin 96 Sep 25 23:38 libvpx drwxr-xr-x 3 json admin 96 Sep 25 23:45 libvterm drwxr-xr-x 3 json admin 96 Sep 25 23:35 libx11 drwxr-xr-x 3 json admin 96 Sep 25 23:35 libxau drwxr-xr-x 3 json admin 96 Sep 25 23:35 libxcb drwxr-xr-x 3 json admin 96 Sep 25 23:35 libxdmcp drwxr-xr-x 3 json admin 96 Sep 25 23:35 libxext drwxr-xr-x 3 json admin 96 Sep 25 23:35 libxrender drwxr-xr-x 3 json admin 96 Sep 25 23:38 little-cms2 drwxr-xr-x 3 json admin 96 Sep 25 23:44 llvm drwxr-xr-x 3 json admin 96 Sep 25 23:44 lolcat drwxr-xr-x 3 json admin 96 Sep 25 23:45 luajit-openresty drwxr-xr-x 3 json admin 96 Sep 25 23:45 luv drwxr-xr-x 3 json admin 96 Sep 29 16:36 lynx drwxr-xr-x 3 json admin 96 Sep 25 23:35 lzo drwxr-xr-x 3 json admin 96 Sep 25 23:37 m4 drwxr-xr-x 3 json admin 96 Sep 26 00:36 macchina drwxr-xr-x 3 json admin 96 Sep 27 11:14 mas drwxr-xr-x 3 json admin 96 Sep 25 23:44 micro drwxr-xr-x 3 json admin 96 Sep 29 10:01 mitmproxy drwxr-xr-x 3 json admin 96 Sep 25 23:45 mosh drwxr-xr-x 3 json admin 96 Sep 25 23:32 mpdecimal drwxr-xr-x 3 json admin 96 Sep 25 23:39 mpfr drwxr-xr-x 3 json admin 96 Sep 25 23:45 msgpack drwxr-xr-x 3 json admin 96 Sep 25 23:42 ncurses drwxr-xr-x 3 json admin 96 Sep 25 23:45 neofetch drwxr-xr-x 3 json admin 96 Sep 27 09:50 neovim drwxr-xr-x 3 json admin 96 Sep 25 23:41 netpbm drwxr-xr-x 3 json admin 96 Sep 25 23:38 nettle drwxr-xr-x 3 json admin 96 Sep 25 23:34 nghttp2 drwxr-xr-x 3 json admin 96 Sep 25 23:46 nmap drwxr-xr-x 3 json admin 96 Sep 25 23:46 nnn drwxr-xr-x 3 json admin 96 Sep 25 23:40 npth drwxr-xr-x 3 json admin 96 Sep 25 23:44 oniguruma drwxr-xr-x 3 json admin 96 Sep 25 23:38 opencore-amr drwxr-xr-x 3 json admin 96 Sep 25 23:43 openexr drwxr-xr-x 3 json admin 96 Sep 25 23:33 openjdk drwxr-xr-x 3 json admin 96 Sep 25 23:38 openjpeg drwxr-xr-x 3 json admin 96 Sep 25 23:34 openldap drwxr-xr-x 3 json admin 96 Sep 25 23:32 openssl@1.1 drwxr-xr-x 3 json admin 96 Sep 25 23:38 opus drwxr-xr-x 3 json admin 96 Sep 25 23:38 p11-kit drwxr-xr-x 3 json admin 96 Sep 25 23:40 pango drwxr-xr-x 3 json admin 96 Sep 25 23:35 pcre drwxr-xr-x 3 json admin 96 Sep 25 23:39 pcre2 drwxr-xr-x 3 json admin 96 Sep 25 23:40 pinentry drwxr-xr-x 3 json admin 96 Sep 25 23:46 pinentry-mac drwxr-xr-x 3 json admin 96 Sep 25 23:35 pixman drwxr-xr-x 3 json admin 96 Sep 25 23:35 pkg-config drwxr-xr-x 3 json admin 96 Sep 25 23:45 protobuf drwxr-xr-x 3 json admin 96 Sep 25 23:46 pyenv drwxr-xr-x 3 json admin 96 Sep 25 23:32 python@3.8 drwxr-xr-x 3 json admin 96 Sep 25 23:32 python@3.9 drwxr-xr-x 3 json admin 96 Sep 25 23:38 rav1e drwxr-xr-x 3 json admin 96 Sep 30 21:17 readline drwxr-xr-x 3 json admin 96 Sep 25 23:34 rtmpdump drwxr-xr-x 3 json admin 96 Sep 25 23:38 rubberband drwxr-xr-x 3 json admin 96 Sep 25 23:46 scrcpy drwxr-xr-x 3 json admin 96 Sep 25 23:45 screenresolution drwxr-xr-x 3 json admin 96 Sep 25 23:38 sdl2 drwxr-xr-x 3 json admin 96 Sep 25 23:43 shared-mime-info drwxr-xr-x 3 json admin 96 Sep 25 23:45 six drwxr-xr-x 3 json admin 96 Sep 25 23:46 sl drwxr-xr-x 3 json admin 96 Sep 25 23:38 snappy drwxr-xr-x 3 json admin 96 Sep 25 23:38 speex drwxr-xr-x 3 json admin 96 Sep 25 23:32 sqlite drwxr-xr-x 3 json admin 96 Sep 25 23:38 srt drwxr-xr-x 3 json admin 96 Sep 29 10:01 ssh-copy-id drwxr-xr-x 3 json admin 96 Sep 25 23:32 tcl-tk drwxr-xr-x 3 json admin 96 Sep 25 23:38 tesseract drwxr-xr-x 3 json admin 96 Sep 25 23:38 theora drwxr-xr-x 3 json admin 96 Sep 25 23:46 tig drwxr-xr-x 3 json admin 96 Sep 25 23:45 tree-sitter drwxr-xr-x 3 json admin 96 Sep 25 23:46 tty-clock drwxr-xr-x 3 json admin 96 Sep 25 23:38 unbound drwxr-xr-x 3 json admin 96 Sep 25 23:45 unibilium drwxr-xr-x 3 json admin 96 Sep 25 23:42 vala drwxr-xr-x 3 json admin 96 Sep 29 16:37 w3m drwxr-xr-x 3 json admin 96 Sep 25 23:38 webp drwxr-xr-x 3 json admin 96 Sep 25 23:46 wget drwxr-xr-x 3 json admin 96 Sep 25 23:38 x264 drwxr-xr-x 3 json admin 96 Sep 25 23:38 x265 drwxr-xr-x 3 json admin 96 Sep 25 23:43 xmlto drwxr-xr-x 3 json admin 96 Sep 25 23:35 xorgproto drwxr-xr-x 3 json admin 96 Sep 25 23:38 xvid drwxr-xr-x 3 json admin 96 Sep 25 23:32 xz drwxr-xr-x 3 json admin 96 Sep 25 23:46 yadm drwxr-xr-x 3 json admin 96 Sep 25 23:46 youtube-dl drwxr-xr-x 3 json admin 96 Sep 25 23:38 zeromq drwxr-xr-x 3 json admin 96 Sep 25 23:38 zimg drwxr-xr-x 3 json admin 96 Sep 25 23:47 zsh drwxr-xr-x 3 json admin 96 Sep 25 23:47 zsh-syntax-highlighting drwxr-xr-x 3 json admin 96 Sep 25 23:34 zstd ==> Casks total 0 drwxr-xr-x 4 json admin 128 Sep 27 11:20 ableton-live-lite drwxr-xr-x 4 json admin 128 Sep 27 11:20 cool-retro-term drwxr-xr-x 4 json admin 128 Sep 30 17:02 docker drwxr-xr-x 4 json admin 128 Sep 30 19:51 fig drwxr-xr-x 4 json admin 128 Sep 29 00:42 figma drwxr-xr-x 4 json admin 128 Sep 25 23:48 font-jetbrains-mono drwxr-xr-x 4 json admin 128 Sep 26 00:46 font-jetbrains-mono-nerd-font drwxr-xr-x 4 json admin 128 Sep 25 23:48 google-cloud-sdk drwxr-xr-x 4 json admin 128 Sep 27 12:59 haptickey drwxr-xr-x 4 json admin 128 Sep 27 11:20 iterm2 drwxr-xr-x 4 json admin 128 Sep 29 22:34 itsycal drwxr-xr-x 4 json admin 128 Sep 27 11:20 karabiner-elements drwxr-xr-x 4 json admin 128 Sep 29 10:07 notion drwxr-xr-x 4 json admin 128 Sep 25 23:49 openscad drwxr-xr-x 4 json admin 128 Sep 29 10:09 pock drwxr-xr-x 4 json admin 128 Sep 25 23:49 raycast drwxr-xr-x 4 json admin 128 Sep 27 11:25 rectangle drwxr-xr-x 4 json admin 128 Sep 25 23:49 scrapple drwxr-xr-x 4 json admin 128 Sep 28 09:00 superhuman drwxr-xr-x 4 json admin 128 Sep 30 19:50 teamviewer drwxr-xr-x 4 json admin 128 Sep 27 11:26 visual-studio-code ```
grtcdr commented 3 years ago

Hi!

If I understand correctly, you'd like to see libmacchina count the packages in:

If on Apple Silicon the last two directories don't exist, then their count will be "0", and it'll just return the count of the first two.

EDIT: We count things in-house, so don't worry about that "0" count there. EDIT 2: Should be fixed with https://github.com/Macchina-CLI/libmacchina/commit/4067dc4d474426889eadd2a6989ca8d876df0c4f EDIT 3: See https://github.com/Macchina-CLI/libmacchina/commit/168daf164a1d472f260ea720e039b57e853a6fd3 as the previously mentioned commit was failing because of some variable naming issues.

grtcdr commented 3 years ago

It shouldn't take long for a new release to come out that features this new change, so I guess I'll close this for now.

EDIT: v1.1.7 is out but give it some time for the homebrew team to update it in their repos :)

jasonappah commented 3 years ago

Awesome - thanks for pushing a fix so quickly!

grtcdr commented 3 years ago

Of course :)

And thank you for taking the time to write us a detailed report.