Spec-Zone.ru › Homebrew

Модуль: OS::Linux::Keg Закрытый

Расширяет:
T::Helpers
Включён в:
Keg
Определён в:
extend/os/linux/keg.rb,
extend/os/linux/keg_relocate.rb

Этот модуль является частью закрытого API. Этот модуль можно использовать только в репозитории Homebrew/brew. Сторонним разработчикам следует по возможности избегать использования этого модуля, поскольку он может быть удалён или изменён без предупреждения.

Краткое описание методов экземпляра свернуть

  • #binary_executable_or_library_files ⇒ Array<ELFShim> закрытый
  • #change_rpath!(file, old_prefix, new_prefix, skip_protodesc_cold: false) ⇒ Boolean закрытый
  • #detect_cxx_stdlibs(options = {}) ⇒ Array<Symbol> закрытый
  • #elf_files ⇒ Array<ELFShim> закрытый
  • #relocate_dynamic_linkage(relocation, skip_protodesc_cold: false) ⇒ void закрытый

Подробное описание методов экземпляра

#binary_executable_or_library_files ⇒ Array<ELFShim>

Этот метод является частью закрытого API. Этот метод можно использовать только в репозитории Homebrew/brew. Сторонним разработчикам следует по возможности избегать использования этого метода, поскольку он может быть удалён или изменён без предупреждения.

Возвращает:

  • (Array<ELFShim>)


8
# File 'extend/os/linux/keg.rb', line 8

def binary_executable_or_library_files = elf_files

#change_rpath!(file, old_prefix, new_prefix, skip_protodesc_cold: false) ⇒ Boolean

Этот метод является частью закрытого API. Этот метод можно использовать только в репозитории Homebrew/brew. Сторонним разработчикам следует по возможности избегать использования этого метода, поскольку он может быть удалён или изменён без предупреждения.

Параметры:

  • file (ELFShim)
  • old_prefix (String, Regexp)
  • new_prefix (String)
  • skip_protodesc_cold (Boolean) (по умолчанию: false)

Возвращает:

  • (Boolean)


31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
# File 'extend/os/linux/keg_relocate.rb', line 31

def change_rpath!(file, old_prefix, new_prefix, skip_protodesc_cold: false)
  return false if !file.elf? || !file.dynamic_elf?

  # Skip relocation of files with `protodesc_cold` sections because patchelf.rb seems to break them,
  # but only when bottling (as we don't want to break existing bottles that require relocation).
  # https://github.com/Homebrew/homebrew-core/pull/232490#issuecomment-3161362452
  return false if skip_protodesc_cold && file.section_names.include?("protodesc_cold")

  updated = {}
  old_rpath = file.rpath
  new_rpath = if old_rpath
    rpath = old_rpath.split(":")
                     .map { |x| x.sub(old_prefix, new_prefix) }
                     .select { |x| x.start_with?(new_prefix, "$ORIGIN") }

    lib_path = "#{new_prefix}/lib"
    rpath << lib_path unless rpath.include? lib_path

    # Add GCC's lib directory (as of GCC 12+) to RPATH when there is existing versioned linkage.
    # This prevents broken linkage when pouring bottles built with an old GCC formula.
    unless name.match?(Version.formula_optionally_versioned_regex(:gcc))
      rpath.map! { |rp| rp.sub(%r{lib/gcc/\d+$}, "lib/gcc/current") }
    end

    rpath.join(":")
  end
  updated[:rpath] = new_rpath if old_rpath != new_rpath

  old_interpreter = file.interpreter
  new_interpreter = if old_interpreter.nil?
    nil
  elsif File.readable? "#{new_prefix}/lib/ld.so"
    "#{new_prefix}/lib/ld.so"
  else
    old_interpreter.sub old_prefix, new_prefix
  end
  updated[:interpreter] = new_interpreter if old_interpreter != new_interpreter
  return false if updated.empty?

  file.patch!(interpreter: updated[:interpreter], rpath: updated[:rpath])
  require_relocation!
  true
end

#detect_cxx_stdlibs(options = {}) ⇒ Array<Symbol>

Этот метод является частью закрытого API. Этот метод можно использовать только в репозитории Homebrew/brew. Сторонним разработчикам следует по возможности избегать использования этого метода, поскольку он может быть удалён или изменён без предупреждения.

Параметры:

  • options (Hash{Symbol => Boolean}) (по умолчанию: {})

Возвращает:

  • (Array<Symbol>)


76
77
78
79
80
81
82
83
84
85
86
87
88
# File 'extend/os/linux/keg_relocate.rb', line 76

def detect_cxx_stdlibs(options = {})
  skip_executables = options.fetch(:skip_executables, false)
  results = Set.new
  elf_files.each do |file|
    next unless file.dynamic_elf?
    next if file.binary_executable? && skip_executables

    dylibs = file.dynamically_linked_libraries
    results << :libcxx if dylibs.any? { |s| s.include? "libc++.so" }
    results << :libstdcxx if dylibs.any? { |s| s.include? "libstdc++.so" }
  end
  results.to_a
end

#elf_files ⇒ Array<ELFShim>

Этот метод является частью закрытого API. Этот метод можно использовать только в репозитории Homebrew/brew. Сторонним разработчикам следует по возможности избегать использования этого метода, поскольку он может быть удалён или изменён без предупреждения.

Возвращает:

  • (Array<ELFShim>)


91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
# File 'extend/os/linux/keg_relocate.rb', line 91

def elf_files
  hardlinks = Set.new
  elf_files = []
  path.find do |pn|
    next if pn.symlink? || pn.directory?

    pn = ELFPathname.wrap(pn)
    next if !pn.dylib? && !pn.binary_executable?

    # If we've already processed a file, ignore its hardlinks (which have the
    # same dev ID and inode). This prevents relocations from being performed
    # on a binary more than once.
    next unless hardlinks.add? [pn.stat.dev, pn.stat.ino]

    elf_files << pn
  end
  elf_files
end

#relocate_dynamic_linkage(relocation, skip_protodesc_cold: false) ⇒ void

Этот метод является частью закрытого API. Этот метод можно использовать только в репозитории Homebrew/brew. Сторонним разработчикам следует по возможности избегать использования этого метода, поскольку он может быть удалён или изменён без предупреждения.

Этот метод возвращает неопределённое значение.

Параметры:

  • relocation (::Keg::Relocation)
  • skip_protodesc_cold (Boolean) (по умолчанию: false)


14
15
16
17
18
19
20
21
22
23
24
25
# File 'extend/os/linux/keg_relocate.rb', line 14

def relocate_dynamic_linkage(relocation, skip_protodesc_cold: false)
  # Patching the dynamic linker of glibc breaks it.
  return if name.match? Version.formula_optionally_versioned_regex(:glibc)

  old_prefix, new_prefix = relocation.replacement_pair_for(:prefix)

  elf_files.each do |file|
    file.ensure_writable do
      change_rpath!(file, old_prefix, new_prefix, skip_protodesc_cold:)
    end
  end
end

© 2009–present Homebrew contributors
Licensed under the BSD 2-Clause License.
https://docs.brew.sh/rubydoc/OS/Linux/Keg.html

Spec-Zone.ru

Настройки Оффлайн Что нового Помощь О нас
Spec-Zone .ru
спецификации, руководства, описания, API