From ffd5b7d7ab9b616408d00b895f4ec0b2d38f6dd4 Mon Sep 17 00:00:00 2001 From: Jack Nagel Date: Fri, 26 Aug 2011 14:30:27 -0500 Subject: [PATCH 1/4] Add support for xz-compressed tarballs Rationale: some software (e.g. GNU Coreutils, GnuTLS 3.x), have started distributing _only_ xz-compressed tarballs. There is no system XZ utility provided by OS X, but it is necessary so that we can continue to provide formulae for this software. If XZUtils isn't installed, we abort and prompt the user to `brew install xz`. The `xz` command itself doesn't do any untarring, so we write the decompressed archive to stdout and pipe it to tar. --- Library/Homebrew/download_strategy.rb | 8 ++++++-- Library/Homebrew/extend/pathname.rb | 4 ++-- Library/Homebrew/test/test_bucket.rb | 2 ++ 3 files changed, 10 insertions(+), 4 deletions(-) diff --git a/Library/Homebrew/download_strategy.rb b/Library/Homebrew/download_strategy.rb index 58221c28f2..625dbaf9af 100644 --- a/Library/Homebrew/download_strategy.rb +++ b/Library/Homebrew/download_strategy.rb @@ -76,8 +76,8 @@ class CurlDownloadStrategy < AbstractDownloadStrategy # Use more than 4 characters to not clash with magicbytes magic_bytes = "____pkg" else - # get the first four bytes - File.open(@tarball_path) { |f| magic_bytes = f.read(4) } + # get the first six bytes + File.open(@tarball_path) { |f| magic_bytes = f.read(6) } end # magic numbers stolen from /usr/share/file/magic/ @@ -89,6 +89,10 @@ class CurlDownloadStrategy < AbstractDownloadStrategy # TODO check if it's really a tar archive safe_system '/usr/bin/tar', 'xf', @tarball_path chdir + when /^\xFD7zXZ\x00/ # xz compressed + raise "You must install XZutils: brew install xz" unless system "/usr/bin/which -s xz" + safe_system "xz -dc #{@tarball_path} | /usr/bin/tar xf -" + chdir when '____pkg' safe_system '/usr/sbin/pkgutil', '--expand', @tarball_path, File.basename(@url) chdir diff --git a/Library/Homebrew/extend/pathname.rb b/Library/Homebrew/extend/pathname.rb index 65d34d4500..018547ff80 100644 --- a/Library/Homebrew/extend/pathname.rb +++ b/Library/Homebrew/extend/pathname.rb @@ -62,9 +62,9 @@ class Pathname return dst end - # extended to support the double extensions .tar.gz and .tar.bz2 + # extended to support the double extensions .tar.gz, .tar.bz2, and .tar.xz def extname - /(\.tar\.(gz|bz2))$/.match to_s + /(\.tar\.(gz|bz2|xz))$/.match to_s return $1 if $1 return File.extname(to_s) end diff --git a/Library/Homebrew/test/test_bucket.rb b/Library/Homebrew/test/test_bucket.rb index 010c06761d..f328dacca1 100644 --- a/Library/Homebrew/test/test_bucket.rb +++ b/Library/Homebrew/test/test_bucket.rb @@ -32,8 +32,10 @@ class BeerTasting < Test::Unit::TestCase assert_nothing_raised do MockFormula.new 'test-0.1.tar.gz' MockFormula.new 'test-0.1.tar.bz2' + MockFormula.new 'test-0.1.tar.xz' MockFormula.new 'test-0.1.tgz' MockFormula.new 'test-0.1.bgz' + MockFormula.new 'test-0.1.txz' MockFormula.new 'test-0.1.zip' end end From e4bed29e99a2fb7be5b2c175f5d38d1cb294ef92 Mon Sep 17 00:00:00 2001 From: Jack Nagel Date: Sun, 11 Dec 2011 01:29:15 -0600 Subject: [PATCH 2/4] completion: complete multiple formula arguments We make the assumption that the first non-option word is the command being invoked. Originally I was trying to allow command completion for non-standard command lines like $ brew --verbose inst but right now executing something like that doesn't actually work. Which is interesting, because the man page implies that it should. Either the man page is incorrect, or something was broken between then and now. Anyway, it would probably be safe to just assume that COMP_WORDS[1] is the command, and we do make that assumption in other places. But if we ever do allow things like "brew --option command", this will be useful. Signed-off-by: Jack Nagel --- Library/Contributions/brew_bash_completion.sh | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/Library/Contributions/brew_bash_completion.sh b/Library/Contributions/brew_bash_completion.sh index 0289204717..97b3791909 100644 --- a/Library/Contributions/brew_bash_completion.sh +++ b/Library/Contributions/brew_bash_completion.sh @@ -205,7 +205,14 @@ _brew_to_completion() esac fi - case "$prev" in + # find the index of the *first* non-switch word + # we can use this to allow completion for multiple formula arguments + local cmd_index=1 + while [[ ${COMP_WORDS[cmd_index]} == -* ]]; do + cmd_index=$((++cmd_index)) + done + + case "${COMP_WORDS[cmd_index]}" in # Commands that take a formula cat|deps|edit|fetch|home|homepage|info|install|log|missing|options|uses|versions) local ff=$(\ls $(brew --repository)/Library/Formula 2> /dev/null | sed "s/\.rb//g") From 3f76af69d3c74aefd7a232bc7fa948ce1d7d6685 Mon Sep 17 00:00:00 2001 From: Jack Nagel Date: Sun, 11 Dec 2011 01:30:15 -0600 Subject: [PATCH 3/4] completion: audit takes formula arguments - Also remove `--strict` completion since that option was removed. Signed-off-by: Jack Nagel --- Library/Contributions/brew_bash_completion.sh | 7 +------ 1 file changed, 1 insertion(+), 6 deletions(-) diff --git a/Library/Contributions/brew_bash_completion.sh b/Library/Contributions/brew_bash_completion.sh index 97b3791909..355d6443f8 100644 --- a/Library/Contributions/brew_bash_completion.sh +++ b/Library/Contributions/brew_bash_completion.sh @@ -63,11 +63,6 @@ _brew_to_completion() # handle subcommand options if [[ "$cur" == --* ]]; then case "${COMP_WORDS[1]}" in - audit) - local opts=$([[ "${COMP_WORDS[*]}" =~ "--strict" ]] || echo "--strict") - COMPREPLY=( $(compgen -W "$opts" -- ${cur}) ) - return - ;; cleanup) local opts=$([[ "${COMP_WORDS[*]}" =~ "--force" ]] || echo "--force") COMPREPLY=( $(compgen -W "$opts" -- ${cur}) ) @@ -214,7 +209,7 @@ _brew_to_completion() case "${COMP_WORDS[cmd_index]}" in # Commands that take a formula - cat|deps|edit|fetch|home|homepage|info|install|log|missing|options|uses|versions) + audit|cat|deps|edit|fetch|home|homepage|info|install|log|missing|options|uses|versions) local ff=$(\ls $(brew --repository)/Library/Formula 2> /dev/null | sed "s/\.rb//g") local af=$(\ls $(brew --repository)/Library/Aliases 2> /dev/null | sed "s/\.rb//g") COMPREPLY=( $(compgen -W "${ff} ${af}" -- ${cur}) ) From 14cd6667b48eaaa8b4d85bded5b7025c2becb38a Mon Sep 17 00:00:00 2001 From: Jack Nagel Date: Sun, 11 Dec 2011 21:59:30 -0600 Subject: [PATCH 4/4] 'CHANGES' is also a meta file Signed-off-by: Jack Nagel --- Library/Homebrew/global.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Library/Homebrew/global.rb b/Library/Homebrew/global.rb index bded211430..fda41c5d32 100644 --- a/Library/Homebrew/global.rb +++ b/Library/Homebrew/global.rb @@ -56,7 +56,7 @@ module Homebrew extend self include FileUtils end -FORMULA_META_FILES = %w[README README.md ChangeLog COPYING LICENSE LICENCE COPYRIGHT AUTHORS] +FORMULA_META_FILES = %w[README README.md ChangeLog CHANGES COPYING LICENSE LICENCE COPYRIGHT AUTHORS] ISSUES_URL = "https://github.com/mxcl/homebrew/wiki/checklist-before-filing-a-new-issue" unless ARGV.include? "--no-compat" or ENV['HOMEBREW_NO_COMPAT']