Where should I call ohai and friends?

(David E Wheeler) #1

I’ve used ohai to generate output about features for my formula, like so:

if build.with? "vertica-support"
  depends_on "libiodbc" => :recommended
  ohai "Vertica support requires the Vertica ODBC driver and vsql"
  ohai "  - Downloads: https://my.vertica.com/download/vertica/client-drivers/"
  ohai "  - ODBC Docs: https://my.vertica.com/docs/9.1.x/HTML/index.htm#Authoring/ConnectingToVertica/InstallingDrivers/MacOSX/InstallingTheODBCDriverOnMacOSX.htm"

So it nicely shows this output when I pass --with-vertica-support — but, unfortunately, it does it several times. Is the class reloaded multiple times in a given run? Do I need to put such calls in the install method? Or is there perhaps a method that gets called before or after install into which I should put such info? If so, would I have to keep the depends_on at the class level?

(Jonathan Chang) #2

It sounds like you instead want to write a custom Requirement, which is something that you use when your formulae requires something from outside of Homebrew to install or run. Run grep -r Requirement $(brew --repo homebrew/core)/Formula to see some examples in homebrew/core, or check out the built-in Requirements. The RRequirement in monetdb is probably the most straightforward.

(David E Wheeler) #3

Yes, I think you’re right. But what about dependencies that may or may not be Homebrew installed, like Postgres? What’s the way to validate that the user either has the Homebrew postgresql' installed or, if not, a version of PostgreSQL installed some other way is present (i.e., psql and pg_config are available)?

Thank you!

(Sean Molenaar) #4

Homebrew pretty much requires all dependencies be installed through homebrew. Otherwise it’d be impossible to keep track of. You should probably just recommend/require the postgres formula.

(David E Wheeler) #5

Well that certainly keeps things simpler. Thanks!