Use extend/OS mechanism for grep args

This commit is contained in:
Tim D. Smith 2017-04-02 09:04:49 -07:00
parent d0feae0632
commit 2f4eaf26a0
2 changed files with 13 additions and 6 deletions

View File

@ -131,6 +131,12 @@ class Keg
mach_o_files mach_o_files
end end
def recursive_fgrep_args
# Don't recurse into symlinks; the man page says this is the default, but
# it's wrong. -O is a BSD-grep-only option.
"-lrO"
end
def self.file_linked_libraries(file, string) def self.file_linked_libraries(file, string)
# Check dynamic library linkage. Importantly, do not perform for static # Check dynamic library linkage. Importantly, do not perform for static
# libraries, which will falsely report "linkage" to themselves. # libraries, which will falsely report "linkage" to themselves.

View File

@ -98,13 +98,14 @@ class Keg
[] []
end end
def recursive_fgrep_args
# for GNU grep; overridden for BSD grep on OS X
"-lr"
end
alias generic_recursive_fgrep_args recursive_fgrep_args
def each_unique_file_matching(string) def each_unique_file_matching(string)
bsd = `/usr/bin/fgrep -V`.include?("BSD grep") Utils.popen_read("/usr/bin/fgrep", recursive_fgrep_args, string, to_s) do |io|
grep_args = "-lr"
# Don't recurse into symlinks; the man page says this is the default, but
# it's wrong.
grep_args += "O" if bsd
Utils.popen_read("/usr/bin/fgrep", grep_args, string, to_s) do |io|
hardlinks = Set.new hardlinks = Set.new
until io.eof? until io.eof?