brew/Library/Homebrew/cmd/unpack.rb

75 lines
1.9 KiB
Ruby
Raw Normal View History

# frozen_string_literal: true
2014-05-17 17:12:40 -05:00
require "stringio"
require "formula"
2019-04-17 18:25:08 +09:00
require "cli/parser"
2014-05-17 17:12:40 -05:00
module Homebrew
2016-09-26 01:44:51 +02:00
module_function
2018-11-11 18:00:11 +05:30
def unpack_args
Homebrew::CLI::Parser.new do
usage_banner <<~EOS
`unpack` [<options>] <formula>
2018-11-11 18:00:11 +05:30
Unpack the source files for <formula> into subdirectories of the current
2018-11-11 18:00:11 +05:30
working directory.
EOS
flag "--destdir=",
description: "Create subdirectories in the directory named by <path> instead."
switch "--patch",
description: "Patches for <formula> will be applied to the unpacked source."
2018-11-11 18:00:11 +05:30
switch "-g", "--git",
description: "Initialise a Git repository in the unpacked source. This is useful for creating "\
2018-11-11 18:00:11 +05:30
"patches for the software."
switch :force
switch :verbose
switch :debug
conflicts "--git", "--patch"
2018-11-11 18:00:11 +05:30
end
end
2014-05-17 17:12:40 -05:00
def unpack
2018-11-11 18:00:11 +05:30
unpack_args.parse
2014-05-17 17:12:40 -05:00
formulae = ARGV.formulae
raise FormulaUnspecifiedError if formulae.empty?
2018-11-11 18:00:11 +05:30
if dir = args.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?
2018-11-11 18:00:11 +05:30
raise "Destination #{stage_dir} already exists!" unless args.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
2018-11-11 18:00:11 +05:30
f.patch if args.patch?
cp_r getwd, stage_dir, preserve: true
end
ENV["VERBOSE"] = nil
2014-05-17 17:12:40 -05:00
2018-11-11 18:00:11 +05:30
next unless args.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