bottle: output maximum number of strings matches.

`brew bottle --verbose` outputs all the matches for a string found
in the files inside the Cellar. Instead of outputting all of these just
output the first 100.

Closes Homebrew/homebrew#44266.

Signed-off-by: Mike McQuaid <mike@mikemcquaid.com>
This commit is contained in:
Mike McQuaid 2015-09-23 14:55:22 +01:00
parent 322a93bce0
commit f154f4898a

View File

@ -32,6 +32,8 @@ BOTTLE_ERB = <<-EOS
end
EOS
MAXIMUM_STRING_MATCHES = 100
module Homebrew
def keg_contains(string, keg, ignores)
@put_string_exists_header, @put_filenames = nil
@ -72,6 +74,8 @@ module Homebrew
end
end
text_matches = []
# Use strings to search through the file for each string
Utils.popen_read("strings", "-t", "x", "-", file.to_s) do |io|
until io.eof?
@ -82,11 +86,18 @@ module Homebrew
next if linked_libraries.include? match # Don't bother reporting a string if it was found by otool
result = true
text_matches << [match, offset]
end
end
if ARGV.verbose?
print_filename string, file
puts " #{Tty.gray}-->#{Tty.reset} match '#{match}' at offset #{Tty.em}0x#{offset}#{Tty.reset}"
end
if ARGV.verbose? && text_matches.any?
print_filename string, file
text_matches.first(MAXIMUM_STRING_MATCHES).each do |match, offset|
puts " #{Tty.gray}-->#{Tty.reset} match '#{match}' at offset #{Tty.em}0x#{offset}#{Tty.reset}"
end
if text_matches.size > MAXIMUM_STRING_MATCHES
puts "Only the first #{MAXIMUM_STRING_MATCHES} matches were output"
end
end
end