Skip to content

Commit

Permalink
Refactor
Browse files Browse the repository at this point in the history
Large refactor to Formula, mostly improving reliability and error handling but
also layout and readability.

General improvements so testing can be more complete.

Patches are automatically downloaded and applied for Formula that return a
list of urls from Formula::patches.

Split out the brew command logic to facilitate testing.

Facility from Adam Vandenberg to allow selective cleaning of files, added
because Python doesn't work when stripped.
  • Loading branch information
mxcl committed Aug 10, 2009
1 parent 6442e45 commit 6b6d369
Show file tree
Hide file tree
Showing 15 changed files with 672 additions and 585 deletions.
2 changes: 1 addition & 1 deletion Library/Contributions/brew_bash_completion.sh
Expand Up @@ -35,7 +35,7 @@ _brew_to_completion()
;;

# Commands that take an existing brew...
abv|info|list|link|ls|ln|rm|uninstall)
abv|info|list|link|ls|ln|rm|remove|uninstall)
cellar_contents=`ls ${brew_base}/Cellar/`
COMPREPLY=( $(compgen -W "${cellar_contents}" -- ${cur}) )
return 0
Expand Down
2 changes: 1 addition & 1 deletion Library/Formula/git.rb
@@ -1,6 +1,6 @@
require 'brewkit'

class GitManuals <UnidentifiedFormula
class GitManuals <Formula
@url='http://www.kernel.org/pub/software/scm/git/git-manpages-1.6.4.tar.bz2'
@md5='851e1df833895c5046a994c28d3d8368'
end
Expand Down
1 change: 0 additions & 1 deletion Library/Formula/grc.rb
Expand Up @@ -39,7 +39,6 @@ def caveats
file. Homebrew can do that for you, just execute this command:
brew install grc --profile >> ~/.profile
EOS
end
end
Expand Down
8 changes: 6 additions & 2 deletions Library/Formula/subversion.rb
@@ -1,6 +1,6 @@
require 'brewkit'

class SubversionDeps <UnidentifiedFormula
class SubversionDeps <Formula
@url='http://subversion.tigris.org/downloads/subversion-deps-1.6.3.tar.bz2'
@md5='22d3687ae93648fcecf945c045931272'
end
Expand All @@ -20,7 +20,11 @@ def install
# Use existing system zlib
# Use dep-provided other libraries
# Don't mess with Apache modules (since we're not sudo)
system "./configure --disable-debug --prefix='#{prefix}' --with-zlib=/usr/lib --disable-mod-activation --without-apache-libexecdir"
system "./configure", "--disable-debug",
"--prefix=#{prefix}",
"--with-zlib=/usr/lib",
"--disable-mod-activation",
"--without-apache-libexecdir"
system "make"
system "make install"
end
Expand Down
4 changes: 2 additions & 2 deletions Library/Formula/taglib.rb
@@ -1,6 +1,6 @@
require 'brewkit'

class TaglibExtras <UnidentifiedFormula
class TaglibExtras <Formula
@url='http://kollide.net/~jefferai/taglib-extras-0.1.6.tar.gz'
@md5='706a82fe4c25606f731faf4c14b5edb0'
end
Expand All @@ -14,7 +14,7 @@ def install
system "./configure --disable-debug --prefix='#{prefix}'"
system "make install"

TaglibExtras.new.brew do |f|
TaglibExtras.new.brew do
system "cmake . #{std_cmake_parameters}"
system "make install"
end unless ARGV.include? '--no-extras'
Expand Down
10 changes: 4 additions & 6 deletions Library/Formula/term.rb
@@ -1,10 +1,8 @@
require 'brewkit'

class Term <ScriptFileFormula
def initialize
@url='http://github.com/liyanage/macosx-shell-scripts/raw/e29f7eaa1eb13d78056dec85dc517626ab1d93e3/term'
@md5='1bbf4509a50224b27ac8c20d3fe8682e'
@version='2.1'
@homepage='http://gist.github.com/116587'
end
@url='http://github.com/liyanage/macosx-shell-scripts/raw/e29f7eaa1eb13d78056dec85dc517626ab1d93e3/term'
@md5='1bbf4509a50224b27ac8c20d3fe8682e'
@version='2.1'
@homepage='http://gist.github.com/116587'
end
238 changes: 238 additions & 0 deletions Library/Homebrew/brew.h.rb
@@ -0,0 +1,238 @@
# Copyright 2009 Max Howell <max@methylblue.com>
#
# This file is part of Homebrew.
#
# Homebrew is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# Homebrew is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with Homebrew. If not, see <http://www.gnu.org/licenses/>.

def make url
require 'formula'

path=Pathname.new url

/(.*?)[-_.]?#{path.version}/.match path.basename
raise "Couldn't parse name from #{url}" if $1.nil? or $1.empty?

path=Formula.path $1
raise "#{path} already exists" if path.exist?

template=<<-EOS
require 'brewkit'
class #{Formula.class $1} <Formula
@url='#{url}'
@homepage=''
@md5=''
cmake def deps
cmake BinaryDep.new 'cmake'
cmake end
cmake
def install
autotools system "./configure --prefix='\#{prefix}' --disable-debug --disable-dependency-tracking"
cmake system "cmake . \#{cmake_std_parameters}"
system "make install"
end
end
EOS

mode=nil
if ARGV.include? '--cmake'
mode= :cmake
elsif ARGV.include? '--autotools'
mode= :autotools
end

f=File.new path, 'w'
template.each_line do |s|
if s.strip.empty?
f.puts
next
end
cmd=s[0..11].strip
if cmd.empty?
cmd=nil
else
cmd=cmd.to_sym
end
out=s[12..-1] || ''

if mode.nil?
# we show both but comment out cmake as it is less common
# the implication being the pacakger should remove whichever is not needed
if cmd == :cmake and not out.empty?
f.print '#'
out = out[1..-1]
end
elsif cmd != mode and not cmd.nil?
next
end
f.puts out
end
f.close

return path
end


def info name
require 'formula'

history="http://github.com/mxcl/homebrew/commits/masterbrew/Library/Formula/#{Formula.path(name).basename}"
exec 'open', history if ARGV.flag? '--github'

f=Formula.factory name
puts "#{f.name} #{f.version}"
puts f.homepage

if f.prefix.parent.directory?
kids=f.prefix.parent.children
kids.each do |keg|
print "#{keg} (#{keg.abv})"
print " *" if f.prefix == keg and kids.length > 1
puts
end
else
puts "Not installed"
end

if f.caveats
puts
puts f.caveats
puts
end

puts history

rescue FormulaUnavailableError
# check for DIY installation
d=HOMEBREW_PREFIX+name
if d.directory?
ohai "DIY Installation"
d.children.each {|keg| puts "#{keg} (#{keg.abv})"}
else
raise "No such formula or keg"
end
end


def clean f
Cleaner.new f
# remove empty directories TODO Rubyize!
`perl -MFile::Find -e"finddepth(sub{rmdir},'#{f.prefix}')"`
end


def install f
f.brew do
if ARGV.flag? '--interactive'
ohai "Entering interactive mode"
puts "Type `exit' to return and finalize the installation"
puts "Install to this prefix: #{f.prefix}"
interactive_shell
elsif ARGV.include? '--help'
system './configure --help'
exit $?
else
f.prefix.mkpath
f.install
%w[README ChangeLog COPYING LICENSE COPYRIGHT AUTHORS].each do |file|
f.prefix.install file if File.file? file
end
end
end
end


def prune
$n=0
$d=0

dirs=Array.new
paths=%w[bin etc lib include share].collect {|d| HOMEBREW_PREFIX+d}

paths.each do |path|
path.find do |path|
path.extend ObserverPathnameExtension
if path.symlink?
path.unlink unless path.resolved_path_exists?
elsif path.directory?
dirs<<path
end
end
end
dirs.sort.reverse_each {|d| d.rmdir_if_possible}
if $n == 0 and $d == 0
puts "Nothing pruned" if ARGV.verbose?
else
# always showing symlinks text is deliberate
print "Pruned #{$n} symbolic links "
print "and #{$n} directories " if $d > 0
puts "from #{HOMEBREW_PREFIX}"
end
end
################################################################ class Cleaner
class Cleaner
def initialize f
@f=f
[f.bin, f.lib].each {|d| clean_dir d}
end
private
def strip path, args=''
return if @f.skip_clean? path
puts "strip #{path}" if ARGV.verbose?
path.chmod 0644 # so we can strip
unless path.stat.nlink > 1
`strip #{args} #{path}`
else
# strip unlinks the file and recreates it, thus breaking hard links!
# is this expected behaviour? patch does it too… still,mktm this fixes it
tmp=`mktemp -t #{path.basename}`.strip
`strip #{args} -o #{tmp} #{path}`
`cat #{tmp} > #{path}`
File.unlink tmp
end
end
def clean_file path
perms=0444
case `file -h #{path}`
when /Mach-O dynamically linked shared library/
strip path, '-SxX'
when /Mach-O [^ ]* ?executable/
strip path
perms=0544
when /script text executable/
perms=0544
end
path.chmod perms
end
def clean_dir d
d.find do |path|
if not path.file?
next
elsif path.extname == '.la' and not @f.skip_clean? path
# *.la files are stupid
path.unlink
else
clean_file path
end
end
end
end
25 changes: 0 additions & 25 deletions Library/Homebrew/env.rb

This file was deleted.

0 comments on commit 6b6d369

Please sign in to comment.