diff options
| author | Jack Nagel | 2014-05-17 17:12:40 -0500 |
|---|---|---|
| committer | Jack Nagel | 2014-05-17 17:12:40 -0500 |
| commit | fbf1c189a78370f30d8b6ebea1aa208a95312a25 (patch) | |
| tree | a39ebaba2a51c84d0af92842dcd89df1647eca2d | |
| parent | 69087812647a13564c704387e9c0b6dbf5e3614e (diff) | |
| download | brew-fbf1c189a78370f30d8b6ebea1aa208a95312a25.tar.bz2 | |
Move brew-unpack to core
| -rw-r--r-- | Library/Contributions/brew_bash_completion.sh | 12 | ||||
| -rwxr-xr-x | Library/Contributions/cmd/brew-unpack.rb | 100 | ||||
| -rw-r--r-- | Library/Contributions/manpages/brew.1.md | 12 | ||||
| -rw-r--r-- | Library/Homebrew/cmd/unpack.rb | 74 | ||||
| -rw-r--r-- | share/man/man1/brew.1 | 12 |
5 files changed, 110 insertions, 100 deletions
diff --git a/Library/Contributions/brew_bash_completion.sh b/Library/Contributions/brew_bash_completion.sh index 7d3fc595f..6f97935f0 100644 --- a/Library/Contributions/brew_bash_completion.sh +++ b/Library/Contributions/brew_bash_completion.sh @@ -370,6 +370,17 @@ _brew_uninstall () __brew_complete_installed } +_brew_unpack () +{ + local cur="${COMP_WORDS[COMP_CWORD]}" + case "$cur" in + --*) + __brewcomp "--git --patch --destdir=" + return + ;; + esac + __brew_complete_formulae +} _brew_update () { local cur="${COMP_WORDS[COMP_CWORD]}" @@ -520,6 +531,7 @@ _brew () switch) _brew_switch ;; tap) _brew_complete_tap ;; uninstall|remove|rm) _brew_uninstall ;; + unpack) _brew_unpack ;; unpin) __brew_complete_formulae ;; untap) __brew_complete_tapped ;; update) _brew_update ;; diff --git a/Library/Contributions/cmd/brew-unpack.rb b/Library/Contributions/cmd/brew-unpack.rb deleted file mode 100755 index 4ff19b0e1..000000000 --- a/Library/Contributions/cmd/brew-unpack.rb +++ /dev/null @@ -1,100 +0,0 @@ -require 'formula' - -require 'stringio' -module ScriptDataReader - # This module contains a method for extracting the contents of DATA from a - # Ruby file other than the script containing the currently executing - # function. Many thanks to Glenn Jackman's Stackoverflow answer which - # provided this code: - # - # http://stackoverflow.com/questions/2156629/can-i-access-the-data-from-a-required-script-in-ruby/2157556#2157556 - def self.load(filename) - data = StringIO.new - File.open(filename) do |f| - begin - line = f.gets - end until line.nil? or line.match(/^__END__$/) - while line = f.gets - data << line - end - end - data.rewind - data - end -end - -module UnpackPatch - def patch - return unless ARGV.flag? "--patch" - - begin - old_verbose = $VERBOSE - $VERBOSE = nil - Object.const_set "DATA", ScriptDataReader.load(path) - ensure - $VERBOSE = old_verbose - end - - super - end -end - -module Homebrew extend self - def unpack_usage; <<-EOS.undent - Usage: brew unpack [-pg] [--destdir=path/to/extract/in] <formulae ...> - - Unpack formulae source code for inspection. - - Formulae archives will be extracted to subfolders inside the current working - directory or a directory specified by `--destdir`. If the `-p` option is - supplied, patches will also be downloaded and applied. If the `-g` option is - specified a git repository is created and all files added so that you can diff - changes. - EOS - end - - def unpack - abort unpack_usage if ARGV.empty? - - formulae = ARGV.formulae - raise FormulaUnspecifiedError if formulae.empty? - - if (dir = ARGV.value('destdir')).nil? - unpack_dir = Pathname.pwd - else - unpack_dir = Pathname.new(dir) - unpack_dir.mkpath unless unpack_dir.exist? - end - - raise "Cannot write to #{unpack_dir}" unless unpack_dir.writable_real? - - formulae.each do |f| - f.extend(UnpackPatch) - - # Create a nice name for the stage folder. - stage_dir = unpack_dir + [f.name, f.version].join('-') - - if stage_dir.exist? - raise "Destination #{stage_dir} already exists!" unless ARGV.force? - rm_rf stage_dir - end - - oh1 "Unpacking #{f.name} to: #{stage_dir}" - ENV['VERBOSE'] = '1' # show messages about tar - f.brew { cp_r getwd, stage_dir } - ENV['VERBOSE'] = nil - - if ARGV.switch? 'g' - ohai "Setting up git repository" - cd stage_dir - system "git", "init", "-q" - system "git", "add", "-A" - system "git", "commit", "-q", "-m", "brew-unpack" - end - end - end -end - -# Here is the actual code that gets run when `brew` loads this external -# command. -Homebrew.unpack diff --git a/Library/Contributions/manpages/brew.1.md b/Library/Contributions/manpages/brew.1.md index 9177fffc2..22d8dbf8f 100644 --- a/Library/Contributions/manpages/brew.1.md +++ b/Library/Contributions/manpages/brew.1.md @@ -352,6 +352,18 @@ Note that these flags should only appear after a command. * `unlinkapps [--local]`: Removes links created by `brew linkapps`. + * `unpack [--git|--patch] [--destdir=<path>]` <formulae>: + + Unpack the source files for <formulae> into subdirectories of the current + working directory. If `--destdir=<path>` is given, the subdirectories will + be created in the directory named by `<path>` instead. + + If `--patch` is passed, patches for <formulae> will be applied to the + unpacked source. + + If `--git` is passed, a Git repository will be initalized in the unpacked + source. This is useful for creating patches for the software. + * `unpin` <formulae>: Unpin <formulae>, allowing them to be upgraded by `brew upgrade`. See also `pin`. diff --git a/Library/Homebrew/cmd/unpack.rb b/Library/Homebrew/cmd/unpack.rb new file mode 100644 index 000000000..ec9b0a126 --- /dev/null +++ b/Library/Homebrew/cmd/unpack.rb @@ -0,0 +1,74 @@ +require "stringio" +require "formula" + +module Homebrew + extend self + + module DATALoader + # Original code from http://stackoverflow.com/a/2157556/371237 + def self.load(path) + data = StringIO.new + path.open("r") do |f| + begin + line = f.gets + end until line.nil? || /^__END__$/ === line + data << line while line = f.gets + end + data.rewind + data + end + end + + module UnpackPatch + def patch + return unless ARGV.flag? "--patch" + + begin + old_verbose, $VERBOSE = $VERBOSE, nil + Object.const_set "DATA", DATALoader.load(path) + ensure + $VERBOSE = old_verbose + end + + super + end + end + + def unpack + formulae = ARGV.formulae + raise FormulaUnspecifiedError if formulae.empty? + + if dir = ARGV.value("destdir") + unpack_dir = Pathname.new(dir) + unpack_dir.mkpath + else + unpack_dir = Pathname.pwd + end + + raise "Cannot write to #{unpack_dir}" unless unpack_dir.writable_real? + + formulae.each do |f| + f.extend(UnpackPatch) + stage_dir = unpack_dir.join("#{f.name}-#{f.version}") + + if stage_dir.exist? + raise "Destination #{stage_dir} already exists!" unless ARGV.force? + rm_rf stage_dir + end + + oh1 "Unpacking #{f.name} to: #{stage_dir}" + + ENV['VERBOSE'] = '1' # show messages about tar + f.brew { cp_r getwd, stage_dir } + ENV['VERBOSE'] = nil + + if ARGV.flag? "--git" + ohai "Setting up git repository" + cd stage_dir + system "git", "init", "-q" + system "git", "add", "-A" + system "git", "commit", "-q", "-m", "brew-unpack" + end + end + end +end diff --git a/share/man/man1/brew.1 b/share/man/man1/brew.1 index de976b5e4..9c8aeffa1 100644 --- a/share/man/man1/brew.1 +++ b/share/man/man1/brew.1 @@ -369,6 +369,18 @@ Remove symlinks for \fIformula\fR from the Homebrew prefix\. This can be useful Removes links created by \fBbrew linkapps\fR\. . .TP +\fBunpack [\-\-git|\-\-patch] [\-\-destdir=<path>]\fR \fIformulae\fR: +. +.IP +Unpack the source files for \fIformulae\fR into subdirectories of the current working directory\. If \fB\-\-destdir=<path>\fR is given, the subdirectories will be created in the directory named by \fB<path>\fR instead\. +. +.IP +If \fB\-\-patch\fR is passed, patches for \fIformulae\fR will be applied to the unpacked source\. +. +.IP +If \fB\-\-git\fR is passed, a Git repository will be initalized in the unpacked source\. This is useful for creating patches for the software\. +. +.TP \fBunpin\fR \fIformulae\fR Unpin \fIformulae\fR, allowing them to be upgraded by \fBbrew upgrade\fR\. See also \fBpin\fR\. . |
