17

Is there a way to check what flags were given when a package was installed with homebrew?

For example, the emacs formula has an absurd number of flags. If I did

brew install emacs --with-glib --with-librsvg

I would like to later determine that for the homebrew installation of emacs I gave the flags --with-glib --with-librsvg and not any other flags.

Test case with lua package:

Before installing the package, info shows all options.

$ brew info lua
lua: stable 5.2.3 (bottled)
http://www.lua.org/
Not installed
From: https://github.com/Homebrew/homebrew/blob/master/Library/Formula/lua.rb
==> Options
--universal
    Build a universal binary
--with-completion
    Enables advanced readline support
--without-sigaction
    Revert to ANSI signal instead of improved POSIX sigaction

I install the package with just the --with-completion flag.

$ brew install lua --with-completion
==> Downloading http://www.lua.org/ftp/lua-5.2.3.tar.gz
######################################################################## 100.0%
==> Downloading http://luajit.org/patches/lua-5.2.0-advanced_readline.patch
######################################################################## 100.0%
==> Downloading http://lua-users.org/files/wiki_insecure/power_patches/5.2/lua-5
######################################################################## 100.0%
==> Patching
patching file Makefile
patching file src/Makefile
patching file src/lua.c
Hunk #1 succeeded at 231 (offset -5 lines).
Hunk #2 succeeded at 559 (offset -4 lines).
Hunk #3 succeeded at 575 (offset -4 lines).
patching file src/lua.c
==> make macosx INSTALL_TOP=/usr/local/Cellar/lua/5.2.3_1 INSTALL_MAN=/usr/local
==> make install INSTALL_TOP=/usr/local/Cellar/lua/5.2.3_1 INSTALL_MAN=/usr/loca
🍺  /usr/local/Cellar/lua/5.2.3_1: 13 files, 312K, built in 6 seconds

After installing the package, info shows all options, including those I did not use. The command does acknowledge that the package was built from source and not poured from a bottle.

$ brew info lua
lua: stable 5.2.3 (bottled)
http://www.lua.org/
/usr/local/Cellar/lua/5.2.3_1 (13 files, 312K) *
  Built from source with: --with-completion
From: https://github.com/Homebrew/homebrew/blob/master/Library/Formula/lua.rb
==> Options
--universal
    Build a universal binary
--with-completion
    Enables advanced readline support
--without-sigaction
    Revert to ANSI signal instead of improved POSIX sigaction
15

When a package is built from source the flags that were used to build are shown when you do brew info <package>.

In this case: brew info emacs | grep "Built from source"

  • The output of brew info always lists all available options for the formula, not the options used if the package was installed. – Praxeolitic Oct 28 '14 at 16:03
  • 1
    That's not true. The info specifies if the package was installed from a bottle or built from source, and if it was built from source it shows the flags that were used. – André Oct 30 '14 at 21:50
  • Edited OP with an example in which, as far as I can tell, info does not specify the flags used for a package built from source. – Praxeolitic Oct 31 '14 at 21:12
  • 2
    Oh oops, I see it and your grep command makes sense now. – Praxeolitic Oct 31 '14 at 21:13
6

There is a file in /usr/local/Cellar underneath each package that is called INSTALL_RECEIPT.json, e.g. for gawk:

/usr/local/Cellar/gawk/4.1.3/INSTALL_RECEIPT.json

that defines how the package was installed. I think the correct way to access it is with

brew info --json=v1 <packagename>

e.g.

brew info --json=v1 gnuplot

That spews out loads of stuff, but if you send it through jq (JSON Processor - handily available via homebrew) you can select out the options you used to install the package like this (checking the gnuplot package):

brew info --json=v1 gnuplot | jq '.[].installed[0].used_options'
[
    "--with-qt"
]

which tells me I installed gnuplot using:

brew install --with-qt gnuplot 
  • This should be the answer. – Jacob Degeling Dec 14 '17 at 11:06
  • for package in $(brew list); do echo -n "brew install $package "; for item in $(brew info --json=v1 $package | jq -r '.[0].installed[0].used_options | .[]'); do echo -n "$item "; done; echo ; done 2>/dev/null can be used to output a list of brew install commands that you can use elsewhere. – Sankalp Jun 2 '18 at 4:27
4

Another useful tool is homebrew-bundler. Once installed via brew tap Homebrew/bundle, you can run brew bundle dump and it will create a Brewfile file that lists all of the packages you have installed along with any additional args used to install them.

  • This is indeed a nice option. And, to edit the Brewfile and check it into your dotfiles repo makes it easy to "setup" new machines. Though, it lists all packages including all dependencies. I'm currently having to parse the list from a brew leaves list that lists only the top-level installed packages. – eduncan911 Jul 24 '16 at 13:47
3

Here's a little bash function that returns the flags irrespective of if package was built from source or not.

function brew_options()
{
    [ "$#" -ne 1 ] && >&2 echo -e "$FUNCNAME requires only 1 option, the package name" && return 1

    local item=$1
    local opts

    ## Check if package installed
    [ -n "$(brew ls --versions $item)" ] || ( >&2 echo -e "$item is not installed" && return 1 )

    set -o pipefail

    ## Get options if built from source
    if ! opts="$(brew info $item | grep 'Built from source with:' | sed 's/^[ \t]*Built from source with:/ /g; s/\,/ /g')" ; then
        # If not built from source, get options from brew metadata
        opts="$(brew info --json=v1 $item | jq -ec '.[].installed[0].used_options' | awk '{print substr($0, 2, length($0) - 2)}' | sed 's/,/ /g;s/"//g')"
    fi

    ## If we're able to get options and its just not spaces echo it 
    if [ "$?" -eq 0 ] && [[ ! -z "${opts// }" ]]; then
        echo "$opts"
    fi

    set +o pipefail

}

To use this bash function within a bash script write

 brew_options PKGNAME

where PKGNAME is the desired homebrew package name. You can also iterate through all installed homebrew packages within a bash script as

 # Command to generate install script
 PKGS=$(brew list)

 # iterate through all packges
 for PKG in $PKGS; do

   echo $PKG `brew_options $PKG`

 done

.

  • depencency note: jq command-line JSON processor – l --marc l May 30 '17 at 1:09

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .