aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAdam Vandenberg2012-03-04 16:48:00 -0800
committerAdam Vandenberg2012-03-05 21:14:39 -0800
commit1b372d7840a60c8d592aa03e5c95fb41a6c5fb6b (patch)
tree9c967f79e64833166227cafbac81e8ba8c2448a4
parent19a0aa51a1e8e5df95f9b802b165ea9ffce9cf27 (diff)
downloadbrew-1b372d7840a60c8d592aa03e5c95fb41a6c5fb6b.tar.bz2
Move path utils out of formula.rb
Make a new module for our FileUtils extensions and use that instead.
-rw-r--r--Library/Homebrew/extend/fileutils.rb40
-rw-r--r--Library/Homebrew/formula.rb46
2 files changed, 47 insertions, 39 deletions
diff --git a/Library/Homebrew/extend/fileutils.rb b/Library/Homebrew/extend/fileutils.rb
new file mode 100644
index 000000000..89c7de2fe
--- /dev/null
+++ b/Library/Homebrew/extend/fileutils.rb
@@ -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
diff --git a/Library/Homebrew/formula.rb b/Library/Homebrew/formula.rb
index 961077c09..06863c136 100644
--- a/Library/Homebrew/formula.rb
+++ b/Library/Homebrew/formula.rb
@@ -1,12 +1,12 @@
require 'download_strategy'
-require 'fileutils'
require 'formula_support'
require 'hardware'
+require 'extend/fileutils'
# Derive and define at least @url, see Library/Formula for examples
class Formula
- include FileUtils
+ include Homebrew::FileUtils
attr_reader :name, :path, :url, :version, :homepage, :specs, :downloader
attr_reader :standard, :unstable
@@ -128,16 +128,6 @@ class Formula
def plist_name; 'homebrew.mxcl.'+name 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.
# Can be overriden to force a custom download strategy
def download_strategy
@@ -441,6 +431,7 @@ class Formula
end
protected
+
# Pretty titles the command and buffers stdout/stderr
# Throws if there's an error
def system cmd, *args
@@ -485,33 +476,8 @@ protected
raise BuildError.new(self, cmd, args, $?)
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.
def fetch
downloader = @downloader
@@ -571,7 +537,9 @@ EOF
end
end
- private
+private
+
+ CHECKSUM_TYPES=[:md5, :sha1, :sha256].freeze
def stage
fetched, downloader = fetch