2015-03-13 20:59:17 -04:00
|
|
|
require "fileutils"
|
2016-02-04 06:26:23 -08:00
|
|
|
require "etc"
|
2012-03-04 16:48:00 -08:00
|
|
|
|
2015-08-29 10:56:24 +01:00
|
|
|
# Homebrew extends Ruby's `FileUtils` to make our code more readable.
|
2017-08-22 10:31:21 +00:00
|
|
|
# @see https://ruby-doc.org/stdlib-2.0.0/libdoc/fileutils/rdoc/FileUtils.html Ruby's FileUtils API
|
2014-06-09 21:36:36 -05:00
|
|
|
module FileUtils
|
2015-08-29 10:56:24 +01:00
|
|
|
# @private
|
2016-09-23 18:13:48 +02:00
|
|
|
alias old_mkdir mkdir
|
2015-08-29 10:56:24 +01:00
|
|
|
|
|
|
|
# A version of mkdir that also changes to that folder in a block.
|
2018-07-13 08:05:33 +01:00
|
|
|
def mkdir(name, mode: nil, noop: nil, verbose: nil, &_block)
|
|
|
|
result = mkdir_p(name, mode: mode, noop: noop, verbose: verbose)
|
|
|
|
return result unless block_given?
|
2016-09-23 22:02:23 +02:00
|
|
|
chdir name do
|
|
|
|
yield
|
2012-03-04 16:48:00 -08:00
|
|
|
end
|
|
|
|
end
|
2014-06-09 21:36:36 -05:00
|
|
|
module_function :mkdir
|
2012-03-04 16:48:00 -08:00
|
|
|
|
2015-08-29 10:56:24 +01:00
|
|
|
# Run `scons` using a Homebrew-installed version rather than whatever is in the `PATH`.
|
2015-08-03 13:09:07 +01:00
|
|
|
def scons(*args)
|
2014-03-14 16:41:57 -05:00
|
|
|
system Formulary.factory("scons").opt_bin/"scons", *args
|
2014-02-28 07:20:52 -08:00
|
|
|
end
|
|
|
|
|
2015-06-26 20:06:11 -07:00
|
|
|
# Run `make` 3.81 or newer.
|
|
|
|
# Uses the system make on Leopard and newer, and the
|
|
|
|
# path to the actually-installed make on Tiger or older.
|
|
|
|
def make(*args)
|
|
|
|
if Utils.popen_read("/usr/bin/make", "--version").match(/Make (\d\.\d+)/)[1] > "3.80"
|
2017-07-07 15:50:01 -07:00
|
|
|
make_path = "/usr/bin/make"
|
2015-06-26 20:06:11 -07:00
|
|
|
else
|
|
|
|
make = Formula["make"].opt_bin/"make"
|
|
|
|
make_path = make.exist? ? make.to_s : (Formula["make"].opt_bin/"gmake").to_s
|
2017-07-07 15:50:01 -07:00
|
|
|
end
|
|
|
|
|
|
|
|
if superenv?
|
|
|
|
make_name = File.basename(make_path)
|
2017-10-29 14:44:43 +00:00
|
|
|
with_env(HOMEBREW_MAKE: make_name) do
|
2017-07-07 15:50:01 -07:00
|
|
|
system "make", *args
|
|
|
|
end
|
|
|
|
else
|
2015-06-26 20:06:11 -07:00
|
|
|
system make_path, *args
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2015-08-29 10:56:24 +01:00
|
|
|
# Run `xcodebuild` without Homebrew's compiler environment variables set.
|
2015-08-03 13:09:07 +01:00
|
|
|
def xcodebuild(*args)
|
2014-02-27 21:47:38 -06:00
|
|
|
removed = ENV.remove_cc_etc
|
|
|
|
system "xcodebuild", *args
|
|
|
|
ensure
|
|
|
|
ENV.update(removed)
|
|
|
|
end
|
2012-03-04 16:48:00 -08:00
|
|
|
end
|