Class: Formula Abstract

Inherits:
Object show all
Extended by:
BuildEnvironmentDSL, Enumerable
Includes:
FileUtils, Utils::Inreplace, Utils::Shell
Defined in:
Library/Homebrew/formula.rb

Overview

This class is abstract.

A formula provides instructions and metadata for Homebrew to install a piece of software. Every Homebrew formula is a Formula. All subclasses of Formula (and all Ruby classes) have to be named UpperCase and not-use-dashes. A formula specified in this-formula.rb should have a class named ThisFormula. Homebrew does enforce that the name of the file and the class correspond. Make sure you check with brew search that the name is free!

class Wget < Formula
  homepage "https://www.gnu.org/software/wget/"
  url "https://ftp.gnu.org/gnu/wget/wget-1.15.tar.gz"
  sha256 "52126be8cf1bddd7536886e74c053ad7d0ed2aa89b4b630f76785bac21695fcd"

  def install
    system "./configure", "--prefix=#{prefix}"
    system "make", "install"
  end
end

Class Attribute Summary collapse

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Methods included from Utils::Shell

export_value, from_path, parent, preferred, prepend_path_in_profile, profile

Methods included from Utils::Inreplace

inreplace

Methods included from FileUtils

#make, mkdir, mktemp, #rake, #ruby, #scons, #xcodebuild

Class Attribute Details

.bottle(*args, &block) ⇒ Object

Adds a bottle SoftwareSpec. This provides a pre-built binary package built by the Homebrew maintainers for you. It will be installed automatically if there is a binary package for your platform and you haven't passed or previously used any options on this formula.

If you maintain your own repository, you can add your own bottle links. http://docs.brew.sh/Bottles.html You can ignore this block entirely if submitting to Homebrew/Homebrew, It'll be handled for you by the Brew Test Bot.

bottle do
  root_url "https://example.com" # Optional root to calculate bottle URLs
  prefix "/opt/homebrew" # Optional HOMEBREW_PREFIX in which the bottles were built.
  cellar "/opt/homebrew/Cellar" # Optional HOMEBREW_CELLAR in which the bottles were built.
  rebuild 1 # Making the old bottle outdated without bumping the version/revision of the formula.
  sha256 "4355a46b19d348dc2f57c046f8ef63d4538ebb936000f3c9ee954a27460dd865" => :el_capitan
  sha256 "53c234e5e8472b6ac51c1ae1cab3fe06fad053beb8ebfd8977b010655bfdd3c3" => :yosemite
  sha256 "1121cfccd5913f0a63fec40a6ffd44ea64f9dc135c66634ba001d10bcf4302a2" => :mavericks
end

Only formulae where the upstream URL breaks or moves frequently, require compile or have a reasonable amount of patches/resources should be bottled. Formulae which do not meet the above requirements should not be bottled.

Formulae which should not be bottled & can be installed without any compile required should be tagged with:

bottle :unneeded

Otherwise formulae which do not meet the above requirements and should not be bottled should be tagged with:

bottle :disable, "reasons"


2147
2148
2149
# File 'Library/Homebrew/formula.rb', line 2147

def bottle(*args, &block)
  stable.bottle(*args, &block)
end

.deprecated_option(hash) ⇒ Object

Deprecated options are used to rename options and migrate users who used them to newer ones. They are mostly used for migrating non-with options (e.g. enable-debug) to with options (e.g. with-debug).

deprecated_option "enable-debug" => "with-debug"


2306
2307
2308
# File 'Library/Homebrew/formula.rb', line 2306

def deprecated_option(hash)
  specs.each { |spec| spec.deprecated_option(hash) }
end

.desc=(value) ⇒ Object (writeonly)

A one-line description of the software. Used by users to get an overview of the software and Homebrew maintainers. Shows when running brew info.

desc "Example formula"


2009
# File 'Library/Homebrew/formula.rb', line 2009

attr_rw :desc

.devel(&block) ⇒ Object

Adds a devel SoftwareSpec. This can be installed by passing the --devel option to allow installing non-stable (e.g. beta) versions of software.

devel do
  url "https://example.com/archive-2.0-beta.tar.gz"
  sha256 "2a2ba417eebaadcb4418ee7b12fe2998f26d6e6f7fda7983412ff66a741ab6f7"

  depends_on "cairo"
  depends_on "pixman"
end


2186
2187
2188
2189
2190
# File 'Library/Homebrew/formula.rb', line 2186

def devel(&block)
  @devel ||= SoftwareSpec.new
  return @devel unless block_given?
  @devel.instance_eval(&block)
end

.head(val = nil, specs = {}, &block) ⇒ Object

Adds a head SoftwareSpec. This can be installed by passing the --HEAD option to allow installing software directly from a branch of a version-control repository. If called as a method this provides just the url for the SoftwareSpec. If a block is provided you can also add depends_on and #patches just to the head SoftwareSpec. The download strategies (e.g. :using =>) are the same as for url. master is the default branch and doesn't need stating with a :branch parameter.

head "https://we.prefer.https.over.git.example.com/.git"
head "https://example.com/.git", :branch => "name_of_branch", :revision => "abc123"

or (if autodetect fails):

head "https://hg.is.awesome.but.git.has.won.example.com/", :using => :hg


2204
2205
2206
2207
2208
2209
2210
2211
2212
2213
# File 'Library/Homebrew/formula.rb', line 2204

def head(val = nil, specs = {}, &block)
  @head ||= HeadSoftwareSpec.new
  if block_given?
    @head.instance_eval(&block)
  elsif val
    @head.url(val, specs)
  else
    @head
  end
end

.homepage=(value) ⇒ Object (writeonly)

The homepage for the software. Used by users to get more information about the software and Homebrew maintainers as a point of contact for e.g. submitting patches. Can be opened with running brew home.

homepage "https://www.example.com"


2018
# File 'Library/Homebrew/formula.rb', line 2018

attr_rw :homepage

.mirror(val) ⇒ Object

Additional URLs for the #stable version of the formula. These are only used if the url fails to download. It's optional and there can be more than one. Generally we add them when the main url is unreliable. If url is really unreliable then we may swap the mirror and url.

mirror "https://in.case.the.host.is.down.example.com"
mirror "https://in.case.the.mirror.is.down.example.com


2099
2100
2101
# File 'Library/Homebrew/formula.rb', line 2099

def mirror(val)
  stable.mirror(val)
end

.option(name, description = "") ⇒ Object

Options can be used as arguments to brew install. To switch features on/off: "with-something" or "with-otherthing". To use other software: "with-other-software" or "without-foo" Note, that for depends_on that are :optional or :recommended, options are generated automatically.

There are also some special options:

  • :universal: build a universal binary/library (e.g. on newer Intel Macs this means a combined x86_64/x86 binary/library).
    option "with-spam", "The description goes here without a dot at the end"
    option "with-qt", "Text here overwrites the autogenerated one from 'depends_on "qt" => :optional'"
    option :universal


2297
2298
2299
# File 'Library/Homebrew/formula.rb', line 2297

def option(name, description = "")
  specs.each { |spec| spec.option(name, description) }
end

.revision=(value) ⇒ Object (writeonly)

