Move methods from FileUtils to Formula
These don't need to live on FileUtils and don't really make sense there either.
This commit is contained in:
parent
5c6ef3d920
commit
256dfc1af9
@ -1,53 +0,0 @@
|
||||
require "fileutils"
|
||||
require "etc"
|
||||
|
||||
# Homebrew extends Ruby's `FileUtils` to make our code more readable.
|
||||
# @see https://ruby-doc.org/stdlib-2.0.0/libdoc/fileutils/rdoc/FileUtils.html Ruby's FileUtils API
|
||||
module FileUtils
|
||||
# @private
|
||||
alias old_mkdir mkdir
|
||||
|
||||
# A version of mkdir that also changes to that folder in a block.
|
||||
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?
|
||||
chdir name do
|
||||
yield
|
||||
end
|
||||
end
|
||||
module_function :mkdir
|
||||
|
||||
# Run `scons` using a Homebrew-installed version rather than whatever is in the `PATH`.
|
||||
def scons(*args)
|
||||
system Formulary.factory("scons").opt_bin/"scons", *args
|
||||
end
|
||||
|
||||
# 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"
|
||||
make_path = "/usr/bin/make"
|
||||
else
|
||||
make = Formula["make"].opt_bin/"make"
|
||||
make_path = make.exist? ? make.to_s : (Formula["make"].opt_bin/"gmake").to_s
|
||||
end
|
||||
|
||||
if superenv?
|
||||
make_name = File.basename(make_path)
|
||||
with_env(HOMEBREW_MAKE: make_name) do
|
||||
system "make", *args
|
||||
end
|
||||
else
|
||||
system make_path, *args
|
||||
end
|
||||
end
|
||||
|
||||
# Run `xcodebuild` without Homebrew's compiler environment variables set.
|
||||
def xcodebuild(*args)
|
||||
removed = ENV.remove_cc_etc
|
||||
system "xcodebuild", *args
|
||||
ensure
|
||||
ENV.update(removed)
|
||||
end
|
||||
end
|
@ -1907,6 +1907,56 @@ class Formula
|
||||
end
|
||||
end
|
||||
|
||||
# A version of `FileUtils.mkdir` that also changes to that folder in
|
||||
# a block.
|
||||
def mkdir(name)
|
||||
result = FileUtils.mkdir_p(name)
|
||||
return result unless block_given?
|
||||
FileUtils.chdir name do
|
||||
yield
|
||||
end
|
||||
end
|
||||
|
||||
# Run `scons` using a Homebrew-installed version rather than whatever is
|
||||
# in the `PATH`.
|
||||
def scons(*args)
|
||||
system Formulary.factory("scons").opt_bin/"scons", *args
|
||||
end
|
||||
|
||||
# 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"
|
||||
make_path = "/usr/bin/make"
|
||||
else
|
||||
make = Formula["make"].opt_bin/"make"
|
||||
make_path = if make.exist?
|
||||
make.to_s
|
||||
else
|
||||
(Formula["make"].opt_bin/"gmake").to_s
|
||||
end
|
||||
end
|
||||
|
||||
if superenv?
|
||||
make_name = File.basename(make_path)
|
||||
with_env(HOMEBREW_MAKE: make_name) do
|
||||
system "make", *args
|
||||
end
|
||||
else
|
||||
system make_path, *args
|
||||
end
|
||||
end
|
||||
|
||||
# Run `xcodebuild` without Homebrew's compiler environment variables set.
|
||||
def xcodebuild(*args)
|
||||
removed = ENV.remove_cc_etc
|
||||
system "xcodebuild", *args
|
||||
ensure
|
||||
ENV.update(removed)
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
# Returns the prefix for a given formula version number.
|
||||
|
@ -33,7 +33,7 @@ HOMEBREW_BOTTLE_DEFAULT_DOMAIN = ENV["HOMEBREW_BOTTLE_DEFAULT_DOMAIN"] ||
|
||||
HOMEBREW_BOTTLE_DOMAIN = ENV["HOMEBREW_BOTTLE_DOMAIN"] ||
|
||||
HOMEBREW_BOTTLE_DEFAULT_DOMAIN
|
||||
|
||||
require "extend/fileutils"
|
||||
require "fileutils"
|
||||
|
||||
module Homebrew
|
||||
extend FileUtils
|
||||
|
@ -182,6 +182,14 @@ class Resource
|
||||
patches << p
|
||||
end
|
||||
|
||||
protected
|
||||
|
||||
def mktemp(prefix)
|
||||
Mktemp.new(prefix).run do |staging|
|
||||
yield staging
|
||||
end
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
def detect_version(val)
|
||||
@ -196,12 +204,6 @@ class Resource
|
||||
end
|
||||
end
|
||||
|
||||
def mktemp(prefix)
|
||||
Mktemp.new(prefix).run do |staging|
|
||||
yield staging
|
||||
end
|
||||
end
|
||||
|
||||
class Go < Resource
|
||||
def stage(target)
|
||||
super(target/name)
|
||||
|
@ -1303,6 +1303,17 @@ describe Formula do
|
||||
end
|
||||
end
|
||||
|
||||
describe "#mkdir" do
|
||||
let(:dst) { mktmpdir }
|
||||
|
||||
it "creates intermediate directories" do
|
||||
f.mkdir dst/"foo/bar/baz" do
|
||||
expect(dst/"foo/bar/baz").to exist, "foo/bar/baz was not created"
|
||||
expect(dst/"foo/bar/baz").to be_a_directory, "foo/bar/baz was not a directory structure"
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
describe "with changed version scheme" do
|
||||
let(:f) do
|
||||
formula "testball" do
|
||||
|
@ -289,16 +289,3 @@ describe Pathname do
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
describe FileUtils do
|
||||
let(:dst) { mktmpdir }
|
||||
|
||||
describe "#mkdir" do
|
||||
it "creates intermediate directories" do
|
||||
described_class.mkdir dst/"foo/bar/baz" do
|
||||
expect(dst/"foo/bar/baz").to exist, "foo/bar/baz was not created"
|
||||
expect(dst/"foo/bar/baz").to be_a_directory, "foo/bar/baz was not a directory structure"
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
Loading…
x
Reference in New Issue
Block a user