Merge pull request #8052 from maxim-belkin/missing_libs_follow_up

formula.rb: update 'missing libraries' feature
This commit is contained in:
Maxim Belkin 2020-07-22 11:31:42 -05:00 committed by GitHub
commit bb90afbfff
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 34 additions and 32 deletions

View File

@ -7,23 +7,6 @@ class Formula
"#{name}.so#{"." unless version.nil?}#{version}" "#{name}.so#{"." unless version.nil?}#{version}"
end end
undef allowed_missing_lib?
def allowed_missing_lib?(lib)
# lib: Full path to the missing library
# Ex.: /home/linuxbrew/.linuxbrew/lib/libsomething.so.1
# x - Name of or a pattern for a library, linkage to which is allowed to be missing.
# Ex. 1: "libONE.so.1"
# Ex. 2: %r{(libONE|libTWO)\.so}
self.class.allowed_missing_libraries.any? do |x|
case x
when Regexp
x.match? lib
when String
lib.include? x
end
end
end
class << self class << self
undef on_linux undef on_linux
@ -31,9 +14,15 @@ class Formula
yield yield
end end
undef ignore_missing_libraries
def ignore_missing_libraries(*libs) def ignore_missing_libraries(*libs)
libs.flatten! libraries = libs.flatten
allowed_missing_libraries.merge(libs) if libraries.any? { |x| !x.is_a?(String) && !x.is_a?(Regexp) }
raise FormulaSpecificationError, "#{__method__} can handle Strings and Regular Expressions only"
end
allowed_missing_libraries.merge(libraries)
end end
# @private # @private

View File

@ -1131,13 +1131,6 @@ class Formula
end end
end end
# Whether this {Formula} is allowed to have a broken linkage to specified library.
# Defaults to false.
# @return [Boolean]
def allowed_missing_lib?(*)
false
end
# Whether this {Formula} is deprecated (i.e. warns on installation). # Whether this {Formula} is deprecated (i.e. warns on installation).
# Defaults to false. # Defaults to false.
# @method deprecated? # @method deprecated?
@ -2763,6 +2756,10 @@ class Formula
def link_overwrite_paths def link_overwrite_paths
@link_overwrite_paths ||= Set.new @link_overwrite_paths ||= Set.new
end end
def ignore_missing_libraries(*)
raise FormulaSpecificationError, "#{__method__} is available on Linux only"
end
end end
end end

View File

@ -15,6 +15,7 @@ class LinkageChecker
@system_dylibs = Set.new @system_dylibs = Set.new
@broken_dylibs = Set.new @broken_dylibs = Set.new
@unexpected_broken_dylibs = nil
@variable_dylibs = Set.new @variable_dylibs = Set.new
@brewed_dylibs = Hash.new { |h, k| h[k] = Set.new } @brewed_dylibs = Hash.new { |h, k| h[k] = Set.new }
@reverse_links = Hash.new { |h, k| h[k] = Set.new } @reverse_links = Hash.new { |h, k| h[k] = Set.new }
@ -62,7 +63,7 @@ class LinkageChecker
if @broken_dylibs.empty? if @broken_dylibs.empty?
puts "No broken library linkage detected" puts "No broken library linkage detected"
elsif unexpected_broken_libs.empty? elsif unexpected_broken_dylibs.empty?
puts "No unexpected broken library linkage detected." puts "No unexpected broken library linkage detected."
else else
puts "Broken library linkage detected" puts "Broken library linkage detected"
@ -71,17 +72,32 @@ class LinkageChecker
def broken_library_linkage? def broken_library_linkage?
issues = [@broken_deps, @unwanted_system_dylibs, @version_conflict_deps] issues = [@broken_deps, @unwanted_system_dylibs, @version_conflict_deps]
[issues, unexpected_broken_libs].flatten.any?(&:present?) [issues, unexpected_broken_dylibs].flatten.any?(&:present?)
end end
def unexpected_broken_libs def unexpected_broken_dylibs
@broken_dylibs.reject { |lib| @formula.allowed_missing_lib? lib } return @unexpected_broken_dylibs if @unexpected_broken_dylibs
@unexpected_broken_dylibs = @broken_dylibs.reject do |broken_lib|
@formula.class.allowed_missing_libraries.any? do |allowed_missing_lib|
case allowed_missing_lib
when Regexp
allowed_missing_lib.match? broken_lib
when String
broken_lib.include? allowed_missing_lib
end
end
end
end end
def broken_dylibs_with_expectations def broken_dylibs_with_expectations
output = {} output = {}
@broken_dylibs.each do |lib| @broken_dylibs.each do |broken_lib|
output[lib] = (unexpected_broken_libs.include? lib) ? ["unexpected"] : ["expected"] output[broken_lib] = if unexpected_broken_dylibs.include? broken_lib
["unexpected"]
else
["expected"]
end
end end
output output
end end