Used for creating new Homebrew versions of software without new upstream versions. For example, if we bump the major version of a library this Formula depends_on then we may need to update the revision of this Formula to install a new version linked against the new library version. 0 if unset.

revision 1


2041
# File 'Library/Homebrew/formula.rb', line 2041

attr_rw :revision

.sha256=(value) ⇒ Object (writeonly)

To verify the #cached_download's integrity and security we verify the SHA-256 hash matches what we've declared in the Formula. To quickly fill this value you can leave it blank and run brew fetch --force and it'll tell you the currently valid value.

sha256 "2a2ba417eebaadcb4418ee7b12fe2998f26d6e6f7fda7983412ff66a741ab6f7"


2111
2112
2113
# File 'Library/Homebrew/formula.rb', line 2111

Checksum::TYPES.each do |type|
  define_method(type) { |val| stable.send(type, val) }
end

.stable(&block) ⇒ Object

Allows adding depends_on and #patches just to the stable SoftwareSpec. This is required instead of using a conditional. It is preferrable to also pull the url and sha256 into the block if one is added.

stable do
  url "https://example.com/foo-1.0.tar.gz"
  sha256 "2a2ba417eebaadcb4418ee7b12fe2998f26d6e6f7fda7983412ff66a741ab6f7"

  depends_on "libxml2"
  depends_on "libffi"
end


2168
2169
2170
2171
2172
# File 'Library/Homebrew/formula.rb', line 2168

def stable(&block)
  @stable ||= SoftwareSpec.new
  return @stable unless block_given?
  @stable.instance_eval(&block)
end

.url(val, specs = {}) ⇒ Object

The URL used to download the source for the #stable version of the formula. We prefer https for security and proxy reasons. If not inferrable, specify the download strategy with :using => ... :git, :hg, :svn, :bzr, :cvs, :curl (normal file download. Will also extract.) :nounzip (without extracting) :post (download via an HTTP POST) S3DownloadStrategy (download from S3 using signed request)

url "https://packed.sources.and.we.prefer.https.example.com/archive-1.2.3.tar.bz2"
url "https://some.dont.provide.archives.example.com",
    :using => :git,
    :tag => "1.2.3",
    :revision => "db8e4de5b2d6653f66aea53094624468caad15d2"


2076
2077
2078
# File 'Library/Homebrew/formula.rb', line 2076

def url(val, specs = {})
  stable.url(val, specs)
end

.version(val = nil) ⇒ Object

The version string for the #stable version of the formula. The version is autodetected from the URL and/or tag so only needs to be declared if it cannot be autodetected correctly.

version "1.2-final"


2086
2087
2088
# File 'Library/Homebrew/formula.rb', line 2086

def version(val = nil)
  stable.version(val)
end

.version_scheme=(value) ⇒ Object (writeonly)

Used for creating new Homebrew versions schemes. For example, if we want to change version scheme from one to another, then we may need to update version_scheme of this Formula to be able to use new version scheme. E.g. to move from 20151020 scheme to 1.0.0 we need to increment version_scheme. Without this, the prior scheme will always equate to a higher version. 0 if unset.

version_scheme 1


2053
# File 'Library/Homebrew/formula.rb', line 2053

attr_rw :version_scheme

Instance Attribute Details

#alias_nameObject (readonly)

The name of the alias that was used to identify this Formula. e.g. another-name-for-this-formula



70
71
72
# File 'Library/Homebrew/formula.rb', line 70

def alias_name
  @alias_name
end

#alias_pathObject (readonly)

The path to the alias that was used to identify this Formula. e.g. /usr/local/Library/Taps/homebrew/homebrew-core/Aliases/another-name-for-this-formula



66
67
68
# File 'Library/Homebrew/formula.rb', line 66

def alias_path
  @alias_path
end

#buildBuildOptions

The BuildOptions for this Formula. Lists the arguments passed and any #options in the Formula. Note that these may differ at different times during the installation of a Formula. This is annoying but the result of state that we're trying to eliminate.

Returns:



159
160
161
# File 'Library/Homebrew/formula.rb', line 159

def build
  @build
end

#buildpathObject (readonly)

The current working directory during builds. Will only be non-nil inside #install.



138
139
140
# File 'Library/Homebrew/formula.rb', line 138

def buildpath
  @buildpath
end

#follow_installed_aliasBoolean Also known as: follow_installed_alias?

A Boolean indicating whether this formula should be considered outdated if the target of the alias it was installed with has since changed. Defaults to true.

Returns:

  • (Boolean)


165
166
167
# File 'Library/Homebrew/formula.rb', line 165

def follow_installed_alias
  @follow_installed_alias
end

#full_alias_nameObject (readonly)

The fully-qualified alias referring to this Formula. For core formula it's the same as #alias_name. e.g. homebrew/tap-name/another-name-for-this-formula



80
81
82
# File 'Library/Homebrew/formula.rb', line 80

def full_alias_name
  @full_alias_name
end

#full_nameObject (readonly)

The fully-qualified name of this Formula. For core formula it's the same as #name. e.g. homebrew/tap-name/this-formula



75
76
77
# File 'Library/Homebrew/formula.rb', line 75

def full_name
  @full_name
end

#nameObject (readonly)

The name of this Formula. e.g. this-formula



62
63
64
# File 'Library/Homebrew/formula.rb', line 62

def name
  @name
end

#pathObject (readonly)

The full path to this Formula. e.g. /usr/local/Library/Taps/homebrew/homebrew-core/Formula/this-formula.rb



84
85
86
# File 'Library/Homebrew/formula.rb', line 84

def path
  @path
end

#revisionObject (readonly)

Used for creating new Homebrew versions of software without new upstream versions.

See Also:



131
132
133
# File 'Library/Homebrew/formula.rb', line 131

def revision
  @revision
end

#testpathObject (readonly)

The current working directory during tests. Will only be non-nil inside #test.



142
143
144
# File 'Library/Homebrew/formula.rb', line 142

def testpath
  @testpath
end

#version_schemeObject (readonly)

Used to change version schemes for packages



134
135
136
# File 'Library/Homebrew/formula.rb', line 134

def version_scheme
  @version_scheme
end

Class Method Details

.[](name) ⇒ Object



1491
1492
1493
# File 'Library/Homebrew/formula.rb', line 1491

def self.[](name)
  Formulary.factory(name)
end

.clear_installed_formulae_cacheObject

Clear caches of .racks and .installed.



1416
1417
1418
1419
# File 'Library/Homebrew/formula.rb', line 1416

def self.clear_installed_formulae_cache
  clear_racks_cache
  @installed = nil
end

.clear_racks_cacheObject

Clear cache of .racks



1411
1412
1413
# File 'Library/Homebrew/formula.rb', line 1411

def self.clear_racks_cache
  @racks = nil
end

.conflicts_with(*names) ⇒ Object

If this formula conflicts with another one.

conflicts_with "imagemagick", :because => "because this is just a stupid example"


2366
2367
2368
2369
# File 'Library/Homebrew/formula.rb', line 2366

def conflicts_with(*names)
  opts = names.last.is_a?(Hash) ? names.pop : {}
  names.each { |name| conflicts << FormulaConflict.new(name, opts[:because]) }
end

.cxxstdlib_check(check_type) ⇒ Object

