From e7b3b8e55985b8e4ab41973dfbd76904d7fd3b91 Mon Sep 17 00:00:00 2001 From: Maxim Belkin Date: Sun, 28 Jun 2020 04:33:00 +0000 Subject: [PATCH 1/3] Allow missing libraries --- Library/Homebrew/formula.rb | 11 +++++++++++ Library/Homebrew/linkage_checker.rb | 16 +++++++++++----- 2 files changed, 22 insertions(+), 5 deletions(-) diff --git a/Library/Homebrew/formula.rb b/Library/Homebrew/formula.rb index 7af9d17b6f..440554651b 100644 --- a/Library/Homebrew/formula.rb +++ b/Library/Homebrew/formula.rb @@ -1131,6 +1131,13 @@ class Formula end end + # Whether this {Formula} is allowed to have broken linkage. + # Defaults to false. + # @return [Boolean] + def allow_missing_libs? + false + end + # Whether this {Formula} is deprecated (i.e. warns on installation). # Defaults to false. # @method deprecated? @@ -2596,6 +2603,10 @@ class Formula @skip_clean_paths ||= Set.new end + def allow_missing_libs + define_method(:allow_missing_libs?) { true } + end + # Software that will not be symlinked into the `brew --prefix` will only # live in its Cellar. Other formulae can depend on it and then brew will # add the necessary includes and libs (etc.) during the brewing of that diff --git a/Library/Homebrew/linkage_checker.rb b/Library/Homebrew/linkage_checker.rb index a654a83701..220b04bfac 100644 --- a/Library/Homebrew/linkage_checker.rb +++ b/Library/Homebrew/linkage_checker.rb @@ -59,14 +59,20 @@ class LinkageChecker display_items "Broken dependencies", @broken_deps, puts_output: puts_output display_items "Unwanted system libraries", @unwanted_system_dylibs, puts_output: puts_output display_items "Conflicting libraries", @version_conflict_deps, puts_output: puts_output - puts "No broken library linkage" unless broken_library_linkage? + if got_library_issues? + puts "Broken library linkage ignored" if @formula.allow_missing_libs? + else + puts "No broken library linkage" + end end def broken_library_linkage? - !@broken_dylibs.empty? || - !@broken_deps.empty? || - !@unwanted_system_dylibs.empty? || - !@version_conflict_deps.empty? + !@formula.allow_missing_libs? && got_library_issues? + end + + def got_library_issues? + issues = [@broken_dylibs, @broken_deps, @unwanted_system_dylibs, @version_conflict_deps] + issues.any?(&:present?) end private From c61aba4ec3cc61f63ebe4840f31acd86d83c96ea Mon Sep 17 00:00:00 2001 From: Maxim Belkin Date: Fri, 10 Jul 2020 21:20:46 +0000 Subject: [PATCH 2/3] Formula: ignore_missing_libraries DSL --- Library/Homebrew/extend/os/linux/formula.rb | 26 ++++++++++++++++++++ Library/Homebrew/formula.rb | 8 ++---- Library/Homebrew/linkage_checker.rb | 27 +++++++++++++++------ 3 files changed, 47 insertions(+), 14 deletions(-) diff --git a/Library/Homebrew/extend/os/linux/formula.rb b/Library/Homebrew/extend/os/linux/formula.rb index 3b4351d057..54c5867b36 100644 --- a/Library/Homebrew/extend/os/linux/formula.rb +++ b/Library/Homebrew/extend/os/linux/formula.rb @@ -7,11 +7,37 @@ class Formula "#{name}.so#{"." unless version.nil?}#{version}" 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| + if x.is_a? Regexp + x.match? lib + elsif x.is_a? String + lib.include? x + end + end + end + class << self undef on_linux def on_linux(&_block) yield end + + def ignore_missing_libraries(*libs) + libs.flatten! + allowed_missing_libraries.merge(libs) + end + + # @private + def allowed_missing_libraries + @allowed_missing_libraries ||= Set.new + end end end diff --git a/Library/Homebrew/formula.rb b/Library/Homebrew/formula.rb index 440554651b..06084522f6 100644 --- a/Library/Homebrew/formula.rb +++ b/Library/Homebrew/formula.rb @@ -1131,10 +1131,10 @@ class Formula end end - # Whether this {Formula} is allowed to have broken linkage. + # Whether this {Formula} is allowed to have a broken linkage to specified library. # Defaults to false. # @return [Boolean] - def allow_missing_libs? + def allowed_missing_lib?(*) false end @@ -2603,10 +2603,6 @@ class Formula @skip_clean_paths ||= Set.new end - def allow_missing_libs - define_method(:allow_missing_libs?) { true } - end - # Software that will not be symlinked into the `brew --prefix` will only # live in its Cellar. Other formulae can depend on it and then brew will # add the necessary includes and libs (etc.) during the brewing of that diff --git a/Library/Homebrew/linkage_checker.rb b/Library/Homebrew/linkage_checker.rb index 220b04bfac..a0dbfeadef 100644 --- a/Library/Homebrew/linkage_checker.rb +++ b/Library/Homebrew/linkage_checker.rb @@ -55,24 +55,35 @@ class LinkageChecker end def display_test_output(puts_output: true) - display_items "Missing libraries", @broken_dylibs, puts_output: puts_output + display_items "Missing libraries", broken_dylibs_with_expectations, puts_output: puts_output display_items "Broken dependencies", @broken_deps, puts_output: puts_output display_items "Unwanted system libraries", @unwanted_system_dylibs, puts_output: puts_output display_items "Conflicting libraries", @version_conflict_deps, puts_output: puts_output - if got_library_issues? - puts "Broken library linkage ignored" if @formula.allow_missing_libs? + + if @broken_dylibs.empty? + puts "No broken library linkage detected" + elsif unexpected_broken_libs.empty? + puts "No unexpected broken library linkage detected." else - puts "No broken library linkage" + puts "Broken library linkage detected" end end def broken_library_linkage? - !@formula.allow_missing_libs? && got_library_issues? + issues = [@broken_deps, @unwanted_system_dylibs, @version_conflict_deps] + [issues, unexpected_broken_libs].flatten.any?(&:present?) end - def got_library_issues? - issues = [@broken_dylibs, @broken_deps, @unwanted_system_dylibs, @version_conflict_deps] - issues.any?(&:present?) + def unexpected_broken_libs + @broken_dylibs.reject { |lib| @formula.allowed_missing_lib? lib } + end + + def broken_dylibs_with_expectations + output = {} + @broken_dylibs.each do |lib| + output[lib] = (unexpected_broken_libs.include? lib) ? ["unexpected"] : ["expected"] + end + output end private From f2ddcda85b6770218d861b26948ddf734e0b0759 Mon Sep 17 00:00:00 2001 From: Maxim Belkin Date: Thu, 16 Jul 2020 13:53:32 +0000 Subject: [PATCH 3/3] Fix style (Convert if-elsif to case-when) --- Library/Homebrew/extend/os/linux/formula.rb | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/Library/Homebrew/extend/os/linux/formula.rb b/Library/Homebrew/extend/os/linux/formula.rb index 54c5867b36..12b28db2a0 100644 --- a/Library/Homebrew/extend/os/linux/formula.rb +++ b/Library/Homebrew/extend/os/linux/formula.rb @@ -15,9 +15,10 @@ class Formula # Ex. 1: "libONE.so.1" # Ex. 2: %r{(libONE|libTWO)\.so} self.class.allowed_missing_libraries.any? do |x| - if x.is_a? Regexp + case x + when Regexp x.match? lib - elsif x.is_a? String + when String lib.include? x end end