From 7080ad5ebc58a472c6159c3218c273ee047a3d39 Mon Sep 17 00:00:00 2001 From: Maxim Belkin Date: Tue, 21 Jul 2020 12:50:22 +0000 Subject: [PATCH 1/8] formula.rb: update missing libs feature 1. Raise an exception on macOS. 2. Verify that the missing libraries are specified either as Strings or Regular Expressions. Signed-off-by: Maxim Belkin --- Library/Homebrew/extend/os/linux/formula.rb | 12 +++++++++--- Library/Homebrew/formula.rb | 4 ++++ 2 files changed, 13 insertions(+), 3 deletions(-) diff --git a/Library/Homebrew/extend/os/linux/formula.rb b/Library/Homebrew/extend/os/linux/formula.rb index 12b28db2a0..f633b52416 100644 --- a/Library/Homebrew/extend/os/linux/formula.rb +++ b/Library/Homebrew/extend/os/linux/formula.rb @@ -19,7 +19,7 @@ class Formula when Regexp x.match? lib when String - lib.include? x + lib.to_s.include? x end end end @@ -31,9 +31,15 @@ class Formula yield end + undef ignore_missing_libraries + def ignore_missing_libraries(*libs) - libs.flatten! - allowed_missing_libraries.merge(libs) + libraries = libs.flatten + unless libraries.all? { |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 # @private diff --git a/Library/Homebrew/formula.rb b/Library/Homebrew/formula.rb index 06084522f6..834b6ab4ea 100644 --- a/Library/Homebrew/formula.rb +++ b/Library/Homebrew/formula.rb @@ -2763,6 +2763,10 @@ class Formula def link_overwrite_paths @link_overwrite_paths ||= Set.new end + + def ignore_missing_libraries(*) + raise FormulaSpecificationError, "#{__method__} is available on Linux only" + end end end From 28227bd26b592d3c4ecb669a662750200938d734 Mon Sep 17 00:00:00 2001 From: Maxim Belkin Date: Tue, 21 Jul 2020 14:11:00 +0000 Subject: [PATCH 2/8] linkage_checker.rb: replace conditional assignment with an if-else --- Library/Homebrew/linkage_checker.rb | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/Library/Homebrew/linkage_checker.rb b/Library/Homebrew/linkage_checker.rb index a0dbfeadef..372cddb2a2 100644 --- a/Library/Homebrew/linkage_checker.rb +++ b/Library/Homebrew/linkage_checker.rb @@ -81,7 +81,11 @@ class LinkageChecker def broken_dylibs_with_expectations output = {} @broken_dylibs.each do |lib| - output[lib] = (unexpected_broken_libs.include? lib) ? ["unexpected"] : ["expected"] + output[lib] = if unexpected_broken_libs.include? lib + ["unexpected"] + else + ["expected"] + end end output end From 68ebf8866ab14334aa6aab8d0672d804c632035d Mon Sep 17 00:00:00 2001 From: Maxim Belkin Date: Tue, 21 Jul 2020 15:40:27 +0000 Subject: [PATCH 3/8] extend/os/linux/formula.rb: allowed_missing_lib: check input class --- Library/Homebrew/extend/os/linux/formula.rb | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/Library/Homebrew/extend/os/linux/formula.rb b/Library/Homebrew/extend/os/linux/formula.rb index f633b52416..a826075a0d 100644 --- a/Library/Homebrew/extend/os/linux/formula.rb +++ b/Library/Homebrew/extend/os/linux/formula.rb @@ -9,6 +9,8 @@ class Formula undef allowed_missing_lib? def allowed_missing_lib?(lib) + raise TypeError "Library must be a string; got a #{lib.class} (#{lib})" unless lib.is_a? String + # 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. @@ -19,7 +21,7 @@ class Formula when Regexp x.match? lib when String - lib.to_s.include? x + lib.include? x end end end From 2ffb9fd0fc4c70faa927b658851bedbefa98422b Mon Sep 17 00:00:00 2001 From: Maxim Belkin Date: Tue, 21 Jul 2020 10:43:28 -0500 Subject: [PATCH 4/8] extend/os/linux/formula.rb: ignore_missing_libraries: change unless to if Change ```rb unless libraries.all? { |x| x.is_a?(String) || x.is_a?(Regexp) } ``` to ```rb if libraries.any? { |x| !x.is_a?(String) && !x.is_a?(Regexp) } ``` Co-authored-by: Mike McQuaid --- Library/Homebrew/extend/os/linux/formula.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Library/Homebrew/extend/os/linux/formula.rb b/Library/Homebrew/extend/os/linux/formula.rb index a826075a0d..7419609e8f 100644 --- a/Library/Homebrew/extend/os/linux/formula.rb +++ b/Library/Homebrew/extend/os/linux/formula.rb @@ -37,7 +37,7 @@ class Formula def ignore_missing_libraries(*libs) libraries = libs.flatten - unless libraries.all? { |x| x.is_a?(String) || x.is_a?(Regexp) } + if libraries.any? { |x| !x.is_a?(String) && !x.is_a?(Regexp) } raise FormulaSpecificationError, "#{__method__} can handle Strings and Regular Expressions only" end From 73495c4959fb614f7cb434b482599fb8821fb824 Mon Sep 17 00:00:00 2001 From: Maxim Belkin Date: Tue, 21 Jul 2020 15:47:59 +0000 Subject: [PATCH 5/8] formula.rb [extend/Linux]: add missing comma --- Library/Homebrew/extend/os/linux/formula.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Library/Homebrew/extend/os/linux/formula.rb b/Library/Homebrew/extend/os/linux/formula.rb index 7419609e8f..f060c1590d 100644 --- a/Library/Homebrew/extend/os/linux/formula.rb +++ b/Library/Homebrew/extend/os/linux/formula.rb @@ -9,7 +9,7 @@ class Formula undef allowed_missing_lib? def allowed_missing_lib?(lib) - raise TypeError "Library must be a string; got a #{lib.class} (#{lib})" unless lib.is_a? String + raise TypeError, "Library must be a string; got a #{lib.class} (#{lib})" unless lib.is_a? String # lib: Full path to the missing library # Ex.: /home/linuxbrew/.linuxbrew/lib/libsomething.so.1 From 1b8c32c7160bd14224d1945205f62815eda3633b Mon Sep 17 00:00:00 2001 From: Maxim Belkin Date: Wed, 22 Jul 2020 14:30:52 +0000 Subject: [PATCH 6/8] Move allowed_missing_libs? to linkage_checker.rb. Optimize 'unexpected_broken_dylibs' --- Library/Homebrew/extend/os/linux/formula.rb | 19 ------------- Library/Homebrew/formula.rb | 7 ----- Library/Homebrew/linkage_checker.rb | 31 +++++++++++++++++---- 3 files changed, 26 insertions(+), 31 deletions(-) diff --git a/Library/Homebrew/extend/os/linux/formula.rb b/Library/Homebrew/extend/os/linux/formula.rb index f060c1590d..0816edbb87 100644 --- a/Library/Homebrew/extend/os/linux/formula.rb +++ b/Library/Homebrew/extend/os/linux/formula.rb @@ -7,25 +7,6 @@ class Formula "#{name}.so#{"." unless version.nil?}#{version}" end - undef allowed_missing_lib? - def allowed_missing_lib?(lib) - raise TypeError, "Library must be a string; got a #{lib.class} (#{lib})" unless lib.is_a? String - - # 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 undef on_linux diff --git a/Library/Homebrew/formula.rb b/Library/Homebrew/formula.rb index 834b6ab4ea..6114a8896c 100644 --- a/Library/Homebrew/formula.rb +++ b/Library/Homebrew/formula.rb @@ -1131,13 +1131,6 @@ class Formula 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). # Defaults to false. # @method deprecated? diff --git a/Library/Homebrew/linkage_checker.rb b/Library/Homebrew/linkage_checker.rb index 372cddb2a2..31b6c0e3cc 100644 --- a/Library/Homebrew/linkage_checker.rb +++ b/Library/Homebrew/linkage_checker.rb @@ -15,6 +15,7 @@ class LinkageChecker @system_dylibs = Set.new @broken_dylibs = Set.new + @unexpected_broken_dylibs = nil @variable_dylibs = Set.new @brewed_dylibs = 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? puts "No broken library linkage detected" - elsif unexpected_broken_libs.empty? + elsif unexpected_broken_dylibs.empty? puts "No unexpected broken library linkage detected." else puts "Broken library linkage detected" @@ -71,17 +72,37 @@ class LinkageChecker def broken_library_linkage? issues = [@broken_deps, @unwanted_system_dylibs, @version_conflict_deps] - [issues, unexpected_broken_libs].flatten.any?(&:present?) + [issues, unexpected_broken_dylibs].flatten.any?(&:present?) end - def unexpected_broken_libs - @broken_dylibs.reject { |lib| @formula.allowed_missing_lib? lib } + def allowed_missing_lib?(lib) + raise TypeError, "Library must be a string; got a #{lib.class} (#{lib})" unless lib.is_a? String + + # 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} + @formula.class.allowed_missing_libraries.any? do |x| + case x + when Regexp + x.match? lib + when String + lib.include? x + end + end + end + + def unexpected_broken_dylibs + return @unexpected_broken_dylibs if @unexpected_broken_dylibs + + @unexpected_broken_dylibs = @broken_dylibs.reject { |lib| allowed_missing_lib? lib } end def broken_dylibs_with_expectations output = {} @broken_dylibs.each do |lib| - output[lib] = if unexpected_broken_libs.include? lib + output[lib] = if unexpected_broken_dylibs.include? lib ["unexpected"] else ["expected"] From 77a38aed0d6a7e7d9806a128d69b5f84f78f2c24 Mon Sep 17 00:00:00 2001 From: Maxim Belkin Date: Wed, 22 Jul 2020 14:39:29 +0000 Subject: [PATCH 7/8] linkage_checker.rb: meld allowed_missing_lib? into unexpected_broken_dylibs --- Library/Homebrew/linkage_checker.rb | 29 ++++++++++------------------- 1 file changed, 10 insertions(+), 19 deletions(-) diff --git a/Library/Homebrew/linkage_checker.rb b/Library/Homebrew/linkage_checker.rb index 31b6c0e3cc..baa99fa1dd 100644 --- a/Library/Homebrew/linkage_checker.rb +++ b/Library/Homebrew/linkage_checker.rb @@ -75,28 +75,19 @@ class LinkageChecker [issues, unexpected_broken_dylibs].flatten.any?(&:present?) end - def allowed_missing_lib?(lib) - raise TypeError, "Library must be a string; got a #{lib.class} (#{lib})" unless lib.is_a? String - - # 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} - @formula.class.allowed_missing_libraries.any? do |x| - case x - when Regexp - x.match? lib - when String - lib.include? x - end - end - end - def unexpected_broken_dylibs return @unexpected_broken_dylibs if @unexpected_broken_dylibs - @unexpected_broken_dylibs = @broken_dylibs.reject { |lib| allowed_missing_lib? lib } + @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 def broken_dylibs_with_expectations From 42f90dba4663370e773c7d4508481efbfb4a2a40 Mon Sep 17 00:00:00 2001 From: Maxim Belkin Date: Wed, 22 Jul 2020 14:41:15 +0000 Subject: [PATCH 8/8] linkage_checker.rb: rename lib to broken_lib --- Library/Homebrew/linkage_checker.rb | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Library/Homebrew/linkage_checker.rb b/Library/Homebrew/linkage_checker.rb index baa99fa1dd..c97a691f10 100644 --- a/Library/Homebrew/linkage_checker.rb +++ b/Library/Homebrew/linkage_checker.rb @@ -92,8 +92,8 @@ class LinkageChecker def broken_dylibs_with_expectations output = {} - @broken_dylibs.each do |lib| - output[lib] = if unexpected_broken_dylibs.include? lib + @broken_dylibs.each do |broken_lib| + output[broken_lib] = if unexpected_broken_dylibs.include? broken_lib ["unexpected"] else ["expected"]