Pass :skip to this method to disable post-install stdlib checking



2395
2396
2397
# File 'Library/Homebrew/formula.rb', line 2395

def cxxstdlib_check(check_type)
  define_method(:skip_cxxstdlib_check?) { true } if check_type == :skip
end

.depends_on(dep) ⇒ Object

The dependencies for this formula. Use strings for the names of other formulae. Homebrew provides some :special dependencies for stuff that requires certain extra handling (often changing some ENV vars or deciding if to use the system provided version or not.)

# `:build` means this dep is only needed during build.
depends_on "cmake" => :build
depends_on "homebrew/dupes/tcl-tk" => :optional
# `:recommended` dependencies are built by default.
# But a `--without-...` option is generated to opt-out.
depends_on "readline" => :recommended
# `:optional` dependencies are NOT built by default.
# But a `--with-...` options is generated.
depends_on "glib" => :optional
# If you need to specify that another formula has to be built with/out
# certain options (note, no `--` needed before the option):
depends_on "zeromq" => "with-pgm"
depends_on "qt" => ["with-qtdbus", "developer"] # Multiple options.
# Optional and enforce that boost is built with `--with-c++11`.
depends_on "boost" => [:optional, "with-c++11"]
# If a dependency is only needed in certain cases:
depends_on "sqlite" if MacOS.version == :leopard
depends_on :xcode # If the formula really needs full Xcode.
depends_on :tex # Homebrew does not provide a Tex Distribution.
depends_on :fortran # Checks that `gfortran` is available or `FC` is set.
depends_on :mpi => :cc # Needs MPI with `cc`
depends_on :mpi => [:cc, :cxx, :optional] # Is optional. MPI with `cc` and `cxx`.
depends_on :macos => :lion # Needs at least OS X Lion (10.7).
depends_on :apr # If a formula requires the CLT-provided apr library to exist.
depends_on :arch => :intel # If this formula only builds on Intel architecture.
depends_on :arch => :x86_64 # If this formula only builds on Intel x86 64-bit.
depends_on :arch => :ppc # Only builds on PowerPC?
depends_on :ld64 # Sometimes ld fails on `MacOS.version < :leopard`. Then use this.
depends_on :x11 # X11/XQuartz components. Non-optional X11 deps should go in Homebrew/Homebrew-x11
depends_on :osxfuse # Permits the use of the upstream signed binary or our source package.
depends_on :tuntap # Does the same thing as above. This is vital for Yosemite and above.
depends_on :mysql => :recommended
# It is possible to only depend on something if
# `build.with?` or `build.without? "another_formula"`:
depends_on :mysql # allows brewed or external mysql to be used
depends_on :postgresql if build.without? "sqlite"
depends_on :hg # Mercurial (external or brewed) is needed
# If any Python >= 2.7 < 3.x is okay (either from macOS or brewed):
depends_on :python
# to depend on Python >= 2.7 but use system Python where possible
depends_on :python if MacOS.version <= :snow_leopard
# Python 3.x if the `--with-python3` is given to `brew install example`
depends_on :python3 => :optional


2280
2281
2282
# File 'Library/Homebrew/formula.rb', line 2280

def depends_on(dep)
  specs.each { |spec| spec.depends_on(dep) }
end

.fails_with(compiler, &block) ⇒ Object

Marks the Formula as failing with a particular compiler so it will fall back to others. For Apple compilers, this should be in the format:

fails_with :clang do
  build 600
  cause "multiple configure and compile errors"
end

The block may be omitted, and if present the build may be omitted; if so, then the compiler will be blacklisted for all versions.

major_version should be the major release number only, for instance '4.8' for the GCC 4.8 series (4.8.0, 4.8.1, etc.). If version or the block is omitted, then the compiler will be blacklisted for all compilers in that series.

For example, if a bug is only triggered on GCC 4.8.1 but is not encountered on 4.8.2:

fails_with :gcc => '4.8' do
  version '4.8.1'
end


2420
2421
2422
2423
# File 'Library/Homebrew/formula.rb', line 2420

def fails_with(compiler, &block)
  # odeprecated "fails_with :llvm" if compiler == :llvm
  specs.each { |spec| spec.fails_with(compiler, &block) }
end

.go_resource(name, &block) ⇒ Object



2228
2229
2230
# File 'Library/Homebrew/formula.rb', line 2228

def go_resource(name, &block)
  specs.each { |spec| spec.go_resource(name, &block) }
end

.installed_with_alias_path(alias_path) ⇒ Object



1444
1445
1446
1447
# File 'Library/Homebrew/formula.rb', line 1444

def self.installed_with_alias_path(alias_path)
  return [] if alias_path.nil?
  installed.select { |f| f.installed_alias_path == alias_path }
end

.keg_only(reason, explanation = "") ⇒ Object

Software that will not be sym-linked into the brew --prefix will only live in its Cellar. Other formulae can depend on it and then brew will add the necessary includes and libs (etc.) during the brewing of that other formula. But generally, keg_only formulae are not in your PATH and not seen by compilers if you build your own software outside of Homebrew. This way, we don't shadow software provided by macOS.

keg_only :provided_by_macos
keg_only "because I want it so"


2390
2391
2392
# File 'Library/Homebrew/formula.rb', line 2390

def keg_only(reason, explanation = "")
  @keg_only_reason = KegOnlyReason.new(reason, explanation)
end

.needs(*standards) ⇒ Object



2425
2426
2427
# File 'Library/Homebrew/formula.rb', line 2425

def needs(*standards)
  specs.each { |spec| spec.needs(*standards) }
end

.patch(strip = :p1, src = nil, &block) ⇒ Object

External patches can be declared using resource-style blocks.

patch do
  url "https://example.com/example_patch.diff"
  sha256 "c6bc3f48ce8e797854c4b865f6a8ff969867bbcaebd648ae6fd825683e59fef2"
end

A strip level of -p1 is assumed. It can be overridden using a symbol argument:

patch :p0 do
  url "https://example.com/example_patch.diff"
  sha256 "c6bc3f48ce8e797854c4b865f6a8ff969867bbcaebd648ae6fd825683e59fef2"
end

Patches can be declared in stable, devel, and head blocks. This form is preferred over using conditionals.

stable do
  patch do
    url "https://example.com/example_patch.diff"
    sha256 "c6bc3f48ce8e797854c4b865f6a8ff969867bbcaebd648ae6fd825683e59fef2"
  end
end

Embedded (__END__) patches are declared like so:

patch :DATA
patch :p0, :DATA

Patches can also be embedded by passing a string. This makes it possible to provide multiple embedded patches while making only some of them conditional.

patch :p0, "..."


2340
2341
2342
# File 'Library/Homebrew/formula.rb', line 2340

def patch(strip = :p1, src = nil, &block)
  specs.each { |spec| spec.patch(strip, src, &block) }
end

.plist_options(options) ⇒ Object

Defines launchd plist handling.

Does your plist need to be loaded at startup?

plist_options :startup => true

Or only when necessary or desired by the user?

plist_options :manual => "foo"

Or perhaps you'd like to give the user a choice? Ooh fancy.

plist_options :startup => true, :manual => "foo start"


2354
2355
2356
2357
# File 'Library/Homebrew/formula.rb', line 2354

