From f154f4898a31a3243003a06732091beda9086eb6 Mon Sep 17 00:00:00 2001 From: Mike McQuaid Date: Wed, 23 Sep 2015 14:55:22 +0100 Subject: [PATCH] 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 --- Library/Homebrew/cmd/bottle.rb | 19 +++++++++++++++---- 1 file changed, 15 insertions(+), 4 deletions(-) diff --git a/Library/Homebrew/cmd/bottle.rb b/Library/Homebrew/cmd/bottle.rb index 7774a568f9..c63c5ae062 100644 --- a/Library/Homebrew/cmd/bottle.rb +++ b/Library/Homebrew/cmd/bottle.rb @@ -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