bottle: Use Parser to parse args
This commit is contained in:
parent
f37b0bc987
commit
41a05b62fe
@ -34,6 +34,7 @@ require "utils/bottles"
|
|||||||
require "tab"
|
require "tab"
|
||||||
require "keg"
|
require "keg"
|
||||||
require "formula_versions"
|
require "formula_versions"
|
||||||
|
require "cli_parser"
|
||||||
require "utils/inreplace"
|
require "utils/inreplace"
|
||||||
require "erb"
|
require "erb"
|
||||||
require "extend/pathname"
|
require "extend/pathname"
|
||||||
@ -68,6 +69,26 @@ MAXIMUM_STRING_MATCHES = 100
|
|||||||
module Homebrew
|
module Homebrew
|
||||||
module_function
|
module_function
|
||||||
|
|
||||||
|
def bottle
|
||||||
|
@args = Homebrew::CLI::Parser.parse do
|
||||||
|
switch "--merge"
|
||||||
|
switch "-v", "--verbose"
|
||||||
|
switch "--skip-relocation"
|
||||||
|
switch "--force-core-tap"
|
||||||
|
switch "--no-rebuild"
|
||||||
|
switch "--keep-old"
|
||||||
|
switch "--write"
|
||||||
|
switch "--no-commit"
|
||||||
|
switch "--json"
|
||||||
|
flag "--root-url"
|
||||||
|
end
|
||||||
|
|
||||||
|
return merge if @args.merge?
|
||||||
|
ARGV.resolved_formulae.each do |f|
|
||||||
|
bottle_formula f
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
def keg_contain?(string, keg, ignores)
|
def keg_contain?(string, keg, ignores)
|
||||||
@put_string_exists_header, @put_filenames = nil
|
@put_string_exists_header, @put_filenames = nil
|
||||||
|
|
||||||
@ -93,7 +114,7 @@ module Homebrew
|
|||||||
linked_libraries = Keg.file_linked_libraries(file, string)
|
linked_libraries = Keg.file_linked_libraries(file, string)
|
||||||
result ||= !linked_libraries.empty?
|
result ||= !linked_libraries.empty?
|
||||||
|
|
||||||
if ARGV.verbose?
|
if @args.verbose?
|
||||||
print_filename.call(string, file) unless linked_libraries.empty?
|
print_filename.call(string, file) unless linked_libraries.empty?
|
||||||
linked_libraries.each do |lib|
|
linked_libraries.each do |lib|
|
||||||
puts " #{Tty.bold}-->#{Tty.reset} links to #{lib}"
|
puts " #{Tty.bold}-->#{Tty.reset} links to #{lib}"
|
||||||
@ -116,7 +137,7 @@ module Homebrew
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
next unless ARGV.verbose? && !text_matches.empty?
|
next unless @args.verbose? && !text_matches.empty?
|
||||||
print_filename.call(string, file)
|
print_filename.call(string, file)
|
||||||
text_matches.first(MAXIMUM_STRING_MATCHES).each do |match, offset|
|
text_matches.first(MAXIMUM_STRING_MATCHES).each do |match, offset|
|
||||||
puts " #{Tty.bold}-->#{Tty.reset} match '#{match}' at offset #{Tty.bold}0x#{offset}#{Tty.reset}"
|
puts " #{Tty.bold}-->#{Tty.reset} match '#{match}' at offset #{Tty.bold}0x#{offset}#{Tty.reset}"
|
||||||
@ -137,7 +158,7 @@ module Homebrew
|
|||||||
absolute_symlinks_start_with_string << pn if link.to_s.start_with?(string)
|
absolute_symlinks_start_with_string << pn if link.to_s.start_with?(string)
|
||||||
end
|
end
|
||||||
|
|
||||||
if ARGV.verbose?
|
if @args.verbose?
|
||||||
unless absolute_symlinks_start_with_string.empty?
|
unless absolute_symlinks_start_with_string.empty?
|
||||||
opoo "Absolute symlink starting with #{string}:"
|
opoo "Absolute symlink starting with #{string}:"
|
||||||
absolute_symlinks_start_with_string.each do |pn|
|
absolute_symlinks_start_with_string.each do |pn|
|
||||||
@ -160,7 +181,7 @@ module Homebrew
|
|||||||
end
|
end
|
||||||
|
|
||||||
unless tap = f.tap
|
unless tap = f.tap
|
||||||
unless ARGV.include?("--force-core-tap")
|
unless @args.force_core_tap?
|
||||||
return ofail "Formula not from core or any taps: #{f.full_name}"
|
return ofail "Formula not from core or any taps: #{f.full_name}"
|
||||||
end
|
end
|
||||||
|
|
||||||
@ -179,9 +200,9 @@ module Homebrew
|
|||||||
|
|
||||||
return ofail "Formula has no stable version: #{f.full_name}" unless f.stable
|
return ofail "Formula has no stable version: #{f.full_name}" unless f.stable
|
||||||
|
|
||||||
if ARGV.include?("--no-rebuild") || !f.tap
|
if @args.no_rebuild? || !f.tap
|
||||||
rebuild = 0
|
rebuild = 0
|
||||||
elsif ARGV.include? "--keep-old"
|
elsif @args.keep_old?
|
||||||
rebuild = f.bottle_specification.rebuild
|
rebuild = f.bottle_specification.rebuild
|
||||||
else
|
else
|
||||||
ohai "Determining #{f.full_name} bottle rebuild..."
|
ohai "Determining #{f.full_name} bottle rebuild..."
|
||||||
@ -214,7 +235,7 @@ module Homebrew
|
|||||||
begin
|
begin
|
||||||
keg.delete_pyc_files!
|
keg.delete_pyc_files!
|
||||||
|
|
||||||
unless ARGV.include? "--skip-relocation"
|
unless @args.skip_relocation?
|
||||||
changed_files = keg.replace_locations_with_placeholders
|
changed_files = keg.replace_locations_with_placeholders
|
||||||
end
|
end
|
||||||
|
|
||||||
@ -265,7 +286,7 @@ module Homebrew
|
|||||||
end
|
end
|
||||||
|
|
||||||
relocatable = true
|
relocatable = true
|
||||||
if ARGV.include? "--skip-relocation"
|
if @args.skip_relocation?
|
||||||
skip_relocation = true
|
skip_relocation = true
|
||||||
else
|
else
|
||||||
relocatable = false if keg_contain?(prefix_check, keg, ignores)
|
relocatable = false if keg_contain?(prefix_check, keg, ignores)
|
||||||
@ -278,23 +299,21 @@ module Homebrew
|
|||||||
end
|
end
|
||||||
skip_relocation = relocatable && !keg.require_relocation?
|
skip_relocation = relocatable && !keg.require_relocation?
|
||||||
end
|
end
|
||||||
puts if !relocatable && ARGV.verbose?
|
puts if !relocatable && @args.verbose?
|
||||||
rescue Interrupt
|
rescue Interrupt
|
||||||
ignore_interrupts { bottle_path.unlink if bottle_path.exist? }
|
ignore_interrupts { bottle_path.unlink if bottle_path.exist? }
|
||||||
raise
|
raise
|
||||||
ensure
|
ensure
|
||||||
ignore_interrupts do
|
ignore_interrupts do
|
||||||
original_tab&.write
|
original_tab&.write
|
||||||
unless ARGV.include? "--skip-relocation"
|
unless @args.skip_relocation?
|
||||||
keg.replace_placeholders_with_locations changed_files
|
keg.replace_placeholders_with_locations changed_files
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
root_url = ARGV.value("root-url")
|
root_url = @args.root_url
|
||||||
# Use underscored version for legacy reasons. Remove at some point.
|
|
||||||
root_url ||= ARGV.value("root_url")
|
|
||||||
|
|
||||||
bottle = BottleSpecification.new
|
bottle = BottleSpecification.new
|
||||||
bottle.tap = tap
|
bottle.tap = tap
|
||||||
@ -314,7 +333,7 @@ module Homebrew
|
|||||||
bottle.sha256 sha256 => Utils::Bottles.tag
|
bottle.sha256 sha256 => Utils::Bottles.tag
|
||||||
|
|
||||||
old_spec = f.bottle_specification
|
old_spec = f.bottle_specification
|
||||||
if ARGV.include?("--keep-old") && !old_spec.checksums.empty?
|
if @args.keep_old? && !old_spec.checksums.empty?
|
||||||
mismatches = [:root_url, :prefix, :cellar, :rebuild].reject do |key|
|
mismatches = [:root_url, :prefix, :cellar, :rebuild].reject do |key|
|
||||||
old_spec.send(key) == bottle.send(key)
|
old_spec.send(key) == bottle.send(key)
|
||||||
end
|
end
|
||||||
@ -340,7 +359,7 @@ module Homebrew
|
|||||||
puts "./#{filename}"
|
puts "./#{filename}"
|
||||||
puts output
|
puts output
|
||||||
|
|
||||||
return unless ARGV.include? "--json"
|
return unless @args.json?
|
||||||
json = {
|
json = {
|
||||||
f.full_name => {
|
f.full_name => {
|
||||||
"formula" => {
|
"formula" => {
|
||||||
@ -371,7 +390,7 @@ module Homebrew
|
|||||||
end
|
end
|
||||||
|
|
||||||
def merge
|
def merge
|
||||||
write = ARGV.include? "--write"
|
write = @args.write?
|
||||||
|
|
||||||
bottles_hash = ARGV.named.reduce({}) do |hash, json_file|
|
bottles_hash = ARGV.named.reduce({}) do |hash, json_file|
|
||||||
deep_merge_hashes hash, JSON.parse(IO.read(json_file))
|
deep_merge_hashes hash, JSON.parse(IO.read(json_file))
|
||||||
@ -400,7 +419,7 @@ module Homebrew
|
|||||||
Utils::Inreplace.inreplace(path) do |s|
|
Utils::Inreplace.inreplace(path) do |s|
|
||||||
if s.include? "bottle do"
|
if s.include? "bottle do"
|
||||||
update_or_add = "update"
|
update_or_add = "update"
|
||||||
if ARGV.include? "--keep-old"
|
if @args.keep_old?
|
||||||
mismatches = []
|
mismatches = []
|
||||||
bottle_block_contents = s[/ bottle do(.+?)end\n/m, 1]
|
bottle_block_contents = s[/ bottle do(.+?)end\n/m, 1]
|
||||||
bottle_block_contents.lines.each do |line|
|
bottle_block_contents.lines.each do |line|
|
||||||
@ -443,7 +462,7 @@ module Homebrew
|
|||||||
string = s.sub!(/ bottle do.+?end\n/m, output)
|
string = s.sub!(/ bottle do.+?end\n/m, output)
|
||||||
odie "Bottle block update failed!" unless string
|
odie "Bottle block update failed!" unless string
|
||||||
else
|
else
|
||||||
if ARGV.include? "--keep-old"
|
if @args.keep_old?
|
||||||
odie "--keep-old was passed but there was no existing bottle block!"
|
odie "--keep-old was passed but there was no existing bottle block!"
|
||||||
end
|
end
|
||||||
puts output
|
puts output
|
||||||
@ -472,7 +491,7 @@ module Homebrew
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
unless ARGV.include? "--no-commit"
|
unless @args.no_commit?
|
||||||
if ENV["HOMEBREW_GIT_NAME"]
|
if ENV["HOMEBREW_GIT_NAME"]
|
||||||
ENV["GIT_AUTHOR_NAME"] =
|
ENV["GIT_AUTHOR_NAME"] =
|
||||||
ENV["GIT_COMMITTER_NAME"] =
|
ENV["GIT_COMMITTER_NAME"] =
|
||||||
@ -498,14 +517,4 @@ module Homebrew
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
def bottle
|
|
||||||
if ARGV.include? "--merge"
|
|
||||||
merge
|
|
||||||
else
|
|
||||||
ARGV.resolved_formulae.each do |f|
|
|
||||||
bottle_formula f
|
|
||||||
end
|
|
||||||
end
|
|
||||||
end
|
|
||||||
end
|
end
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user