def plist_options(options)
  @plist_startup = options[:startup]
  @plist_manual = options[:manual]
end

.pour_bottle?(&block) ⇒ Boolean

Defines whether the Formula's bottle can be used on the given Homebrew installation.

For example, if the bottle requires the Xcode CLT to be installed a Formula would declare:

pour_bottle? do
  reason "The bottle needs the Xcode CLT to be installed."
  satisfy { MacOS::CLT.installed? }
end

If satisfy returns false then a bottle will not be used and instead the Formula will be built from source and reason will be printed.

Returns:

  • (Boolean)


2469
2470
2471
2472
# File 'Library/Homebrew/formula.rb', line 2469

def pour_bottle?(&block)
  @pour_bottle_check = PourBottleCheck.new(self)
  @pour_bottle_check.instance_eval(&block)
end

.resource(name, klass = Resource, &block) ⇒ Object

Additional downloads can be defined as resources and accessed in the install method. Resources can also be defined inside a stable, devel, or head block. This mechanism replaces ad-hoc "subformula" classes.

resource "additional_files" do
  url "https://example.com/additional-stuff.tar.gz"
  sha256 "c6bc3f48ce8e797854c4b865f6a8ff969867bbcaebd648ae6fd825683e59fef2"
end


2222
2223
2224
2225
2226
# File 'Library/Homebrew/formula.rb', line 2222

def resource(name, klass = Resource, &block)
  specs.each do |spec|
    spec.resource(name, klass, &block) unless spec.resource_defined?(name)
  end
end

.skip_clean(*paths) ⇒ Object



2371
2372
2373
2374
2375
# File 'Library/Homebrew/formula.rb', line 2371

def skip_clean(*paths)
  paths.flatten!
  # Specifying :all is deprecated and will become an error
  skip_clean_paths.merge(paths)
end

.test(&block) ⇒ Boolean

Test (is required for new formula and makes us happy). The block will create, run in and delete a temporary directory.

We are fine if the executable does not error out, so we know linking and building the software was ok.

system bin/"foobar", "--version"
(testpath/"test.file").write <<-EOS.undent
  writing some test file, if you need to
EOS
assert_equal "OK", shell_output("test_command test.file").strip

Need complete control over stdin, stdout?

require "open3"
Open3.popen3("#{bin}/example", "argument") do |stdin, stdout, _|
  stdin.write("some text")
  stdin.close
  assert_equal "result", stdout.read
end

The test will fail if it returns false, or if an exception is raised. Failed assertions and failed system commands will raise exceptions.

Returns:

  • (Boolean)


2453
2454
2455
# File 'Library/Homebrew/formula.rb', line 2453

def test(&block)
  define_method(:test, &block)
end

Instance Method Details

#_outdated_kegs(options = {}) ⇒ Object



1197
1198
1199
1200
1201
1202
1203
1204
1205
1206
1207
1208
1209
1210
1211
1212
1213
1214
1215
1216
1217
1218
1219
1220
1221
1222
1223
1224
1225
1226
# File 'Library/Homebrew/formula.rb', line 1197

def _outdated_kegs(options = {})
  all_kegs = []

  installed_kegs.each do |keg|
    all_kegs << keg
    version = keg.version
    next if version.head?

    tab = Tab.for_keg(keg)
    next if version_scheme > tab.version_scheme
    next if version_scheme == tab.version_scheme && pkg_version > version

    # don't consider this keg current if there's a newer formula available
    next if follow_installed_alias? && new_formula_available?

    return [] # this keg is the current version of the formula, so it's not outdated
  end

  # Even if this formula hasn't been installed, there may be installations
  # of other formulae which used to be targets of the alias currently
  # targetting this formula. These should be counted as outdated versions.
  all_kegs.concat old_installed_formulae.flat_map(&:installed_kegs)

  head_version = latest_head_version
  if head_version && !head_version_outdated?(head_version, options)
    []
  else
    all_kegs.sort_by(&:version)
  end
end

#active_log_prefixObject

The prefix, if any, to use in filenames for logging current activity



875
876
877
878
879
880
881
# File 'Library/Homebrew/formula.rb', line 875

def active_log_prefix
  if active_log_type
    "#{active_log_type}."
  else
    ""
  end
end

#alias_changed?Boolean

Has the alias used to install the formula changed, or are different formulae already installed with this alias?

Returns:

  • (Boolean)


1250
1251
1252
# File 'Library/Homebrew/formula.rb', line 1250

def alias_changed?
  installed_alias_target_changed? || supersedes_an_installed_formula?
end

#aliasesObject

All of aliases for the formula



410
411
412
413
414
415
416
# File 'Library/Homebrew/formula.rb', line 410

def aliases
  @aliases ||= if tap
    tap.alias_reverse_table[full_name] || []
  else
    []
  end
end

#bash_completionObject

The directory where the formula's Bash completion files should be installed. This is symlinked into HOMEBREW_PREFIX after installation or with brew link for formulae that are not keg-only.



840
841
842
# File 'Library/Homebrew/formula.rb', line 840

def bash_completion
  prefix+"etc/bash_completion.d"
end

#binObject

The directory where the formula's binaries should be installed. This is symlinked into HOMEBREW_PREFIX after installation or with brew link for formulae that are not keg-only.

Need to install into the #bin but the makefile doesn't mkdir -p prefix/bin?

bin.mkpath

No make install available?

bin.install "binary1"


623
624
625
# File 'Library/Homebrew/formula.rb', line 623

def bin
  prefix+"bin"
end

#caveatsString

Tell the user about any Homebrew-specific caveats or locations regarding this package. These should not contain setup instructions that would apply to installation through a different package manager on a different OS.

def caveats
  <<-EOS.undent
    Are optional. Something the user should know?
  EOS
end
def caveats
  s = <<-EOS.undent
    Print some important notice to the user when `brew info <formula>` is
    called or when brewing a formula.
    This is optional. You can use all the vars like #{version} here.
  EOS
  s += "Some issue only on older systems" if MacOS.version < :mountain_lion
  s
end

Returns:



1059
1060
1061
# File 'Library/Homebrew/formula.rb', line 1059

def caveats
  nil
end

#current_installed_alias_targetObject



1232
1233
1234
# File 'Library/Homebrew/formula.rb', line 1232

def current_installed_alias_target
  Formulary.factory(installed_alias_path) if installed_alias_path
end

#descObject

The description of the software.

See Also:



357
358
359
# File 'Library/Homebrew/formula.rb', line 357

def desc
  self.class.desc
end

#docObject

The directory where the formula's documentation should be installed. This is symlinked into HOMEBREW_PREFIX after installation or with brew link for formulae that are not keg-only.



630
631
632
# File 'Library/Homebrew/formula.rb', line 630

def doc
  share+"doc"+name
end

#elispObject

The directory where Emacs Lisp files should be installed, with the formula name appended to avoid linking conflicts.

Install an Emacs mode included with a software package:

elisp.install "contrib/emacs/example-mode.el"


784
785
786
# File 'Library/Homebrew/formula.rb', line 784

def elisp
  prefix+"share/emacs/site-lisp"+name
end

#etcObject

