Move path utils out of formula.rb
Make a new module for our FileUtils extensions and use that instead.
This commit is contained in:
parent
19a0aa51a1
commit
1b372d7840
40
Library/Homebrew/extend/fileutils.rb
Normal file
40
Library/Homebrew/extend/fileutils.rb
Normal file
@ -0,0 +1,40 @@
|
|||||||
|
require 'fileutils'
|
||||||
|
|
||||||
|
# We enhance FileUtils to make our Formula code more readable.
|
||||||
|
module Homebrew::FileUtils
|
||||||
|
include FileUtils
|
||||||
|
|
||||||
|
# Create a temporary directory then yield. When the block returns,
|
||||||
|
# recursively delete the temporary directory.
|
||||||
|
def mktemp
|
||||||
|
# I used /tmp rather than `mktemp -td` because that generates a directory
|
||||||
|
# name with exotic characters like + in it, and these break badly written
|
||||||
|
# scripts that don't escape strings before trying to regexp them :(
|
||||||
|
|
||||||
|
# If the user has FileVault enabled, then we can't mv symlinks from the
|
||||||
|
# /tmp volume to the other volume. So we let the user override the tmp
|
||||||
|
# prefix if they need to.
|
||||||
|
tmp_prefix = ENV['HOMEBREW_TEMP'] || '/tmp'
|
||||||
|
tmp=Pathname.new `/usr/bin/mktemp -d #{tmp_prefix}/homebrew-#{name}-#{version}-XXXX`.strip
|
||||||
|
raise "Couldn't create build sandbox" if not tmp.directory? or $? != 0
|
||||||
|
begin
|
||||||
|
wd=Dir.pwd
|
||||||
|
chdir tmp
|
||||||
|
yield
|
||||||
|
ensure
|
||||||
|
chdir wd
|
||||||
|
tmp.rmtree
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
# A version of mkdir that also changes to that folder in a block.
|
||||||
|
def mkdir name, &block
|
||||||
|
super(name)
|
||||||
|
if block_given?
|
||||||
|
chdir name do
|
||||||
|
yield
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
end
|
@ -1,12 +1,12 @@
|
|||||||
require 'download_strategy'
|
require 'download_strategy'
|
||||||
require 'fileutils'
|
|
||||||
require 'formula_support'
|
require 'formula_support'
|
||||||
require 'hardware'
|
require 'hardware'
|
||||||
|
require 'extend/fileutils'
|
||||||
|
|
||||||
|
|
||||||
# Derive and define at least @url, see Library/Formula for examples
|
# Derive and define at least @url, see Library/Formula for examples
|
||||||
class Formula
|
class Formula
|
||||||
include FileUtils
|
include Homebrew::FileUtils
|
||||||
|
|
||||||
attr_reader :name, :path, :url, :version, :homepage, :specs, :downloader
|
attr_reader :name, :path, :url, :version, :homepage, :specs, :downloader
|
||||||
attr_reader :standard, :unstable
|
attr_reader :standard, :unstable
|
||||||
@ -128,16 +128,6 @@ class Formula
|
|||||||
def plist_name; 'homebrew.mxcl.'+name end
|
def plist_name; 'homebrew.mxcl.'+name end
|
||||||
def plist_path; prefix+(plist_name+'.plist') end
|
def plist_path; prefix+(plist_name+'.plist') end
|
||||||
|
|
||||||
# A version of mkdir that also changes to that folder in a block
|
|
||||||
def mkdir name, &block
|
|
||||||
FileUtils.mkdir name
|
|
||||||
if block_given?
|
|
||||||
FileUtils.chdir name do
|
|
||||||
yield
|
|
||||||
end
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
# Use the @spec_to_use to detect the download strategy.
|
# Use the @spec_to_use to detect the download strategy.
|
||||||
# Can be overriden to force a custom download strategy
|
# Can be overriden to force a custom download strategy
|
||||||
def download_strategy
|
def download_strategy
|
||||||
@ -441,6 +431,7 @@ class Formula
|
|||||||
end
|
end
|
||||||
|
|
||||||
protected
|
protected
|
||||||
|
|
||||||
# Pretty titles the command and buffers stdout/stderr
|
# Pretty titles the command and buffers stdout/stderr
|
||||||
# Throws if there's an error
|
# Throws if there's an error
|
||||||
def system cmd, *args
|
def system cmd, *args
|
||||||
@ -485,33 +476,8 @@ protected
|
|||||||
raise BuildError.new(self, cmd, args, $?)
|
raise BuildError.new(self, cmd, args, $?)
|
||||||
end
|
end
|
||||||
|
|
||||||
private
|
|
||||||
# Create a temporary directory then yield. When the block returns,
|
|
||||||
# recursively delete the temporary directory.
|
|
||||||
def mktemp
|
|
||||||
# I used /tmp rather than `mktemp -td` because that generates a directory
|
|
||||||
# name with exotic characters like + in it, and these break badly written
|
|
||||||
# scripts that don't escape strings before trying to regexp them :(
|
|
||||||
|
|
||||||
# If the user has FileVault enabled, then we can't mv symlinks from the
|
|
||||||
# /tmp volume to the other volume. So we let the user override the tmp
|
|
||||||
# prefix if they need to.
|
|
||||||
tmp_prefix = ENV['HOMEBREW_TEMP'] || '/tmp'
|
|
||||||
tmp=Pathname.new `/usr/bin/mktemp -d #{tmp_prefix}/homebrew-#{name}-#{version}-XXXX`.strip
|
|
||||||
raise "Couldn't create build sandbox" if not tmp.directory? or $? != 0
|
|
||||||
begin
|
|
||||||
wd=Dir.pwd
|
|
||||||
Dir.chdir tmp
|
|
||||||
yield
|
|
||||||
ensure
|
|
||||||
Dir.chdir wd
|
|
||||||
tmp.rmtree
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
CHECKSUM_TYPES=[:md5, :sha1, :sha256].freeze
|
|
||||||
|
|
||||||
public
|
public
|
||||||
|
|
||||||
# For brew-fetch and others.
|
# For brew-fetch and others.
|
||||||
def fetch
|
def fetch
|
||||||
downloader = @downloader
|
downloader = @downloader
|
||||||
@ -573,6 +539,8 @@ EOF
|
|||||||
|
|
||||||
private
|
private
|
||||||
|
|
||||||
|
CHECKSUM_TYPES=[:md5, :sha1, :sha256].freeze
|
||||||
|
|
||||||
def stage
|
def stage
|
||||||
fetched, downloader = fetch
|
fetched, downloader = fetch
|
||||||
verify_download_integrity fetched if fetched.kind_of? Pathname
|
verify_download_integrity fetched if fetched.kind_of? Pathname
|
||||||
|
Loading…
x
Reference in New Issue
Block a user