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