brew/Library/Homebrew/cmd/unpack.rb

59 lines
1.6 KiB
Ruby
Raw Normal View History

2016-04-08 16:28:43 +02:00
#: * `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.
2016-04-08 16:28:43 +02:00
#:
#: If `--patch` is passed, patches for <formulae> will be applied to the
#: unpacked source.
#:
2017-04-02 10:14:21 +01:00
#: If `--git` (or `-g`) is passed, a Git repository will be initialized in the unpacked
2016-04-08 16:28:43 +02:00
#: source. This is useful for creating patches for the software.
2014-05-17 17:12:40 -05:00
require "stringio"
require "formula"
module Homebrew
2016-09-26 01:44:51 +02:00
module_function
2014-05-17 17:12:40 -05:00
def unpack
formulae = ARGV.formulae
raise FormulaUnspecifiedError if formulae.empty?
if dir = ARGV.value("destdir")
unpack_dir = Pathname.new(dir).expand_path
2014-05-17 17:12:40 -05:00
unpack_dir.mkpath
else
unpack_dir = Pathname.pwd
end
raise "Cannot write to #{unpack_dir}" unless unpack_dir.writable_real?
formulae.each do |f|
2017-06-01 16:06:51 +02:00
stage_dir = unpack_dir/"#{f.name}-#{f.version}"
2014-05-17 17:12:40 -05:00
if stage_dir.exist?
raise "Destination #{stage_dir} already exists!" unless ARGV.force?
2018-09-17 02:45:00 +02:00
2014-05-17 17:12:40 -05:00
rm_rf stage_dir
end
2018-02-09 11:31:51 +09:00
oh1 "Unpacking #{Formatter.identifier(f.full_name)} to: #{stage_dir}"
2014-05-17 17:12:40 -05:00
ENV["VERBOSE"] = "1" # show messages about tar
f.brew do
f.patch if ARGV.flag?("--patch")
cp_r getwd, stage_dir, preserve: true
end
ENV["VERBOSE"] = nil
2014-05-17 17:12:40 -05:00
2016-09-10 10:24:57 +01:00
next unless ARGV.git?
2018-09-17 02:45:00 +02:00
2016-09-10 10:24:57 +01:00
ohai "Setting up git repository"
cd stage_dir
system "git", "init", "-q"
system "git", "add", "-A"
system "git", "commit", "-q", "-m", "brew-unpack"
2014-05-17 17:12:40 -05:00
end
end
end