Class: LinkageChecker Private

Inherits:
Object show all
Defined in:
linkage_checker.rb,
extend/os/linux/linkage_checker.rb

Overview

This class is part of a private API. This class may only be used in the Homebrew/brew repository. Third parties should avoid using this class if possible, as it may be removed or changed without warning.

Check for broken/missing linkage in a formula’s keg.

Constant Summary collapse

SYSTEM_LIBRARY_ALLOWLIST =

Libraries provided by glibc and gcc.

%w[
  ld-linux-x86-64.so.2
  ld-linux-aarch64.so.1
  libanl.so.1
  libatomic.so.1
  libc.so.6
  libdl.so.2
  libm.so.6
  libmvec.so.1
  libnss_files.so.2
  libpthread.so.0
  libresolv.so.2
  librt.so.1
  libthread_db.so.1
  libutil.so.1
  libgcc_s.so.1
  libgomp.so.1
  libstdc++.so.6
  libquadmath.so.0
].freeze

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(keg, formula = nil, cache_db:, rebuild_cache: false) ⇒ LinkageChecker

This method is part of a private API. This method may only be used in the Homebrew/brew repository. Third parties should avoid using this method if possible, as it may be removed or changed without warning.

Returns a new instance of LinkageChecker.



15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
# File 'linkage_checker.rb', line 15

def initialize(keg, formula = nil, cache_db:, rebuild_cache: false)
  @keg = keg
  @formula = formula || resolve_formula(keg)
  @store = LinkageCacheStore.new(keg.to_s, cache_db)

  @system_dylibs    = Set.new
  @broken_dylibs    = Set.new
  @unexpected_broken_dylibs = nil
  @unexpected_present_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 }
  @broken_deps      = Hash.new { |h, k| h[k] = [] }
  @indirect_deps    = []
  @undeclared_deps  = []
  @unnecessary_deps = []
  @unwanted_system_dylibs = []
  @version_conflict_deps = []
  @files_missing_rpaths = []

  check_dylibs(rebuild_cache: rebuild_cache)
end

Instance Attribute Details

#formulaObject (readonly)

This method is part of a private API. This method may only be used in the Homebrew/brew repository. Third parties should avoid using this method if possible, as it may be removed or changed without warning.



13
14
15
# File 'linkage_checker.rb', line 13

def formula
  @formula
end

#kegObject (readonly)

This method is part of a private API. This method may only be used in the Homebrew/brew repository. Third parties should avoid using this method if possible, as it may be removed or changed without warning.



13
14
15
# File 'linkage_checker.rb', line 13

def keg
  @keg
end

#storeObject (readonly)

This method is part of a private API. This method may only be used in the Homebrew/brew repository. Third parties should avoid using this method if possible, as it may be removed or changed without warning.



13
14
15
# File 'linkage_checker.rb', line 13

def store
  @store
end

#undeclared_depsObject (readonly)

This method is part of a private API. This method may only be used in the Homebrew/brew repository. Third parties should avoid using this method if possible, as it may be removed or changed without warning.



13
14
15
# File 'linkage_checker.rb', line 13

def undeclared_deps
  @undeclared_deps
end

Instance Method Details

#broken_dylibs_with_expectationsObject

This method is part of a private API. This method may only be used in the Homebrew/brew repository. Third parties should avoid using this method if possible, as it may be removed or changed without warning.



123
124
125
126
127
128
129
130
131
132
133
# File 'linkage_checker.rb', line 123

def broken_dylibs_with_expectations
  output = {}
  @broken_dylibs.each do |broken_lib|
    output[broken_lib] = if unexpected_broken_dylibs.include? broken_lib
      ["unexpected"]
    else
      ["expected"]
    end
  end
  output
end

#broken_library_linkage?(test: false, strict: false) ⇒ Boolean Also known as: generic_broken_library_linkage?

Parameters:

  • test (Boolean) (defaults to: false)
  • strict (Boolean) (defaults to: false)

Returns:

  • (Boolean)


59
60
61
# File 'extend/os/linux/linkage_checker.rb', line 59

def broken_library_linkage?(test: false, strict: false)
  generic_broken_library_linkage?(test: test, strict: strict) || @libnsl_found
end

#display_deprecated_warning(strict: false) ⇒ Object



29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
# File 'extend/os/linux/linkage_checker.rb', line 29

def display_deprecated_warning(strict: false)
  # Steps when moving these to `odisabled`:
  # - Remove the old library from SYSTEM_LIBRARY_ALLOWLIST above.
  # - Remove the `disable` and `disable_for_developer` kwargs here.
  # - Adjust the `broken_library_linkage?` override below to not check for the library.
  # - Remove the relevant `fail_on_lib*?`.
  # If there's no more deprecations left:
  # - Remove the `broken_library_linkage?` override and the generic alias in HOMEBREW_LIBRARY/linkage_checker.rb.
  #
  # Steps when removing handling for a library entirely (assuming the steps to `odisabled` has already been done):
  # - Remove the relevant setting of `@lib*_found` in `check_dylibs` below.
  # - Remove the `odisabled` line
  # If there's no library deprecated/disabled handling left:
  # - Remove the `display_` overrides here and the associated generic aliases in HOMEBREW_LIBRARY/linkage_checker.rb

  return unless @libnsl_found

  odisabled "linkage to libnsl.so.1", "libnsl.so.3 in the libnsl formula"
end

#display_normal_outputObject Also known as: generic_display_normal_output

This method is part of a private API. This method may only be used in the Homebrew/brew repository. Third parties should avoid using this method if possible, as it may be removed or changed without warning.



49
50
51
52
# File 'extend/os/linux/linkage_checker.rb', line 49

def display_normal_output
  generic_display_normal_output
  display_deprecated_warning
end

#display_reverse_outputObject

This method is part of a private API. This method may only be used in the Homebrew/brew repository. Third parties should avoid using this method if possible, as it may be removed or changed without warning.



53
54
55
56
57
58
59
60
61
62
63
64
65
# File 'linkage_checker.rb', line 53

def display_reverse_output
  return if @reverse_links.empty?

  sorted = @reverse_links.sort
  sorted.each do |dylib, files|
    puts dylib
    files.each do |f|
      unprefixed = f.to_s.delete_prefix "#{keg}/"
      puts "  #{unprefixed}"
    end
    puts if dylib != sorted.last.first
  end
end

#display_test_output(puts_output: true, strict: false) ⇒ Object Also known as: generic_display_test_output

This method is part of a private API. This method may only be used in the Homebrew/brew repository. Third parties should avoid using this method if possible, as it may be removed or changed without warning.



54
55
56
57
# File 'extend/os/linux/linkage_checker.rb', line 54

def display_test_output(puts_output: true, strict: false)
  generic_display_test_output(puts_output: puts_output, strict: strict)
  display_deprecated_warning(strict: strict)
end

#unexpected_broken_dylibsObject

This method is part of a private API. This method may only be used in the Homebrew/brew repository. Third parties should avoid using this method if possible, as it may be removed or changed without warning.



95
96
97
98
99
100
101
102
103
104
105
106
107
108
# File 'linkage_checker.rb', line 95

def unexpected_broken_dylibs
  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

#unexpected_present_dylibsObject

This method is part of a private API. This method may only be used in the Homebrew/brew repository. Third parties should avoid using this method if possible, as it may be removed or changed without warning.



110
111
112
113
114
115
116
117
118
119
120
121
# File 'linkage_checker.rb', line 110

def unexpected_present_dylibs
  @unexpected_present_dylibs ||= @formula.class.allowed_missing_libraries.reject do |allowed_missing_lib|
    @broken_dylibs.any? do |broken_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