Class: Keg Private
- Extended by:
- Cachable, Forwardable, T::Generic, Utils::Output::Mixin
- Includes:
- OS::Linux::Keg, OS::Mac::Keg, Utils::Output::Mixin
- Defined in:
- keg.rb,
keg_relocate.rb,
keg.rbi,
sorbet/rbi/dsl/keg.rbi
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.
Defined Under Namespace
Classes: AlreadyLinkedError, ConflictError, DirectoryNotWritableError, LinkError, Relocation
Constant Summary collapse
- Cache =
This constant is part of a private API. This constant may only be used in the Homebrew/brew repository. Third parties should avoid using this constant if possible, as it may be removed or changed without warning.
type_template { { fixed: T::Hash[Symbol, T.untyped] } }
- LOCALEDIR_RX =
This constant is part of a private API. This constant may only be used in the Homebrew/brew repository. Third parties should avoid using this constant if possible, as it may be removed or changed without warning.
Locale-specific directories have the form
language[_territory][.codeset][@modifier] %r{(locale|man)/([a-z]{2}|C|POSIX)(_[A-Z]{2})?(\.[a-zA-Z\-0-9]+(@.+)?)?}- INFOFILE_RX =
This constant is part of a private API. This constant may only be used in the Homebrew/brew repository. Third parties should avoid using this constant if possible, as it may be removed or changed without warning.
%r{info/([^.].*?\.info(\.gz)?|dir)$}- SHARE_PATHS =
This constant is part of a private API. This constant may only be used in the Homebrew/brew repository. Third parties should avoid using this constant if possible, as it may be removed or changed without warning.
These paths relative to the keg's share directory should always be real directories in the prefix, never symlinks.
%w[ aclocal doc info java locale man man/man1 man/man2 man/man3 man/man4 man/man5 man/man6 man/man7 man/man8 man/cat1 man/cat2 man/cat3 man/cat4 man/cat5 man/cat6 man/cat7 man/cat8 applications gnome gnome/help icons mime-info pixmaps sounds postgresql ].freeze
- ELISP_EXTENSIONS =
This constant is part of a private API. This constant may only be used in the Homebrew/brew repository. Third parties should avoid using this constant if possible, as it may be removed or changed without warning.
%w[.el .elc].freeze
- PYC_EXTENSIONS =
This constant is part of a private API. This constant may only be used in the Homebrew/brew repository. Third parties should avoid using this constant if possible, as it may be removed or changed without warning.
%w[.pyc .pyo].freeze
- LIBTOOL_EXTENSIONS =
This constant is part of a private API. This constant may only be used in the Homebrew/brew repository. Third parties should avoid using this constant if possible, as it may be removed or changed without warning.
%w[.la .lai].freeze
- KEEPME_FILE =
This constant is part of a private API. This constant may only be used in the Homebrew/brew repository. Third parties should avoid using this constant if possible, as it may be removed or changed without warning.
".keepme"- PREFIX_PLACEHOLDER =
This constant is part of a private API. This constant may only be used in the Homebrew/brew repository. Third parties should avoid using this constant if possible, as it may be removed or changed without warning.
"@@HOMEBREW_PREFIX@@"- CELLAR_PLACEHOLDER =
This constant is part of a private API. This constant may only be used in the Homebrew/brew repository. Third parties should avoid using this constant if possible, as it may be removed or changed without warning.
"@@HOMEBREW_CELLAR@@"- REPOSITORY_PLACEHOLDER =
This constant is part of a private API. This constant may only be used in the Homebrew/brew repository. Third parties should avoid using this constant if possible, as it may be removed or changed without warning.
"@@HOMEBREW_REPOSITORY@@"- LIBRARY_PLACEHOLDER =
This constant is part of a private API. This constant may only be used in the Homebrew/brew repository. Third parties should avoid using this constant if possible, as it may be removed or changed without warning.
"@@HOMEBREW_LIBRARY@@"- PERL_PLACEHOLDER =
This constant is part of a private API. This constant may only be used in the Homebrew/brew repository. Third parties should avoid using this constant if possible, as it may be removed or changed without warning.
"@@HOMEBREW_PERL@@"- JAVA_PLACEHOLDER =
This constant is part of a private API. This constant may only be used in the Homebrew/brew repository. Third parties should avoid using this constant if possible, as it may be removed or changed without warning.
"@@HOMEBREW_JAVA@@"- NULL_BYTE =
This constant is part of a private API. This constant may only be used in the Homebrew/brew repository. Third parties should avoid using this constant if possible, as it may be removed or changed without warning.
"\x00"- NULL_BYTE_STRING =
This constant is part of a private API. This constant may only be used in the Homebrew/brew repository. Third parties should avoid using this constant if possible, as it may be removed or changed without warning.
"\\x00"- JAVA_REGEX =
This constant is part of a private API. This constant may only be used in the Homebrew/brew repository. Third parties should avoid using this constant if possible, as it may be removed or changed without warning.
%r{#{HOMEBREW_PREFIX}/opt/openjdk(@\d+(\.\d+)*)?/libexec(/openjdk\.jdk/Contents/Home)?}
Constants included from OS::Mac::Keg
OS::Mac::Keg::FRAMEWORK_RX, OS::Mac::Keg::VARIABLE_REFERENCE_RX
Instance Attribute Summary collapse
- #linked_keg_record ⇒ Pathname readonly private
- #name ⇒ String readonly private
- #opt_record ⇒ Pathname readonly private
Class Method Summary collapse
- .all ⇒ Array<Keg> private
- .file_linked_libraries(_file, _string) ⇒ Array<Pathname> private
- .for(path) ⇒ Keg private
- .from_rack(rack) ⇒ Keg? private
- .keg_link_directories ⇒ Array<String> private
-
.must_be_writable_directories ⇒ Array<Pathname>
private
Keep relatively in sync with https://github.com/Homebrew/install/blob/HEAD/install.sh.
-
.must_exist_directories ⇒ Array<Pathname>
private
Keep relatively in sync with https://github.com/Homebrew/install/blob/HEAD/install.sh.
- .must_exist_subdirectories ⇒ Array<Pathname> private
- .text_matches_in_file(file, string, ignores, linked_libraries, formula_and_runtime_deps_names) ⇒ Array<Array<(String, String)>> private
Instance Method Summary collapse
- #/(*args, &block) ⇒ T.untyped private
- #abv(*args, &block) ⇒ T.untyped private
- #aliases ⇒ Array<String> private
- #apps ⇒ Array<Pathname> private
- #binary_executable_or_library_files ⇒ Array<Pathname> private
- #binary_file?(file) ⇒ Boolean private
- #codesign_patched_binary(file) ⇒ void private
- #completion_installed?(shell) ⇒ Boolean private
- #consistent_reproducible_symlink_permissions! ⇒ void private
- #delete_pyc_files! ⇒ void private
- #detect_cxx_stdlibs(_options = {}) ⇒ Array<Symbol> private
- #directory?(*args, &block) ⇒ Boolean private
- #disk_usage(*args, &block) ⇒ T.untyped private
- #each_unique_file_matching(string, &_block) ⇒ void private
- #egrep_args ⇒ Array<(String, Array<String>)> private
- #elisp_installed? ⇒ Boolean private
- #empty_installation? ⇒ Boolean private
- #exist?(*args, &block) ⇒ Boolean private
- #file_count(*args, &block) ⇒ T.untyped private
- #find(*args, &block) ⇒ T.untyped private
- #fix_dynamic_linkage ⇒ void private
- #functions_installed?(shell) ⇒ Boolean private
- #homebrew_created_file?(file) ⇒ Boolean private
- #ignore_interrupts_and_uninstall! ⇒ void private
- #initialize(path) ⇒ void constructor private
- #join(*args, &block) ⇒ T.untyped private
- #keepme_refs ⇒ Array<String> private
- #lib ⇒ Pathname private
- #libexec ⇒ Pathname private
- #libtool_files ⇒ Array<Pathname> private
- #link(verbose: false, dry_run: false, overwrite: false) ⇒ Integer private
- #linked? ⇒ Boolean private
- #lock(&_block) ⇒ void private
- #new_usr_local_replacement_pairs ⇒ Hash{Symbol => Hash{Symbol => String}} private
- #normalize_pod2man_outputs! ⇒ void private
- #oldname_opt_records ⇒ Array<Pathname> private
- #openjdk_dep_name_if_applicable ⇒ String? private
- #optlink(verbose: false, dry_run: false, overwrite: false) ⇒ void private
- #optlinked? ⇒ Boolean private
- #plist_installed? ⇒ Boolean private
- #prepare_debug_symbols ⇒ void private
- #prepare_relocation_to_locations ⇒ Relocation private
- #prepare_relocation_to_placeholders(new_usr_local_relocation: new_usr_local_relocation?) ) ⇒ Relocation private
- #rack ⇒ Pathname private
- #recursive_fgrep_args ⇒ String private
- #relocate_build_prefix(keg, old_prefix, new_prefix) ⇒ void private
- #relocate_dynamic_linkage(_relocation, skip_protodesc_cold: false) ⇒ void private
- #remove_linked_keg_record ⇒ void private
- #remove_old_aliases ⇒ void private
- #remove_oldname_opt_records ⇒ void private
- #remove_opt_record ⇒ void private
- #rename(*args, &block) ⇒ T.untyped private
- #replace_locations_with_placeholders ⇒ Array<Pathname> private
- #replace_placeholders_with_locations(files, skip_linkage: false) ⇒ void private
- #replace_text_in_files(relocation, files: nil) ⇒ Array<Pathname> private
- #require_relocation? ⇒ Boolean private
- #runtime_dependencies ⇒ Array<T.untyped>? private
-
#scheme_and_version ⇒ Array<(Integer, PkgVersion)>
private
For ordering kegs by version with
.sort_by,.max_by, etc. - #symlink_files ⇒ Array<Pathname> private
- #tab ⇒ Tab private
- #text_files ⇒ Array<Pathname> private
- #to_formula ⇒ Formula private
- #to_path(*args, &block) ⇒ T.untyped private
- #uninstall(raise_failures: false) ⇒ void private
- #unlink(verbose: false, dry_run: false) ⇒ Integer private
- #version ⇒ PkgVersion private
- #version_scheme ⇒ Integer private
Methods included from Cachable
Methods included from Utils::Output::Mixin
issue_reporting_message, odebug, odeprecated, odie, odisabled, ofail, oh1, oh1_title, ohai, ohai_title, onoe, opoo, opoo_outside_github_actions, pretty_deprecated, pretty_disabled, pretty_duration, pretty_install_status, pretty_installed, pretty_outdated, pretty_uninstalled, pretty_upgradable
Methods included from OS::Mac::Keg
#change_dylib_id, #change_install_name, #change_rpath, #delete_rpath, #dylib_id_for, #each_linkage_for, #find_dylib, #find_dylib_suffix_from, #fixed_name, #formula_preserve_rpath?, #loader_name_for, #mach_o_files, #prepare_codesign_writable_files, #relocated_name_for
Methods included from SystemCommand::Mixin
#system_command, #system_command!
Methods included from OS::Linux::Keg
Constructor Details
#initialize(path) ⇒ void
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.
205 206 207 208 209 210 211 212 213 214 215 216 |
# File 'keg.rb', line 205 def initialize(path) path = path.resolved_path if path.to_s.start_with?("#{HOMEBREW_PREFIX}/opt/") raise "#{path} is not a valid keg" if path.parent.parent.realpath != HOMEBREW_CELLAR.realpath raise "#{path} is not a directory" unless path.directory? @path = path @name = T.let(path.parent.basename.to_s, String) @linked_keg_record = T.let(HOMEBREW_LINKED_KEGS/name, Pathname) @opt_record = T.let(HOMEBREW_PREFIX/"opt/#{name}", Pathname) @oldname_opt_records = T.let([], T::Array[Pathname]) @require_relocation = false end |
Instance Attribute Details
#linked_keg_record ⇒ Pathname (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.
194 195 196 |
# File 'keg.rb', line 194 def linked_keg_record @linked_keg_record end |
#name ⇒ String (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.
191 192 193 |
# File 'keg.rb', line 191 def name @name end |
#opt_record ⇒ Pathname (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.
194 195 196 |
# File 'keg.rb', line 194 def opt_record @opt_record end |
Class Method Details
.all ⇒ Array<Keg>
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.
140 141 142 |
# File 'keg.rb', line 140 def self.all Formula.racks.flat_map(&:subdirs).map { |d| new(d) } end |
.file_linked_libraries(_file, _string) ⇒ Array<Pathname>
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.
458 459 460 |
# File 'keg_relocate.rb', line 458 def self.file_linked_libraries(_file, _string) [] end |
.for(path) ⇒ Keg
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.
117 118 119 120 121 122 123 124 125 126 127 128 129 |
# File 'keg.rb', line 117 def self.for(path) original_path = path raise Errno::ENOENT, original_path.to_s unless original_path.exist? if (path = original_path.realpath) until path.root? return Keg.new(path) if path.parent.parent == HOMEBREW_CELLAR.realpath path = path.parent.realpath # realpath() prevents root? failing end end raise NotAKegError, "#{original_path} is not inside a keg" end |
.from_rack(rack) ⇒ Keg?
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.
132 133 134 135 136 137 |
# File 'keg.rb', line 132 def self.from_rack(rack) return unless rack.directory? kegs = rack.subdirs.map { |d| new(d) } kegs.find(&:linked?) || kegs.find(&:optlinked?) || kegs.max_by(&:scheme_and_version) end |
.keg_link_directories ⇒ Array<String>
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.
145 146 147 148 149 |
# File 'keg.rb', line 145 def self.keg_link_directories @keg_link_directories ||= T.let(%w[ bin etc include lib sbin share var ].freeze, T.nilable(T::Array[String])) end |
.must_be_writable_directories ⇒ Array<Pathname>
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.
Keep relatively in sync with https://github.com/Homebrew/install/blob/HEAD/install.sh
171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 |
# File 'keg.rb', line 171 def self.must_be_writable_directories @must_be_writable_directories ||= T.let((%w[ etc/bash_completion.d lib/pkgconfig share/aclocal share/doc share/info share/locale share/man share/man/man1 share/man/man2 share/man/man3 share/man/man4 share/man/man5 share/man/man6 share/man/man7 share/man/man8 share/zsh share/zsh/site-functions share/pwsh share/pwsh/completions var/log ].map { |dir| HOMEBREW_PREFIX/dir } + must_exist_subdirectories + [ HOMEBREW_CACHE, HOMEBREW_CELLAR, HOMEBREW_LOCKS, HOMEBREW_LOGS, HOMEBREW_REPOSITORY, Language::Python.homebrew_site_packages, ]).sort.uniq.freeze, T.nilable(T::Array[Pathname])) end |
.must_exist_directories ⇒ Array<Pathname>
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.
Keep relatively in sync with https://github.com/Homebrew/install/blob/HEAD/install.sh
162 163 164 165 166 |
# File 'keg.rb', line 162 def self.must_exist_directories @must_exist_directories ||= T.let((must_exist_subdirectories + [ HOMEBREW_CELLAR, ].sort.uniq).freeze, T.nilable(T::Array[Pathname])) end |
.must_exist_subdirectories ⇒ Array<Pathname>
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.
152 153 154 155 156 157 |
# File 'keg.rb', line 152 def self.must_exist_subdirectories @must_exist_subdirectories ||= T.let((keg_link_directories - %w[var] + %w[ opt var/homebrew/linked ]).map { |dir| HOMEBREW_PREFIX/dir }.sort.uniq.freeze, T.nilable(T::Array[Pathname])) end |
.text_matches_in_file(file, string, ignores, linked_libraries, formula_and_runtime_deps_names) ⇒ Array<Array<(String, String)>>
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.
417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 |
# File 'keg_relocate.rb', line 417 def self.text_matches_in_file(file, string, ignores, linked_libraries, formula_and_runtime_deps_names) text_matches = [] path_regex = Relocation.path_to_regex(string) Utils.popen_read("strings", "-t", "x", "-", file.to_s) do |io| until io.eof? str = io.readline.chomp next if ignores.any? { |i| str.match?(i) } next unless str.match? path_regex offset, match = str.split(" ", 2) odie "Failed to parse strings output: #{str.inspect}" unless match # Some binaries contain strings with lists of files # e.g. `/usr/local/lib/foo:/usr/local/share/foo:/usr/lib/foo` # Each item in the list should be checked separately match.split(":").each do |sub_match| # Not all items in the list may be matches next unless sub_match.match? path_regex next if linked_libraries.include? sub_match # Don't bother reporting a string if it was found by otool # Do not report matches to files that do not exist. next unless File.exist? sub_match # Do not report matches to build dependencies. if formula_and_runtime_deps_names.present? begin keg_name = Keg.for(Pathname.new(sub_match)).name next unless formula_and_runtime_deps_names.include? keg_name rescue NotAKegError nil end end text_matches << [match, offset] unless text_matches.any? { |text| text.last == offset } end end end text_matches end |
Instance Method Details
#/(*args, &block) ⇒ T.untyped
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.
10 |
# File 'sorbet/rbi/dsl/keg.rbi', line 10 def /(*args, &block); end |
#abv(*args, &block) ⇒ T.untyped
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 |
# File 'sorbet/rbi/dsl/keg.rbi', line 13 def abv(*args, &block); end |
#aliases ⇒ Array<String>
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.
606 607 608 |
# File 'keg.rb', line 606 def aliases tab.aliases || [] end |
#apps ⇒ Array<Pathname>
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.
440 441 442 443 |
# File 'keg.rb', line 440 def apps app_prefix = optlinked? ? opt_record : path Pathname.glob("#{app_prefix}/{,libexec/}*.app") end |
#binary_executable_or_library_files ⇒ Array<Pathname>
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.
692 693 694 |
# File 'keg.rb', line 692 def binary_executable_or_library_files [] end |
#binary_file?(file) ⇒ Boolean
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.
330 331 332 333 334 335 336 337 |
# File 'keg_relocate.rb', line 330 def binary_file?(file) grep_bin, grep_args = egrep_args # We need to pass NULL_BYTE_STRING, the literal string "\x00", to grep # rather than NULL_BYTE, a literal null byte, because grep will internally # convert the literal string "\x00" to a null byte. Utils.popen_read(grep_bin, *grep_args, NULL_BYTE_STRING, file).present? end |
#codesign_patched_binary(file) ⇒ void
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.
This method returns an undefined value.
697 |
# File 'keg.rb', line 697 def codesign_patched_binary(file); end |
#completion_installed?(shell) ⇒ Boolean
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.
406 407 408 409 410 411 412 413 414 415 416 |
# File 'keg.rb', line 406 def completion_installed?(shell) dir = case shell when :bash then path/"etc/bash_completion.d" when :fish then path/"share/fish/vendor_completions.d" when :zsh dir = path/"share/zsh/site-functions" dir if dir.directory? && dir.children.any? { |f| f.basename.to_s.start_with?("_") } when :pwsh then path/"share/pwsh/completions" end !dir.nil? && dir.directory? && !dir.children.empty? end |
#consistent_reproducible_symlink_permissions! ⇒ void
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.
This method returns an undefined value.
581 |
# File 'keg.rb', line 581 def ; end |
#delete_pyc_files! ⇒ void
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.
This method returns an undefined value.
627 628 629 630 |
# File 'keg.rb', line 627 def delete_pyc_files! path.find { |pn| pn.delete if PYC_EXTENSIONS.include?(pn.extname) } path.find { |pn| FileUtils.rm_rf pn if pn.basename.to_s == "__pycache__" } end |
#detect_cxx_stdlibs(_options = {}) ⇒ Array<Symbol>
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.
290 291 292 |
# File 'keg_relocate.rb', line 290 def detect_cxx_stdlibs( = {}) [] end |
#directory?(*args, &block) ⇒ Boolean
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.
16 |
# File 'sorbet/rbi/dsl/keg.rbi', line 16 def directory?(*args, &block); end |
#disk_usage(*args, &block) ⇒ T.untyped
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.
19 |
# File 'sorbet/rbi/dsl/keg.rbi', line 19 def disk_usage(*args, &block); end |
#each_unique_file_matching(string, &_block) ⇒ void
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.
This method returns an undefined value.
313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 |
# File 'keg_relocate.rb', line 313 def each_unique_file_matching(string, &_block) Utils.popen_read("fgrep", recursive_fgrep_args, string, to_s) do |io| hardlinks = Set.new until io.eof? file = Pathname.new(io.readline.chomp) # Don't return symbolic links. next if file.symlink? # To avoid returning hardlinks, only return files with unique inodes. # Hardlinks will have the same inode as the file they point to. yield file if hardlinks.add? file.stat.ino end end end |
#egrep_args ⇒ Array<(String, Array<String>)>
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.
301 302 303 304 305 306 307 308 309 310 |
# File 'keg_relocate.rb', line 301 def egrep_args grep_bin = "grep" grep_args = [ "--files-with-matches", "--perl-regexp", "--binary-files=text", ] [grep_bin, grep_args] end |
#elisp_installed? ⇒ Boolean
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.
446 447 448 449 450 |
# File 'keg.rb', line 446 def elisp_installed? return false unless (path/"share/emacs/site-lisp"/name).exist? (path/"share/emacs/site-lisp"/name).children.any? { |f| ELISP_EXTENSIONS.include? f.extname } end |
#empty_installation? ⇒ Boolean
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.
243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 |
# File 'keg.rb', line 243 def empty_installation? Pathname.glob("#{path}/*") do |file| return false if file.directory? && !file.children.reject(&:ds_store?).empty? basename = file.basename.to_s require "metafiles" next if Metafiles.copy?(basename) next if %w[.DS_Store INSTALL_RECEIPT.json].include?(basename) return false end true end |
#exist?(*args, &block) ⇒ Boolean
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.
22 |
# File 'sorbet/rbi/dsl/keg.rbi', line 22 def exist?(*args, &block); end |
#file_count(*args, &block) ⇒ T.untyped
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.
25 |
# File 'sorbet/rbi/dsl/keg.rbi', line 25 def file_count(*args, &block); end |
#find(*args, &block) ⇒ T.untyped
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.
28 |
# File 'sorbet/rbi/dsl/keg.rbi', line 28 def find(*args, &block); end |
#fix_dynamic_linkage ⇒ void
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.
This method returns an undefined value.
72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 |
# File 'keg_relocate.rb', line 72 def fix_dynamic_linkage symlink_files.each do |file| link = file.readlink # Don't fix relative symlinks next unless link.absolute? link_starts_cellar = link.to_s.start_with?(HOMEBREW_CELLAR.to_s) link_starts_prefix = link.to_s.start_with?(HOMEBREW_PREFIX.to_s) next if !link_starts_cellar && !link_starts_prefix new_src = link.relative_path_from(file.parent) file.unlink FileUtils.ln_s(new_src, file) end end |
#functions_installed?(shell) ⇒ Boolean
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.
419 420 421 422 423 424 425 426 427 428 429 430 431 432 |
# File 'keg.rb', line 419 def functions_installed?(shell) case shell when :fish dir = path/"share/fish/vendor_functions.d" dir.directory? && !dir.children.empty? when :zsh # Check for non completion functions (i.e. files not started with an underscore), # since those can be checked separately dir = path/"share/zsh/site-functions" dir.directory? && dir.children.any? { |f| !f.basename.to_s.start_with?("_") } else false end end |
#homebrew_created_file?(file) ⇒ Boolean
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.
211 212 213 214 215 |
# File 'keg_relocate.rb', line 211 def homebrew_created_file?(file) return false unless file.basename.to_s.start_with?("homebrew.") %w[.plist .service .timer].include?(file.extname) end |
#ignore_interrupts_and_uninstall! ⇒ void
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.
This method returns an undefined value.
346 347 348 349 350 |
# File 'keg.rb', line 346 def ignore_interrupts_and_uninstall! ignore_interrupts do uninstall end end |
#join(*args, &block) ⇒ T.untyped
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.
34 |
# File 'sorbet/rbi/dsl/keg.rbi', line 34 def join(*args, &block); end |
#keepme_refs ⇒ Array<String>
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.
684 685 686 687 688 689 |
# File 'keg.rb', line 684 def keepme_refs keepme = path/KEEPME_FILE return [] if !keepme.exist? || !keepme.readable? keepme.readlines.select { |ref| File.exist?(ref.strip) } end |
#lib ⇒ Pathname
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.
340 341 342 |
# File 'keg_relocate.rb', line 340 def lib path/"lib" end |
#libexec ⇒ Pathname
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.
345 346 347 |
# File 'keg_relocate.rb', line 345 def libexec path/"libexec" end |
#libtool_files ⇒ Array<Pathname>
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.
392 393 394 395 396 397 398 399 400 401 |
# File 'keg_relocate.rb', line 392 def libtool_files libtool_files = [] path.find do |pn| next if pn.symlink? || pn.directory? || Keg::LIBTOOL_EXTENSIONS.exclude?(pn.extname) libtool_files << pn end libtool_files end |
#link(verbose: false, dry_run: false, overwrite: false) ⇒ Integer
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.
488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 |
# File 'keg.rb', line 488 def link(verbose: false, dry_run: false, overwrite: false) raise AlreadyLinkedError, self if linked_keg_record.directory? ObserverPathnameExtension.reset_counts! optlink(verbose:, dry_run:, overwrite:) unless dry_run # yeah indeed, you have to force anything you need in the main tree into # these dirs REMEMBER that *NOT* everything needs to be in the main tree link_dir("etc", verbose:, dry_run:, overwrite:) { :mkpath } link_dir("bin", verbose:, dry_run:, overwrite:) { :skip_dir } link_dir("sbin", verbose:, dry_run:, overwrite:) { :skip_dir } link_dir("include", verbose:, dry_run:, overwrite:) do |relative_path| case relative_path.to_s when /^postgresql@\d+/ :mkpath else :link end end link_dir("share", verbose:, dry_run:, overwrite:) do |relative_path| case relative_path.to_s when INFOFILE_RX then :info when "locale/locale.alias", %r{^icons/.*/icon-theme\.cache$} :skip_file when LOCALEDIR_RX, %r{^icons/}, # all icons subfolders should also mkpath /^zsh/, /^fish/, %r{^lua/}, # Lua, Lua51, Lua53 all need the same handling. %r{^guile/}, /^postgresql@\d+/, /^pypy/, *SHARE_PATHS :mkpath else :link end end link_dir("lib", verbose:, dry_run:, overwrite:) do |relative_path| case relative_path.to_s when "charset.alias" :skip_file when "pkgconfig", # pkg-config database gets explicitly created "cmake", # cmake database gets explicitly created "dtrace", # lib/language folders also get explicitly created /^gdk-pixbuf/, "ghc", /^gio/, /^lua/, /^mecab/, /^node/, /^ocaml/, /^perl5/, "php", /^postgresql@\d+/, /^pypy/, /^python[23]\.\d+/, /^R/, /^ruby/ :mkpath else # Everything else is symlinked to the Cellar :link end end link_dir("Frameworks", verbose:, dry_run:, overwrite:) do |relative_path| # Frameworks contain symlinks pointing into a subdir, so we have to use # the :link strategy. However, for Foo.framework and # Foo.framework/Versions we have to use :mkpath so that multiple formulae # can link their versions into it and `brew [un]link` works. if relative_path.to_s.match?(%r{[^/]*\.framework(/Versions)?$}) :mkpath else :link end end make_relative_symlink(linked_keg_record, path, verbose:, dry_run:, overwrite:) unless dry_run rescue LinkError unlink(verbose:) raise else ObserverPathnameExtension.n end |
#linked? ⇒ Boolean
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.
263 264 265 266 267 |
# File 'keg.rb', line 263 def linked? linked_keg_record.symlink? && linked_keg_record.directory? && path == linked_keg_record.resolved_path end |
#lock(&_block) ⇒ void
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.
This method returns an undefined value.
393 394 395 396 397 398 399 400 401 402 403 |
# File 'keg.rb', line 393 def lock(&_block) FormulaLock.new(name).with_lock do oldname_locks = oldname_opt_records.map do |record| FormulaLock.new(record.basename.to_s) end oldname_locks.each(&:lock) yield ensure oldname_locks&.each(&:unlock) end end |
#new_usr_local_replacement_pairs ⇒ Hash{Symbol => Hash{Symbol => String}}
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.
94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 |
# File 'keg_relocate.rb', line 94 def new_usr_local_replacement_pairs { prefix: { old: "/usr/local/opt", new: "#{PREFIX_PLACEHOLDER}/opt", }, caskroom: { old: "/usr/local/Caskroom", new: "#{PREFIX_PLACEHOLDER}/Caskroom", }, etc_name: { old: "/usr/local/etc/#{name}", new: "#{PREFIX_PLACEHOLDER}/etc/#{name}", }, var_homebrew: { old: "/usr/local/var/homebrew", new: "#{PREFIX_PLACEHOLDER}/var/homebrew", }, var_www: { old: "/usr/local/var/www", new: "#{PREFIX_PLACEHOLDER}/var/www", }, var_name: { old: "/usr/local/var/#{name}", new: "#{PREFIX_PLACEHOLDER}/var/#{name}", }, var_log_name: { old: "/usr/local/var/log/#{name}", new: "#{PREFIX_PLACEHOLDER}/var/log/#{name}", }, var_lib_name: { old: "/usr/local/var/lib/#{name}", new: "#{PREFIX_PLACEHOLDER}/var/lib/#{name}", }, var_run_name: { old: "/usr/local/var/run/#{name}", new: "#{PREFIX_PLACEHOLDER}/var/run/#{name}", }, var_db_name: { old: "/usr/local/var/db/#{name}", new: "#{PREFIX_PLACEHOLDER}/var/db/#{name}", }, share_name: { old: "/usr/local/share/#{name}", new: "#{PREFIX_PLACEHOLDER}/share/#{name}", }, } end |
#normalize_pod2man_outputs! ⇒ void
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.
This method returns an undefined value.
633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 |
# File 'keg.rb', line 633 def normalize_pod2man_outputs! # Only process uncompressed manpages, which end in a digit manpages = Dir[path/"share/man/*/*.[1-9]{,p,pm}"] generated_regex = /^\.\\"\s*Automatically generated by .*\n/ manpages.each do |f| manpage = Pathname.new(f) next unless manpage.file? content = manpage.read unless content.valid_encoding? # Occasionally, a manpage might not be encoded as UTF-8. ISO-8859-1 is a # common alternative that's worth trying in this case. content = File.read(manpage, encoding: "ISO-8859-1") # If the encoding is still invalid, we can't do anything about it. next unless content.valid_encoding? end content = content.gsub(generated_regex, "") content = content.lines.map do |line| if line.start_with?(".TH") # Split the line by spaces, but preserve quoted strings parts = line.split(/\s(?=(?:[^"]|"[^"]*")*$)/) next line if parts.length != 6 # pod2man embeds the perl version used into the 5th field of the footer parts[4]&.gsub!(/^"perl v.*"$/, "\"\"") # man extension remove in man files parts[2]&.gsub!(/([1-9])(?:pm|p)?/, "\\1") "#{parts.join(" ")}\n" elsif line.start_with?(".IX") # Split the line by spaces, but preserve quoted strings parts = line.split(/\s(?=(?:[^"]|"[^"]*")*$)/) next line if parts.length != 3 next line if parts[1] != "Title" # man extension remove in man files parts[2]&.gsub!(/([1-9])(?:pm|p)?/, "\\1") "#{parts.join(" ")}\n" else line end end.join manpage.atomic_write(content) end end |
#oldname_opt_records ⇒ Array<Pathname>
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.
475 476 477 478 479 480 481 482 483 484 485 |
# File 'keg.rb', line 475 def oldname_opt_records return @oldname_opt_records unless @oldname_opt_records.empty? @oldname_opt_records = if (opt_dir = HOMEBREW_PREFIX/"opt").directory? opt_dir.subdirs.select do |dir| dir.symlink? && dir != opt_record && path.parent == dir.resolved_path.parent end else [] end end |
#openjdk_dep_name_if_applicable ⇒ String?
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.
202 203 204 205 206 207 208 |
# File 'keg_relocate.rb', line 202 def openjdk_dep_name_if_applicable deps = runtime_dependencies return if deps.blank? dep_names = deps.map { |d| d["full_name"] } dep_names.find { |d| d.match? Version.formula_optionally_versioned_regex(:openjdk) } end |
#optlink(verbose: false, dry_run: false, overwrite: false) ⇒ void
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.
This method returns an undefined value.
611 612 613 614 615 616 617 618 619 620 621 622 623 624 |
# File 'keg.rb', line 611 def optlink(verbose: false, dry_run: false, overwrite: false) opt_record.delete if opt_record.symlink? || opt_record.exist? make_relative_symlink(opt_record, path, verbose:, dry_run:, overwrite:) aliases.each do |a| alias_opt_record = opt_record.parent/a alias_opt_record.delete if alias_opt_record.symlink? || alias_opt_record.exist? make_relative_symlink(alias_opt_record, path, verbose:, dry_run:, overwrite:) end oldname_opt_records.each do |record| record.delete make_relative_symlink(record, path, verbose:, dry_run:, overwrite:) end end |
#optlinked? ⇒ Boolean
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.
276 277 278 |
# File 'keg.rb', line 276 def optlinked? opt_record.symlink? && path == opt_record.resolved_path end |
#plist_installed? ⇒ Boolean
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.
435 436 437 |
# File 'keg.rb', line 435 def plist_installed? !Dir["#{path}/*.plist"].empty? end |
#prepare_debug_symbols ⇒ void
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.
This method returns an undefined value.
578 |
# File 'keg.rb', line 578 def prepare_debug_symbols; end |
#prepare_relocation_to_locations ⇒ Relocation
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.
180 181 182 183 184 185 186 187 188 189 190 191 192 |
# File 'keg_relocate.rb', line 180 def prepare_relocation_to_locations relocation = Relocation.new relocation.add_replacement_pair(:prefix, PREFIX_PLACEHOLDER, HOMEBREW_PREFIX.to_s) relocation.add_replacement_pair(:cellar, CELLAR_PLACEHOLDER, HOMEBREW_CELLAR.to_s) relocation.add_replacement_pair(:repository, REPOSITORY_PLACEHOLDER, HOMEBREW_REPOSITORY.to_s) relocation.add_replacement_pair(:library, LIBRARY_PLACEHOLDER, HOMEBREW_LIBRARY.to_s) relocation.add_replacement_pair(:perl, PERL_PLACEHOLDER, "#{HOMEBREW_PREFIX}/opt/perl/bin/perl") if (openjdk = openjdk_dep_name_if_applicable) relocation.add_replacement_pair(:java, JAVA_PLACEHOLDER, "#{HOMEBREW_PREFIX}/opt/#{openjdk}/libexec") end relocation end |
#prepare_relocation_to_placeholders(new_usr_local_relocation: new_usr_local_relocation?) ) ⇒ Relocation
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.
144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 |
# File 'keg_relocate.rb', line 144 def prepare_relocation_to_placeholders(new_usr_local_relocation: new_usr_local_relocation?) relocation = Relocation.new # Use selective HOMEBREW_PREFIX replacement when HOMEBREW_PREFIX=/usr/local # This avoids overzealous replacement of system paths when a script refers to e.g. /usr/local/bin if new_usr_local_relocation new_usr_local_replacement_pairs.each do |key, value| relocation.add_replacement_pair(key, value.fetch(:old), value.fetch(:new), path: true) end else relocation.add_replacement_pair(:prefix, HOMEBREW_PREFIX.to_s, PREFIX_PLACEHOLDER, path: true) end relocation.add_replacement_pair(:cellar, HOMEBREW_CELLAR.to_s, CELLAR_PLACEHOLDER, path: true) # when HOMEBREW_PREFIX == HOMEBREW_REPOSITORY we should use HOMEBREW_PREFIX for all relocations to avoid # being unable to differentiate between them. if HOMEBREW_PREFIX != HOMEBREW_REPOSITORY relocation.add_replacement_pair(:repository, HOMEBREW_REPOSITORY.to_s, REPOSITORY_PLACEHOLDER, path: true) end relocation.add_replacement_pair(:library, HOMEBREW_LIBRARY.to_s, LIBRARY_PLACEHOLDER, path: true) relocation.add_replacement_pair(:perl, %r{\A#![ \t]*(?:/usr/bin/perl\d\.\d+|#{HOMEBREW_PREFIX}/opt/perl/bin/perl)( |$)}o, "#!#{PERL_PLACEHOLDER}\\1") relocation.add_replacement_pair(:java, JAVA_REGEX, JAVA_PLACEHOLDER) relocation end |
#rack ⇒ Pathname
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.
219 220 221 |
# File 'keg.rb', line 219 def rack path.parent end |
#recursive_fgrep_args ⇒ String
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.
295 296 297 298 |
# File 'keg_relocate.rb', line 295 def recursive_fgrep_args # for GNU grep; overridden for BSD grep on OS X "-lr" end |
#relocate_build_prefix(keg, old_prefix, new_prefix) ⇒ void
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.
This method returns an undefined value.
250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 |
# File 'keg_relocate.rb', line 250 def relocate_build_prefix(keg, old_prefix, new_prefix) each_unique_file_matching(old_prefix) do |file| # Skip files which are not binary, as they do not need null padding. next unless keg.binary_file?(file) # Skip sharballs, which appear to break if patched. next if file.text_executable? # Split binary by null characters into array and substitute new prefix for old prefix. # Null padding is added if the new string is too short. file.ensure_writable do binary = File.binread file odebug "Replacing build prefix in: #{file}" binary_strings = binary.split(/#{NULL_BYTE}/o, -1) match_indices = binary_strings.each_index.select { |i| binary_strings.fetch(i).include?(old_prefix.to_s) } # Only perform substitution on strings which match prefix regex. match_indices.each do |i| s = binary_strings.fetch(i) binary_strings[i] = s.gsub(old_prefix.to_s, new_prefix.to_s) .ljust(s.size, NULL_BYTE) end # Rejoin strings by null bytes. patched_binary = binary_strings.join(NULL_BYTE) if patched_binary.size != binary.size raise <<~EOS Patching failed! Original and patched binary sizes do not match. Original size: #{binary.size} Patched size: #{patched_binary.size} EOS end file.atomic_write patched_binary end codesign_patched_binary(file.to_s) end end |
#relocate_dynamic_linkage(_relocation, skip_protodesc_cold: false) ⇒ void
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.
This method returns an undefined value.
89 |
# File 'keg_relocate.rb', line 89 def relocate_dynamic_linkage(_relocation, skip_protodesc_cold: false); end |
#remove_linked_keg_record ⇒ void
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.
This method returns an undefined value.
270 271 272 273 |
# File 'keg.rb', line 270 def remove_linked_keg_record linked_keg_record.unlink linked_keg_record.parent.rmdir_if_possible end |
#remove_old_aliases ⇒ void
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.
This method returns an undefined value.
281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 |
# File 'keg.rb', line 281 def remove_old_aliases opt = opt_record.parent linkedkegs = linked_keg_record.parent tap = begin to_formula.tap rescue # If the formula can't be found, just ignore aliases for now. nil end if tap bad_tap_opt = opt/tap.user FileUtils.rm_rf bad_tap_opt if !bad_tap_opt.symlink? && bad_tap_opt.directory? end aliases.each do |a| # versioned aliases are handled below next if a.match?(/.+@./) remove_alias_symlink(opt/a, opt_record) remove_alias_symlink(linkedkegs/a, linked_keg_record) end Pathname.glob("#{opt_record}@*").each do |a| a = a.basename.to_s next if aliases.include?(a) remove_alias_symlink(opt/a, rack) remove_alias_symlink(linkedkegs/a, rack) end end |
#remove_oldname_opt_records ⇒ void
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.
This method returns an undefined value.
584 585 586 587 588 589 590 591 592 |
# File 'keg.rb', line 584 def remove_oldname_opt_records oldname_opt_records.reject! do |record| return false if record.resolved_path != path record.unlink record.parent.rmdir_if_possible true end end |
#remove_opt_record ⇒ void
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.
This method returns an undefined value.
315 316 317 318 |
# File 'keg.rb', line 315 def remove_opt_record opt_record.unlink opt_record.parent.rmdir_if_possible end |
#rename(*args, &block) ⇒ T.untyped
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.
37 |
# File 'sorbet/rbi/dsl/keg.rbi', line 37 def rename(*args, &block); end |
#replace_locations_with_placeholders ⇒ Array<Pathname>
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.
173 174 175 176 177 |
# File 'keg_relocate.rb', line 173 def replace_locations_with_placeholders relocation = prepare_relocation_to_placeholders.freeze relocate_dynamic_linkage(relocation, skip_protodesc_cold: true) replace_text_in_files(relocation) end |
#replace_placeholders_with_locations(files, skip_linkage: false) ⇒ void
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.
This method returns an undefined value.
195 196 197 198 199 |
# File 'keg_relocate.rb', line 195 def replace_placeholders_with_locations(files, skip_linkage: false) relocation = prepare_relocation_to_locations.freeze relocate_dynamic_linkage(relocation) unless skip_linkage replace_text_in_files(relocation, files:) end |
#replace_text_in_files(relocation, files: nil) ⇒ Array<Pathname>
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.
218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 |
# File 'keg_relocate.rb', line 218 def replace_text_in_files(relocation, files: nil) files ||= text_files | libtool_files changed_files = T.let([], T::Array[Pathname]) files.map { path.join(it) }.group_by { |f| f.stat.ino }.each_value do |first, *rest| first = T.must(first) s = first.open("rb", &:read) # Use full prefix replacement for Homebrew-created files when using selective relocation file_relocation = if new_usr_local_relocation? && homebrew_created_file?(first) prepare_relocation_to_placeholders(new_usr_local_relocation: false) else relocation end next unless file_relocation.replace_text!(s) changed_files += [first, *rest].map { |file| file.relative_path_from(path) } begin first.atomic_write(s) rescue SystemCallError first.ensure_writable do first.open("wb") { |f| f.write(s) } end else rest.each { |file| FileUtils.ln(first, file, force: true) } end end changed_files end |
#require_relocation? ⇒ Boolean
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.
260 |
# File 'keg.rb', line 260 def require_relocation? = @require_relocation |
#runtime_dependencies ⇒ Array<T.untyped>?
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.
600 601 602 603 |
# File 'keg.rb', line 600 def runtime_dependencies Keg.cache[:runtime_dependencies] ||= {} Keg.cache[:runtime_dependencies][path] ||= tab.runtime_dependencies end |
#scheme_and_version ⇒ Array<(Integer, PkgVersion)>
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.
For ordering kegs by version with .sort_by, .max_by, etc.
465 466 467 |
# File 'keg.rb', line 465 def scheme_and_version [version_scheme, version] end |
#symlink_files ⇒ Array<Pathname>
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.
404 405 406 407 408 409 410 411 |
# File 'keg_relocate.rb', line 404 def symlink_files symlink_files = [] path.find do |pn| symlink_files << pn if pn.symlink? end symlink_files end |
#tab ⇒ Tab
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.
595 596 597 |
# File 'keg.rb', line 595 def tab Tab.for_keg(self) end |
#text_files ⇒ Array<Pathname>
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.
350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 |
# File 'keg_relocate.rb', line 350 def text_files text_files = [] return text_files if !which("file") || !which("xargs") files = Set.new path.find.reject { |pn| next true if pn.symlink? next true if pn.directory? next false if pn.basename.to_s == "orig-prefix.txt" # for python virtualenvs next true if pn == self/".brew/#{name}.rb" require "metafiles" next true if Metafiles::EXTENSIONS.include?(pn.extname) if pn.text_executable? text_files << pn next true end false } output, _status = Open3.capture2("xargs -0 file --no-dereference --print0", stdin_data: files.to_a.join("\0")) # `file` output sometimes contains data from the file, which may include # invalid UTF-8 entities, so tell Ruby this is just a bytestring output.force_encoding(Encoding::ASCII_8BIT) output.each_line do |line| path, info = line.split("\0", 2) # `file` sometimes prints more than one line of output per file; # subsequent lines do not contain a null-byte separator, so `info` # will be `nil` for those lines next unless info next unless info.include?("text") path = Pathname.new(path) next unless files.include?(path) text_files << path end text_files end |
#to_formula ⇒ Formula
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.
470 471 472 |
# File 'keg.rb', line 470 def to_formula Formulary.from_keg(self) end |
#to_path(*args, &block) ⇒ T.untyped
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.
40 |
# File 'sorbet/rbi/dsl/keg.rbi', line 40 def to_path(*args, &block); end |
#uninstall(raise_failures: false) ⇒ void
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.
This method returns an undefined value.
321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 |
# File 'keg.rb', line 321 def uninstall(raise_failures: false) CacheStoreDatabase.use(:linkage) do |db| break unless db.created? LinkageCacheStore.new(path.to_s, T.cast(db, CacheStoreDatabase[String, T::Hash[T.any(String, Symbol), T.anything]])).delete! end FileUtils.rm_r(path) path.parent.rmdir_if_possible remove_opt_record if optlinked? remove_linked_keg_record if linked? remove_old_aliases remove_oldname_opt_records rescue Errno::EACCES, Errno::ENOTEMPTY raise if raise_failures odie <<~EOS Could not remove #{name} keg! Do so manually: sudo rm -rf #{path} EOS end |
#unlink(verbose: false, dry_run: false) ⇒ Integer
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.
353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 |
# File 'keg.rb', line 353 def unlink(verbose: false, dry_run: false) ObserverPathnameExtension.reset_counts! dirs = [] keg_directories = self.class.keg_link_directories.map { |d| path/d }.select(&:exist?) keg_directories.each do |dir| dir.find do |src| dst = HOMEBREW_PREFIX + src.relative_path_from(path) dst.extend(ObserverPathnameExtension) dirs << dst if dst.directory? && !dst.symlink? # check whether the file to be unlinked is from the current keg first next unless dst.symlink? next if src != dst.resolved_path if dry_run puts dst Find.prune if src.directory? next end dst.uninstall_info if dst.to_s.match?(INFOFILE_RX) dst.unlink Find.prune if src.directory? end end unless dry_run remove_old_aliases remove_linked_keg_record if linked? (dirs - self.class.must_exist_subdirectories).reverse_each(&:rmdir_if_possible) end ObserverPathnameExtension.n end |
#version ⇒ PkgVersion
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.
453 454 455 |
# File 'keg.rb', line 453 def version PkgVersion.parse(path.basename.to_s) end |
#version_scheme ⇒ Integer
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.
458 459 460 |
# File 'keg.rb', line 458 def version_scheme @version_scheme ||= T.let(tab.version_scheme, T.nilable(Integer)) end |