The directory where the formula's configuration files should be installed. Anything using etc.install will not overwrite other files on e.g. upgrades but will write a new file named *.default. This directory is not inside the HOMEBREW_CELLAR so it is persisted across upgrades.



809
810
811
# File 'Library/Homebrew/formula.rb', line 809

def etc
  (HOMEBREW_PREFIX+"etc").extend(InstallRenamed)
end

#fish_completionObject

The directory where the formula's fish completion files should be installed. This is symlinked into HOMEBREW_PREFIX after installation or with brew link for formulae that are not keg-only.



856
857
858
# File 'Library/Homebrew/formula.rb', line 856

def fish_completion
  share+"fish/vendor_completions.d"
end

#fish_functionObject

The directory where the formula's fish function files should be installed. This is symlinked into HOMEBREW_PREFIX after installation or with brew link for formulae that are not keg-only.



832
833
834
# File 'Library/Homebrew/formula.rb', line 832

def fish_function
  share+"fish/vendor_functions.d"
end

#frameworksObject

The directory where the formula's Frameworks should be installed. This is symlinked into HOMEBREW_PREFIX after installation or with brew link for formulae that are not keg-only. This is not symlinked into HOMEBREW_PREFIX.



792
793
794
# File 'Library/Homebrew/formula.rb', line 792

def frameworks
  prefix+"Frameworks"
end

#full_installed_alias_nameObject



270
271
272
# File 'Library/Homebrew/formula.rb', line 270

def full_installed_alias_name
  full_name_with_optional_tap(installed_alias_name)
end

#full_installed_specified_nameObject

The name (including tap) specified to install this formula.



295
296
297
# File 'Library/Homebrew/formula.rb', line 295

def full_installed_specified_name
  full_installed_alias_name || full_name
end

#full_specified_nameObject

The name (including tap) specified to find this formula.



285
286
287
# File 'Library/Homebrew/formula.rb', line 285

def full_specified_name
  full_alias_name || full_name
end

#head_version_outdated?(version, options = {}) ⇒ Boolean

Returns:

  • (Boolean)


520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
# File 'Library/Homebrew/formula.rb', line 520

def head_version_outdated?(version, options = {})
  tab = Tab.for_keg(prefix(version))

  return true if tab.version_scheme < version_scheme
  return true if stable && tab.stable_version && tab.stable_version < stable.version
  return true if devel && tab.devel_version && tab.devel_version < devel.version

  if options[:fetch_head]
    return false unless head && head.downloader.is_a?(VCSDownloadStrategy)
    downloader = head.downloader
    downloader.shutup! unless ARGV.verbose?
    downloader.commit_outdated?(version.version.commit)
  else
    false
  end
end

#homepageObject

The homepage for the software.

See Also:



363
364
365
# File 'Library/Homebrew/formula.rb', line 363

def homepage
  self.class.homepage
end

#includeObject

The directory where the formula's headers should be installed. This is symlinked into HOMEBREW_PREFIX after installation or with brew link for formulae that are not keg-only.

No make install available?

include.install "example.h"


640
641
642
# File 'Library/Homebrew/formula.rb', line 640

def include
  prefix+"include"
end

#infoObject

The directory where the formula's info files should be installed. This is symlinked into HOMEBREW_PREFIX after installation or with brew link for formulae that are not keg-only.



647
648
649
# File 'Library/Homebrew/formula.rb', line 647

def info
  share+"info"
end

#inreplace(paths, before = nil, after = nil) ⇒ Object

Actually implemented in Utils::Inreplace.inreplace. Sometimes we have to change a bit before we install. Mostly we prefer a patch but if you need the prefix of this formula in the patch you have to resort to inreplace, because in the patch you don't have access to any var defined by the formula. Only HOMEBREW_PREFIX is available in the embedded patch. inreplace supports regular expressions.

inreplace "somefile.cfg", /look[for]what?/, "replace by #{bin}/tool"


# File 'Library/Homebrew/formula.rb', line 49

#installObject

This method is overridden in Formula subclasses to provide the installation instructions. The sources (from url) are downloaded, hash-checked and Homebrew changes into a temporary directory where the archive was unpacked or repository cloned.

def install
  system "./configure", "--prefix=#{prefix}"
  system "make", "install"
end


1733
1734
# File 'Library/Homebrew/formula.rb', line 1733

def install
end

#installed_alias_nameObject



266
267
268
# File 'Library/Homebrew/formula.rb', line 266

def installed_alias_name
  File.basename(installed_alias_path) if installed_alias_path
end

#installed_alias_pathObject

The alias path that was used to install this formula, if it exists. Can differ from alias_path, which is the alias used to find the formula, and is specified to this instance.



259
260
261
262
263
264
# File 'Library/Homebrew/formula.rb', line 259

def installed_alias_path
  path = build.source["path"] if build.is_a?(Tab)
  return unless path =~ %r{#{HOMEBREW_TAP_DIR_REGEX}/Aliases}
  return unless File.symlink?(path)
  path
end

#installed_alias_target_changed?Boolean

Has the target of the alias used to install this formula changed? Returns false if the formula wasn't installed with an alias.

Returns:

  • (Boolean)


1238
1239
1240
1241
# File 'Library/Homebrew/formula.rb', line 1238

def installed_alias_target_changed?
  target = current_installed_alias_target
  target && target.name != name
end

#installed_specified_nameObject

The name specified to install this formula.



290
291
292
# File 'Library/Homebrew/formula.rb', line 290

def installed_specified_name
  installed_alias_name || name
end

#keg_only?Boolean

rarely, you don't want your library symlinked into the main prefix see gettext.rb for an example

Returns:

  • (Boolean)


1065
1066
1067
# File 'Library/Homebrew/formula.rb', line 1065

def keg_only?
  keg_only_reason && keg_only_reason.valid?
end

#kext_prefixObject

The directory where the formula's kernel extensions should be installed. This is symlinked into HOMEBREW_PREFIX after installation or with brew link for formulae that are not keg-only. This is not symlinked into HOMEBREW_PREFIX.



800
801
802
# File 'Library/Homebrew/formula.rb', line 800

def kext_prefix
  prefix+"Library/Extensions"
end

#latest_formulaObject

If the alias has changed value, return the new formula. Otherwise, return self.



1256
1257
1258
# File 'Library/Homebrew/formula.rb', line 1256

def latest_formula
  installed_alias_target_changed? ? current_installed_alias_target : self
end

#latest_head_prefixObject



515
516
517
518
# File 'Library/Homebrew/formula.rb', line 515

def latest_head_prefix
  head_version = latest_head_version
  prefix(head_version) if head_version
end

#latest_head_versionObject



504
505
506
507
508
509
510
511
512
513
# File 'Library/Homebrew/formula.rb', line 504

def latest_head_version
  head_versions = installed_prefixes.map do |pn|
    pn_pkgversion = PkgVersion.parse(pn.basename.to_s)
    pn_pkgversion if pn_pkgversion.head?
  end.compact

  head_versions.max_by do |pn_pkgversion|
    [Tab.for_keg(prefix(pn_pkgversion)).source_modified_time, pn_pkgversion.revision]
  end
end

#libObject

The directory where the formula's libraries should be installed. This is symlinked into HOMEBREW_PREFIX after installation or with brew link for formulae that are not keg-only.

No make install available?

lib.install "example.dylib"


657
658
659
# File 'Library/Homebrew/formula.rb', line 657

def lib
  prefix+"lib"
end

#libexecObject

The directory where the formula's binaries should be installed. This is not symlinked into HOMEBREW_PREFIX. It is also commonly used to install files that we do not wish to be symlinked into HOMEBREW_PREFIX from one of the other directories and instead manually create symlinks or wrapper scripts into e.g. #bin.



666
667
668
# File 'Library/Homebrew/formula.rb', line 666

def libexec
  prefix+"libexec"
end

#linked?Boolean

Is the formula linked?

Returns:

  • (Boolean)


574
575
576
# File 'Library/Homebrew/formula.rb', line 574

def linked?
  linked_keg.symlink?
end

#linked_versionObject

PkgVersion of the linked keg for the formula.



590
591
592
593
# File 'Library/Homebrew/formula.rb', line 590

def linked_version
  return unless linked?
  Keg.for(linked_keg).version
end

#manObject

The root directory where the formula's manual pages should be installed. This is symlinked into HOMEBREW_PREFIX after installation or with brew link for formulae that are not keg-only. Often one of the more specific man functions should be used instead e.g. #man1



675
676
677
# File 'Library/Homebrew/formula.rb', line 675

def man
  share+"man"
end

#man1Object

The directory where the formula's man1 pages should be installed. This is symlinked into HOMEBREW_PREFIX after installation or with brew link for formulae that are not keg-only.

No make install available?

man1.install "example.1"


685
686
687
# File 'Library/Homebrew/formula.rb', line 685

def man1
  man+"man1"
end

#man2Object

The directory where the formula's man2 pages should be installed. This is symlinked into HOMEBREW_PREFIX after installation or with brew link for formulae that are not keg-only.



692
693
694
# File 'Library/Homebrew/formula.rb', line 692

def man2
  man+"man2"
end

#man3Object

The directory where the formula's man3 pages should be installed. This is symlinked into HOMEBREW_PREFIX after installation or with brew link for formulae that are not keg-only.

No make install available?

man3.install "man.3"


702
703
704
# File 'Library/Homebrew/formula.rb', line 702

def man3
  man+"man3"
end

#man4Object

The directory where the formula's man4 pages should be installed. This is symlinked into HOMEBREW_PREFIX after installation or with brew link for formulae that are not keg-only.



709
710
711
# File 'Library/Homebrew/formula.rb', line 709

def man4
  man+"man4"
end

#man5Object

The directory where the formula's man5 pages should be installed. This is symlinked into HOMEBREW_PREFIX after installation or with brew link for formulae that are not keg-only.



716
717
718
# File 'Library/Homebrew/formula.rb', line 716

def man5
  man+"man5"
end

#man6Object

The directory where the formula's man6 pages should be installed. This is symlinked into HOMEBREW_PREFIX after installation or with brew link for formulae that are not keg-only.



723
724
725
# File 'Library/Homebrew/formula.rb', line 723

def man6
  man+"man6"
end

#man7Object

The directory where the formula's man7 pages should be installed. This is symlinked into HOMEBREW_PREFIX after installation or with brew link for formulae that are not keg-only.



730
731
732
# File 'Library/Homebrew/formula.rb', line 730

def man7
  man+"man7"
end

#man8Object

The directory where the formula's man8 pages should be installed. This is symlinked into HOMEBREW_PREFIX after installation or with brew link for formulae that are not keg-only.



737
738
739
# File 'Library/Homebrew/formula.rb', line 737

def man8
  man+"man8"
end

#migration_needed?Boolean

Returns:

  • (Boolean)


1177
1178
1179
1180
1181
1182
1183
1184
1185
1186
# File 'Library/Homebrew/formula.rb', line 1177

def migration_needed?
  return false unless oldname
  return false if rack.exist?

  old_rack = HOMEBREW_CELLAR/oldname
  return false unless old_rack.directory?
  return false if old_rack.subdirs.empty?

  tap == Tab.for_keg(old_rack.subdirs.first).tap
end

#missing_dependencies(hide: nil) ⇒ Object

Returns a list of formulae depended on by this formula that aren't installed



1553
1554
1555
1556
1557
1558
1559
1560
1561
1562
1563
1564
1565
1566
1567
1568
1569
1570
1571
# File 'Library/Homebrew/formula.rb', line 1553

def missing_dependencies(hide: nil)
  hide ||= []
  missing_dependencies = recursive_dependencies do |dependent, dep|
    if dep.optional? || dep.recommended?
      tab = Tab.for_formula(dependent)
      Dependency.prune unless tab.with?(dep)
    elsif dep.build?
      Dependency.prune
    end
  end

  missing_dependencies.map!(&:to_formula)
  missing_dependencies.select! do |d|
    hide.include?(d.name) || d.installed_prefixes.empty?
  end
  missing_dependencies
rescue FormulaUnavailableError
  []
end

#new_formula_available?Boolean

Returns:

  • (Boolean)


1228
1229
1230
# File 'Library/Homebrew/formula.rb', line 1228

def new_formula_available?
  installed_alias_target_changed? && !latest_formula.installed?
end

#old_installed_formulaeObject



1260
1261
1262
1263
1264
1265
1266
# File 'Library/Homebrew/formula.rb', line 1260

def old_installed_formulae
  # If this formula isn't the current target of the alias,
  # it doesn't make sense to say that other formulae are older versions of it
  # because we don't know which came first.
  return [] if alias_path.nil? || installed_alias_target_changed?
  self.class.installed_with_alias_path(alias_path).reject { |f| f.name == name }
end

#oldnameObject

An old name for the formula



402
403
404
405
406
407
# File 'Library/Homebrew/formula.rb', line 402

def oldname
  @oldname ||= if tap
    formula_renames = tap.formula_renames
    formula_renames.to_a.rassoc(name).first if formula_renames.value?(name)
  end
end

#opt_binObject



953
954
955
# File 'Library/Homebrew/formula.rb', line 953

def opt_bin
  opt_prefix+"bin"
end

#opt_elispObject



981
982
983
# File 'Library/Homebrew/formula.rb', line 981

def opt_elisp
  opt_prefix+"share/emacs/site-lisp"+name
end

#opt_frameworksObject



985
986
987
# File 'Library/Homebrew/formula.rb', line 985

def opt_frameworks
  opt_prefix+"Frameworks"
end

#opt_includeObject



957
958
959
# File 'Library/Homebrew/formula.rb', line 957

def opt_include
  opt_prefix+"include"
end

#opt_libObject



961
962
963
# File 'Library/Homebrew/formula.rb', line 961

def opt_lib
  opt_prefix+"lib"
end

#opt_libexecObject



965
966
967
# File 'Library/Homebrew/formula.rb', line 965

def opt_libexec
  opt_prefix+"libexec"
end

#opt_pkgshareObject



977
978
979
# File 'Library/Homebrew/formula.rb', line 977

def opt_pkgshare
  opt_prefix+"share"+name
end

#opt_prefixObject

A stable path for this formula, when installed. Contains the formula name but no version number. Only the active version will be linked here if multiple versions are installed.

This is the prefered way to refer a formula in plists or from another formula, as the path is stable even when the software is updated.

args << "--with-readline=#{Formula["readline"].opt_prefix}" if build.with? "readline"


949
950
951
# File 'Library/Homebrew/formula.rb', line 949

def opt_prefix
  Pathname.new("#{HOMEBREW_PREFIX}/opt/#{name}")
end

#opt_sbinObject



969
970
971
# File 'Library/Homebrew/formula.rb', line 969

def opt_sbin
  opt_prefix+"sbin"
end

#opt_shareObject



973
974
975
# File 'Library/Homebrew/formula.rb', line 973

def opt_share
  opt_prefix+"share"
end

#option_defined?(name) ⇒ Boolean

If a named option is defined for the currently active SoftwareSpec.

Returns:

  • (Boolean)


472
473
474
# File 'Library/Homebrew/formula.rb', line 472

def option_defined?(name)
  active_spec.option_defined?(name)
end

#optlinked?Boolean

Is the formula linked to opt?

Returns:

  • (Boolean)


579
580
581
# File 'Library/Homebrew/formula.rb', line 579

def optlinked?
  opt_prefix.symlink?
end

#pkg_versionObject

The PkgVersion for this formula with version and #revision information.



384
385
386
# File 'Library/Homebrew/formula.rb', line 384

def pkg_version
  PkgVersion.new(version, revision)
end

#pkgshareObject

The directory where the formula's shared files should be installed, with the name of the formula appended to avoid linking conflicts. This is symlinked into HOMEBREW_PREFIX after installation or with brew link for formulae that are not keg-only.

No make install available?

pkgshare.install "examples"


775
776
777
# File 'Library/Homebrew/formula.rb', line 775

def pkgshare
  prefix+"share"+name
end

#plistObject

This method can be overridden to provide a plist. For more examples read Apple's handy manpage: https://developer.apple.com/library/mac/documentation/Darwin/Reference/ManPages/man5/plist.5.html

def plist; <<-EOS.undent
 <?xml version="1.0" encoding="UTF-8"?>
 <!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
 <plist version="1.0">
 <dict>
   <key>Label</key>
     <string>#{plist_name}</string>
   <key>ProgramArguments</key>
   <array>
     <string>#{opt_bin}/example</string>
     <string>--do-this</string>
   </array>
   <key>RunAtLoad</key>
   <true/>
   <key>KeepAlive</key>
   <true/>
   <key>StandardErrorPath</key>
   <string>/dev/null</string>
   <key>StandardOutPath</key>
   <string>/dev/null</string>
 </plist>
 EOS
end


918
919
920
# File 'Library/Homebrew/formula.rb', line 918

def plist
  nil
end

#plist_nameObject

The generated launchd #plist service name.



923
924
925
# File 'Library/Homebrew/formula.rb', line 923

def plist_name
  "homebrew.mxcl."+name
end

#plist_pathObject

The generated launchd #plist file path.



928
929
930
# File 'Library/Homebrew/formula.rb', line 928

def plist_path
  prefix+(plist_name+".plist")
end

#post_installObject

Can be overridden to run commands on both source and bottle installation.



1005
# File 'Library/Homebrew/formula.rb', line 1005

def post_install; end

#pour_bottle?Boolean

Indicates that this formula supports bottles. (Not necessarily that one should be used in the current installation run.) Can be overridden to selectively disable bottles from formulae. Defaults to true so overridden version does not have to check if bottles are supported. Replaced by pour_bottle's satisfy method if it is specified.

Returns:

  • (Boolean)


995
996
997
# File 'Library/Homebrew/formula.rb', line 995

def pour_bottle?
  true
end

#prefix(v = pkg_version) ⇒ Object

The directory in the cellar that the formula is installed to. This directory points to #opt_prefix if it exists and if ##prefix is not called from within the same formula's #install or #post_install methods. Otherwise, return the full path to the formula's versioned cellar.



563
564
565
566
567
568
569
570
571
# File 'Library/Homebrew/formula.rb', line 563

def prefix(v = pkg_version)
  versioned_prefix = versioned_prefix(v)
  if !@prefix_returns_versioned_prefix && v == pkg_version &&
     versioned_prefix.directory? && Keg.new(versioned_prefix).optlinked?
    opt_prefix
  else
    versioned_prefix
  end
end

#prefix_linked?(v = pkg_version) ⇒ Boolean

Is formula's linked keg points to the prefix.

Returns:

  • (Boolean)


584
585
586
587
# File 'Library/Homebrew/formula.rb', line 584

def prefix_linked?(v = pkg_version)
  return false unless linked?
  linked_keg.resolved_path == versioned_prefix(v)
end

#resource(name) ⇒ Object

A named Resource for the currently active SoftwareSpec. Additional downloads can be defined as #resources. Resource#stage will create a temporary directory and yield to a block.

resource("additional_files").stage { bin.install "my/extra/tool" }


397
398
399
# File 'Library/Homebrew/formula.rb', line 397

def resource(name)
  active_spec.resource(name)
end

#resourcesObject

The Resources for the currently active SoftwareSpec.



419
420
421
# File 'Library/Homebrew/formula.rb', line 419

def resources
  active_spec.resources.values
end

#sbinObject

The directory where the formula's sbin binaries should be installed. This is symlinked into HOMEBREW_PREFIX after installation or with brew link for formulae that are not keg-only. Generally we try to migrate these to #bin instead.



745
746
747
# File 'Library/Homebrew/formula.rb', line 745

def sbin
  prefix+"sbin"
end

#shareObject

The directory where the formula's shared files should be installed. This is symlinked into HOMEBREW_PREFIX after installation or with brew link for formulae that are not keg-only.

Need a custom directory?

(share/"concept").mkpath

Installing something into another custom directory?

(share/"concept2").install "ducks.txt"

Install ./example_code/simple/ones to share/demos

(share/"demos").install "example_code/simple/ones"

Install ./example_code/simple/ones to share/demos/examples

(share/"demos").install "example_code/simple/ones" => "examples"


764
765
766
# File 'Library/Homebrew/formula.rb', line 764

def share
  prefix+"share"
end

#skip_cxxstdlib_check?Boolean

Returns:

  • (Boolean)


1122
1123
1124
# File 'Library/Homebrew/formula.rb', line 1122

def skip_cxxstdlib_check?
  false
end

#specified_nameObject

The name specified to find this formula.



280
281
282
# File 'Library/Homebrew/formula.rb', line 280

def specified_name
  alias_name || name
end

#specified_pathObject

The path that was specified to find this formula.



275
276
277
# File 'Library/Homebrew/formula.rb', line 275

def specified_path
  alias_path || path
end

#std_cmake_argsObject

Standard parameters for CMake builds. Setting CMAKE_FIND_FRAMEWORK to "LAST" tells CMake to search for our libraries before trying to utilize Frameworks, many of which will be from 3rd party installs. Note: there isn't a std_autotools variant because autotools is a lot less consistent and the standard parameters are more memorable.



1334
1335
1336
1337
1338
1339
1340
1341
1342
1343
1344
1345
1346
1347
1348
1349
1350
1351
1352
# File 'Library/Homebrew/formula.rb', line 1334

def std_cmake_args
  args = %W[
    -DCMAKE_C_FLAGS_RELEASE=-DNDEBUG
    -DCMAKE_CXX_FLAGS_RELEASE=-DNDEBUG
    -DCMAKE_INSTALL_PREFIX=#{prefix}
    -DCMAKE_BUILD_TYPE=Release
    -DCMAKE_FIND_FRAMEWORK=LAST
    -DCMAKE_VERBOSE_MAKEFILE=ON
    -Wno-dev
  ]

  # Avoid false positives for clock_gettime support on 10.11.
  # CMake cache entries for other weak symbols may be added here as needed.
  if MacOS.version == "10.11" && MacOS::Xcode.installed? && MacOS::Xcode.version >= "8.0"
    args << "-DHAVE_CLOCK_GETTIME:INTERNAL=0"
  end

  args
end

#supersedes_an_installed_formula?Boolean

Is this formula the target of an alias used to install an old formula?

Returns:

  • (Boolean)


1244
1245
1246
# File 'Library/Homebrew/formula.rb', line 1244

def supersedes_an_installed_formula?
  old_installed_formulae.any?
end

#system(cmd, *args) ⇒ Object

To call out to the system, we use the system method and we prefer you give the args separately as in the line below, otherwise a subshell has to be opened first.

system "./bootstrap.sh", "--arg1", "--prefix=#{prefix}"

For CMake we have some necessary defaults in #std_cmake_args:

system "cmake", ".", *std_cmake_args

If the arguments given to configure (or make or cmake) are depending on options defined above, we usually make a list first and then use the args << if <condition> to append to:

args = ["--with-option1", "--with-option2"]

# Most software still uses `configure` and `make`.
# Check with `./configure --help` what our options are.
system "./configure", "--disable-debug", "--disable-dependency-tracking",
                      "--disable-silent-rules", "--prefix=#{prefix}",
                      *args # our custom arg list (needs `*` to unpack)

# If there is a "make", "install" available, please use it!
system "make", "install"


1771
1772
1773
1774
1775
1776
1777
1778
1779
1780
1781
1782
1783
1784
1785
1786
1787
1788
1789
1790
1791
1792
1793
1794
1795
1796
1797
1798
1799
1800
1801
1802
1803
1804
1805
1806
1807
1808
1809
1810
1811
1812
1813
1814
1815
1816
1817
1818
1819
1820
1821
1822
1823
1824
1825
1826
1827
1828
1829
1830
1831
1832
1833
1834
1835
1836
1837
1838
1839
1840
1841
1842
1843
1844
1845
1846
1847
1848
1849
1850
1851
1852
1853
1854
1855
1856
1857
1858
1859
# File 'Library/Homebrew/formula.rb', line 1771

def system(cmd, *args)
  verbose = ARGV.verbose?
  verbose_using_dots = !ENV["HOMEBREW_VERBOSE_USING_DOTS"].nil?

  # remove "boring" arguments so that the important ones are more likely to
  # be shown considering that we trim long ohai lines to the terminal width
  pretty_args = args.dup
  if cmd == "./configure" && !verbose
    pretty_args.delete "--disable-dependency-tracking"
    pretty_args.delete "--disable-debug"
  end
  pretty_args.each_index do |i|
    if pretty_args[i].to_s.start_with? "import setuptools"
      pretty_args[i] = "import setuptools..."
    end
  end
  ohai "#{cmd} #{pretty_args*" "}".strip

  @exec_count ||= 0
  @exec_count += 1
  logfn = format("#{logs}/#{active_log_prefix}%02d.%s", @exec_count, File.basename(cmd).split(" ").first)
  logs.mkpath

  File.open(logfn, "w") do |log|
    log.puts Time.now, "", cmd, args, ""
    log.flush

    if verbose
      rd, wr = IO.pipe
      begin
        pid = fork do
          rd.close
          log.close
          exec_cmd(cmd, args, wr, logfn)
        end
        wr.close

        if verbose_using_dots
          last_dot = Time.at(0)
          while buf = rd.gets
            log.puts buf
            # make sure dots printed with interval of at least 1 min.
            next unless (Time.now - last_dot) > 60
            print "."
            $stdout.flush
            last_dot = Time.now
          end
          puts
        else
          while buf = rd.gets
            log.puts buf
            puts buf
          end
        end
      ensure
        rd.close
      end
    else
      pid = fork { exec_cmd(cmd, args, log, logfn) }
    end

    Process.wait(pid)

    $stdout.flush

    unless $?.success?
      log_lines = ENV["HOMEBREW_FAIL_LOG_LINES"]
      log_lines ||= "15"

      log.flush
      if !verbose || verbose_using_dots
        puts "Last #{log_lines} lines from #{logfn}:"
        Kernel.system "/usr/bin/tail", "-n", log_lines, logfn
      end
      log.puts

      require "system_config"
      require "build_environment"

      env = ENV.to_hash

      SystemConfig.dump_verbose_config(log)
      log.puts
      Homebrew.dump_build_env(env, log)

      raise BuildError.new(self, cmd, args, env)
    end
  end
end

#to_sObject



1319
1320
1321
# File 'Library/Homebrew/formula.rb', line 1319

def to_s
  name
end

#update_head_versionObject



375
376
377
378
379
380
381
# File 'Library/Homebrew/formula.rb', line 375

def update_head_version
  return unless head?
  return unless head.downloader.is_a?(VCSDownloadStrategy)
  return unless head.downloader.cached_location.exist?

  head.version.update_commit(head.downloader.last_commit)
end

#varObject

The directory where the formula's variable files should be installed. This directory is not inside the HOMEBREW_CELLAR so it is persisted across upgrades.



816
817
818
# File 'Library/Homebrew/formula.rb', line 816

def var
  HOMEBREW_PREFIX+"var"
end

#versionObject

The version for the currently active SoftwareSpec. The version is autodetected from the URL and/or tag so only needs to be declared if it cannot be autodetected correctly.

See Also:



371
372
373
# File 'Library/Homebrew/formula.rb', line 371

def version
  active_spec.version
end

#versioned_formula?Boolean

If this is a @-versioned formula.

Returns:

  • (Boolean)


389
390
391
# File 'Library/Homebrew/formula.rb', line 389

def versioned_formula?
  name.include?("@")
end

#with_logging(log_type) ⇒ Object

Runs a block with the given log type in effect for its duration



884
885
886
887
888
889
890
# File 'Library/Homebrew/formula.rb', line 884

def with_logging(log_type)
  old_log_type = @active_log_type
  @active_log_type = log_type
  yield
ensure
  @active_log_type = old_log_type
end

#zsh_completionObject

The directory where the formula's ZSH completion files should be installed. This is symlinked into HOMEBREW_PREFIX after installation or with brew link for formulae that are not keg-only.



848
849
850
# File 'Library/Homebrew/formula.rb', line 848

def zsh_completion
  share+"zsh/site-functions"
end

#zsh_functionObject

The directory where the formula's ZSH function files should be installed. This is symlinked into HOMEBREW_PREFIX after installation or with brew link for formulae that are not keg-only.



824
825
826
# File 'Library/Homebrew/formula.rb', line 824

def zsh_function
  share+"zsh/site-functions"
end