Module: FormulaCellarChecks Abstract Private

Extended by:
T::Helpers
Includes:
OS::Linux::FormulaCellarChecks, OS::Mac::FormulaCellarChecks
Included in:
FormulaInstaller, Homebrew::FormulaAuditor
Defined in:
formula_cellar_checks.rb

Overview

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

This module is abstract.

Subclasses must implement the abstract methods below.

Checks to perform on a formula's keg (versioned Cellar path).

Constant Summary collapse

VALID_LIBRARY_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[.a .jnilib .la .o .so .jar .prl .pm .sh].freeze

Constants included from OS::Mac::FormulaCellarChecks

OS::Mac::FormulaCellarChecks::MACOS_LIB_EXTENSIONS

Instance Method Summary collapse

Methods included from OS::Mac::FormulaCellarChecks

#check_flat_namespace, #check_linkage, #check_openssl_links, #check_python_framework_links, #check_shadowed_headers

Instance Method Details

#audit_installed ⇒ 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.



563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
# File 'formula_cellar_checks.rb', line 563

def audit_installed
  @new_formula ||= T.let(false, T.nilable(T::Boolean))
  @strict ||= T.let(false, T.nilable(T::Boolean))

  problem_if_output(check_manpages)
  problem_if_output(check_infopages)
  problem_if_output(check_jars)
  problem_if_output(check_service_command(formula))
  problem_if_output(check_non_libraries) if @new_formula
  problem_if_output(check_non_executables(formula.bin))
  problem_if_output(check_generic_executables(formula.bin))
  problem_if_output(check_non_executables(formula.sbin))
  problem_if_output(check_generic_executables(formula.sbin))
  problem_if_output(check_easy_install_pth(formula.lib))
  problem_if_output(check_elisp_dirname(formula.share, formula.name))
  problem_if_output(check_elisp_root(formula.share, formula.name))
  problem_if_output(check_python_packages(formula.lib, formula.deps))
  problem_if_output(check_shim_references(formula.prefix))
  problem_if_output(check_plist(formula.prefix, formula.launchd_service_path))
  problem_if_output(check_python_symlinks(formula.name, formula.keg_only?))
  problem_if_output(check_cpuid_instruction(formula))
  problem_if_output(check_binary_arches(formula))
  problem_if_output(check_prebuilt_npm_binaries(formula)) if @strict
end

#binary_program?(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.

Parameters:

Returns:

  • (Boolean)


94
95
96
# File 'formula_cellar_checks.rb', line 94

def binary_program?(file)
  file.binary_executable?
end

#check_binary_arches(formula) ⇒ 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.

Parameters:

Returns:



370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
# File 'formula_cellar_checks.rb', line 370

def check_binary_arches(formula)
  return unless formula.prefix.directory?

  keg = Keg.new(formula.prefix)
  mismatches = {}
  keg.binary_executable_or_library_files.each do |file|
    next if !file.is_a?(MachOShim) && !file.is_a?(ELFShim)

    farch = file.arch
    mismatches[file] = farch if farch != Hardware::CPU.arch
  end
  return if mismatches.empty?

  compatible_universal_binaries, mismatches = mismatches.partition do |file, arch|
    arch == :universal && file.archs.include?(Hardware::CPU.arch)
  end
  # To prevent transformation into nested arrays
  compatible_universal_binaries = compatible_universal_binaries.to_h
  mismatches = mismatches.to_h

  universal_binaries_expected = if (formula_tap = formula.tap).present? && formula_tap.core_tap?
    # Apply audit exception to versioned formulae too from the unversioned name.
    formula_name = formula.unversioned_formula_name || formula.name
    formula_tap.audit_exception(:universal_binary_allowlist, formula_name)
  else
    true
  end

  mismatches_expected = (formula_tap = formula.tap).blank? ||
                        formula_tap.audit_exception(:mismatched_binary_allowlist, formula.name)
  mismatches_expected = [mismatches_expected] if mismatches_expected.is_a?(String)
  if mismatches_expected.is_a?(Array)
    glob_flags = File::FNM_DOTMATCH | File::FNM_EXTGLOB | File::FNM_PATHNAME
    mismatches.delete_if do |file, _arch|
      mismatches_expected.any? { |pattern| file.fnmatch?("#{formula.prefix.realpath}/#{pattern}", glob_flags) }
    end
    mismatches_expected = false
    return if mismatches.empty? && compatible_universal_binaries.empty?
  end

  return if mismatches.empty? && universal_binaries_expected
  return if compatible_universal_binaries.empty? && mismatches_expected
  return if universal_binaries_expected && mismatches_expected

  s = ""

  if mismatches.present? && !mismatches_expected
    s += <<~EOS
      Binaries built for a non-native architecture were installed into #{formula}'s prefix.
      The offending files are:
        #{mismatches.map { |m| "#{m.first}\t(#{m.last})" } * "\n  "}
    EOS
  end

  if compatible_universal_binaries.present? && !universal_binaries_expected
    s += <<~EOS
      Unexpected universal binaries were found.
      The offending files are:
        #{compatible_universal_binaries.keys * "\n  "}
    EOS
  end

  s
end

#check_cpuid_instruction(formula) ⇒ 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.

Parameters:

Returns:



324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
# File 'formula_cellar_checks.rb', line 324

def check_cpuid_instruction(formula)
  # Checking for `cpuid` only makes sense on Intel:
  # https://en.wikipedia.org/wiki/CPUID
  return unless Hardware::CPU.intel?

  dot_brew_formula = formula.prefix/".brew/#{formula.name}.rb"
  return unless dot_brew_formula.exist?

  return unless dot_brew_formula.read.include? "ENV.runtime_cpu_detection"
  return if formula.tap&.audit_exception(:no_cpuid_allowlist, formula.name)

  # macOS `objdump` is a bit slow, so we prioritise llvm's `llvm-objdump` (~5.7x faster)
  # or binutils' `objdump` (~1.8x faster) if they are installed.
  if Utils::Path.formula_any_version_installed?("llvm")
    objdump = Utils::Path.formula_opt_bin("llvm")/"llvm-objdump"
  end
  if Utils::Path.formula_any_version_installed?("binutils")
    objdump ||= Utils::Path.formula_opt_bin("binutils")/"objdump"
  end
  objdump ||= which("objdump")
  objdump ||= which("objdump", ORIGINAL_PATHS)

  unless objdump
    return <<~EOS
      No `objdump` found, so cannot check for a `cpuid` instruction. Install `objdump` with
        brew install binutils
    EOS
  end

  keg = Keg.new(formula.prefix)
  return if keg.binary_executable_or_library_files.any? do |file|
    cpuid_instruction?(file, objdump)
  end

  hardlinks = Set.new
  return if formula.lib.directory? && formula.lib.find.any? do |pn|
    next false if pn.symlink? || pn.directory? || pn.extname != ".a"
    next false unless hardlinks.add? [pn.stat.dev, pn.stat.ino]

    cpuid_instruction?(pn, objdump)
  end

  "No `cpuid` instruction detected. #{formula} should not use `ENV.runtime_cpu_detection`."
end

#check_easy_install_pth(lib) ⇒ 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.

Parameters:

Returns:



150
151
152
153
154
155
156
157
158
159
160
161
# File 'formula_cellar_checks.rb', line 150

def check_easy_install_pth(lib)
  pth_found = Dir["#{lib}/python3*/site-packages/easy-install.pth"].map { |f| File.dirname(f) }
  return if pth_found.empty?

  <<~EOS
    'easy-install.pth' files were found.
    These '.pth' files are likely to cause link conflicts.
    Easy install is now deprecated, do not use it.
    The offending files are:
      #{pth_found * "\n  "}
  EOS
end

#check_elisp_dirname(share, name) ⇒ 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.

Parameters:

Returns:



164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
# File 'formula_cellar_checks.rb', line 164

def check_elisp_dirname(share, name)
  return unless (share/"emacs/site-lisp").directory?
  # Emacs itself can do what it wants
  return if name == "emacs"

  bad_dir_name = (share/"emacs/site-lisp").children.any? do |child|
    child.directory? && child.basename.to_s != name
  end

  return unless bad_dir_name

  <<~EOS
    Emacs Lisp files were installed into the wrong "site-lisp" subdirectory.
    They should be installed into:
      #{share}/emacs/site-lisp/#{name}
  EOS
end

#check_elisp_root(share, name) ⇒ 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.

Parameters:

Returns:



183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
# File 'formula_cellar_checks.rb', line 183

def check_elisp_root(share, name)
  return unless (share/"emacs/site-lisp").directory?
  # Emacs itself can do what it wants
  return if name == "emacs"

  elisps = (share/"emacs/site-lisp").children.select do |file|
    Keg::ELISP_EXTENSIONS.include? file.extname
  end
  return if elisps.empty?

  <<~EOS
    Emacs Lisp files were linked directly to "#{HOMEBREW_PREFIX}/share/emacs/site-lisp".
    This may cause conflicts with other packages.
    They should instead be installed into:
      #{share}/emacs/site-lisp/#{name}
    The offending files are:
      #{elisps * "\n  "}
  EOS
end

#check_env_path(bin) ⇒ 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.

Parameters:

Returns:



25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
# File 'formula_cellar_checks.rb', line 25

def check_env_path(bin)
  return if Homebrew::EnvConfig.no_env_hints?

  # warn the user if stuff was installed outside of their PATH
  return unless bin.directory?
  return if bin.children.empty?

  prefix_bin = (HOMEBREW_PREFIX/bin.basename)
  return unless prefix_bin.directory?

  prefix_bin = prefix_bin.realpath
  return if ORIGINAL_PATHS.include? prefix_bin

  <<~EOS
    "#{prefix_bin}" is not in your PATH.
    You can amend this by altering your #{Utils::Shell.profile} file.
  EOS
end

#check_generic_executables(bin) ⇒ 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.

Parameters:

Returns:



132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
# File 'formula_cellar_checks.rb', line 132

def check_generic_executables(bin)
  return unless bin.directory?

  generic_names = %w[service start stop]
  generics = bin.children.select { |g| generic_names.include? g.basename.to_s }
  return if generics.empty?

  <<~EOS
    Generic binaries were installed to "#{bin}".
    Binaries with generic names are likely to conflict with other software.
    Homebrew suggests that this software is installed to "libexec" and then
    symlinked as needed.
    The offending files are:
      #{generics * "\n  "}
  EOS
end

#check_infopages ⇒ 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.

Returns:



57
58
59
60
61
62
63
64
65
66
# File 'formula_cellar_checks.rb', line 57

def check_infopages
  # Check for info pages that aren't in share/info
  return unless (formula.prefix/"info").directory?

  <<~EOS
    A top-level "info" directory was found.
    Homebrew suggests that info pages live under "share".
    This can often be fixed by passing `--infodir=\#{info}` to `configure`.
  EOS
end

#check_jars ⇒ 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.

Returns:



69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
# File 'formula_cellar_checks.rb', line 69

def check_jars
  return unless formula.lib.directory?

  jars = formula.lib.children.select { |g| g.extname == ".jar" }
  return if jars.empty?

  <<~EOS
    JARs were installed to "#{formula.lib}".
    Installing JARs to "lib" can cause conflicts between packages.
    For Java software, it is typically better for the formula to
    install to "libexec" and then symlink or wrap binaries into "bin".
    See formulae 'activemq', 'jruby', etc. for examples.
    The offending files are:
      #{jars * "\n  "}
  EOS
end

#check_manpages ⇒ 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.

Returns:



45
46
47
48
49
50
51
52
53
54
# File 'formula_cellar_checks.rb', line 45

def check_manpages
  # Check for man pages that aren't in share/man
  return unless (formula.prefix/"man").directory?

  <<~EOS
    A top-level "man" directory was found.
    Homebrew requires that man pages live under "share".
    This can often be fixed by passing `--mandir=\#{man}` to `configure`.
  EOS
end

#check_non_executables(bin) ⇒ 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.

Parameters:

Returns:



118
119
120
121
122
123
124
125
126
127
128
129
# File 'formula_cellar_checks.rb', line 118

def check_non_executables(bin)
  return unless bin.directory?

  non_exes = bin.children.select { |g| g.directory? || !g.executable? }
  return if non_exes.empty?

  <<~EOS
    Non-executables were installed to "#{bin}".
    The offending files are:
      #{non_exes * "\n  "}
  EOS
end

#check_non_libraries ⇒ 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.

Returns:



99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
# File 'formula_cellar_checks.rb', line 99

def check_non_libraries
  return unless formula.lib.directory?

  non_libraries = formula.lib.children.reject do |g|
    next true if g.directory?

    valid_library_extension? g
  end
  return if non_libraries.empty?

  <<~EOS
    Non-libraries were installed to "#{formula.lib}".
    Installing non-libraries to "lib" is discouraged.
    The offending files are:
      #{non_libraries * "\n  "}
  EOS
end

#check_plist(prefix, plist) ⇒ 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.

Parameters:

Returns:



265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
# File 'formula_cellar_checks.rb', line 265

def check_plist(prefix, plist)
  return unless prefix.directory?

  require "plist"
  plist = begin
    Plist.parse_xml(plist, marshal: false)
  rescue
    nil
  end
  return if plist.blank?

  program_location = plist["ProgramArguments"]&.first
  key = "first ProgramArguments value"
  if program_location.blank?
    program_location = plist["Program"]
    key = "Program"
  end
  return if program_location.blank?

  Dir.chdir("/") do
    unless File.exist?(program_location)
      return <<~EOS
        The plist "#{key}" does not exist:
          #{program_location}
      EOS
    end

    return if File.executable?(program_location)
  end

  <<~EOS
    The plist "#{key}" is not executable:
      #{program_location}
  EOS
end

#check_prebuilt_npm_binaries(formula) ⇒ 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.

Parameters:

Returns:



436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
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
# File 'formula_cellar_checks.rb', line 436

def check_prebuilt_npm_binaries(formula)
  return unless formula.prefix.directory?

  formula_tap = formula.tap
  return if formula_tap.blank? || !formula_tap.core_tap?

  # Audit exceptions apply to a versioned formula from its unversioned name.
  formula_name = formula.unversioned_formula_name || formula.name
  expected = formula_tap.audit_exception(:prebuilt_binary_allowlist, formula_name)
  return if expected == true

  expected = [expected] if expected.is_a?(String)
  glob_flags = File::FNM_DOTMATCH | File::FNM_EXTGLOB | File::FNM_PATHNAME
  candidates = Keg.new(formula.prefix).binary_executable_or_library_files.select do |file|
    # Prebuilt addons are a policy question of their own, but a downloaded
    # one shows that the helpers shipped beside it could not be built.
    next true if file.extname == ".node"
    next false unless binary_program?(file)

    if expected.is_a?(Array) &&
       expected.any? { |pattern| file.fnmatch?("#{formula.prefix.realpath}/#{pattern}", glob_flags) }
      next false
    end

    true
  end
  return if candidates.all? { |file| file.extname == ".node" }

  cache = Homebrew::PackageManagerCache.path("npm_cache")/"_cacache"
  return unless cache.directory?

  # npm keys a cached response by where it came from: make-fetch-happen uses
  # `request-cache:<url>` and pacote `tarball:<spec>`, so a key ending in an
  # HTTP(S) URL is what it downloaded, while `npm pack` output installed from
  # disk is keyed `file:` and is the formula's own build. Records are appended,
  # so the last one for a key wins and a deletion appends a null integrity.
  records = {}
  (cache/"index-v5").glob("**/*").each do |index|
    next unless index.file?

    index.each_line do |line|
      entry = JSON.parse(line.split("\t", 2).last.to_s)
      next unless entry.is_a?(Hash)

      key = entry["key"].to_s
      url = key[%r{:(https?://\S+)\z}, 1]
      next if url.nil?

      integrity = entry["integrity"]
      records[key] = integrity.is_a?(String) ? [integrity, url] : nil
    rescue JSON::ParserError, TypeError
      next
    end
  end

  # An integrity is `<algorithm>-<base64 digest>` and names the content file,
  # which is stored under the first two byte pairs of that digest in hex.
  hashes = { "sha512" => Digest::SHA512, "sha256" => Digest::SHA256, "sha1" => Digest::SHA1 }
  archives = {}
  records.each_value do |record|
    next if record.nil?

    integrity, url = record
    algorithm, _, encoded = integrity.partition("-")
    hash = hashes[algorithm]
    next if hash.nil?

    hex = encoded.unpack1("m").to_s.unpack1("H*").to_s
    archive = cache/"content-v2"/algorithm/hex.sub(/\A(\h{2})(\h{2})/, '\1/\2/')
    next unless archive.file?

    archives[archive] ||= [url[%r{https?://[^/]+/(.+)/-/}, 1] || File.basename(url), hash, hex]
  end

  # Sizes come from a `stat`, so nothing is hashed until a package carries a
  # file that could match. A gzip stream opens with a magic number, closes
  # with the uncompressed size of its contents, and is never shorter than
  # that header and footer, so anything that cannot hold a candidate is
  # skipped without decompressing it.
  gzip_magic = [0x1F, 0x8B]
  gzip_size_bytes = 4
  smallest_gzip_stream = 18
  by_size = candidates.group_by(&:size)
  minimum_size = by_size.keys.min.to_i
  digests = {}
  prebuilt = {}
  archives.each do |archive, (package, hash, hex)|
    next if archive.size < smallest_gzip_stream
    next if archive.binread(gzip_magic.length)&.unpack("C#{gzip_magic.length}") != gzip_magic

    uncompressed_size = archive.binread(gzip_size_bytes, archive.size - gzip_size_bytes)
    next if uncompressed_size.to_s.unpack1("V").to_i < minimum_size

    # Retaining this cache is only safe because what reads it verifies the
    # digest that named the file, so do that before trusting its contents.
    next if hash.file(archive).hexdigest != hex

    Zlib::GzipReader.open(archive.to_s) do |gzip|
      Gem::Package::TarReader.new(gzip).each do |entry|
        files = by_size[entry.header.size] if entry.file?
        next if files.nil?

        member = Digest::SHA256.hexdigest(entry.read.to_s)
        files.each do |file|
          next if (digests[file] ||= Digest::SHA256.file(file).hexdigest) != member

          prebuilt[file.relative_path_from(formula.prefix)] = "#{entry.full_name} of #{package}"
        end
      end
    end
  rescue Zlib::Error, Gem::Package::Error
    next
  end
  addon_dirs = prebuilt.keys.select { |file| file.extname == ".node" }.map(&:dirname)
  prebuilt.reject! { |file, _source| file.extname == ".node" || addon_dirs.include?(file.dirname) }
  return if prebuilt.empty?

  <<~EOS
    Prebuilt executables from npm packages were installed into #{formula}'s prefix.
    Each is byte-identical to a file in a package npm recorded downloading,
    so it was shipped rather than built from source.
    The offending files are:
      #{prebuilt.map { |file, source| "#{file}\t(#{source})" } * "\n  "}
  EOS
end

#check_python_packages(lib, deps) ⇒ 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.

Parameters:

Returns:



204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
# File 'formula_cellar_checks.rb', line 204

def check_python_packages(lib, deps)
  return unless lib.directory?

  lib_subdirs = lib.children
                   .select(&:directory?)
                   .map(&:basename)

  pythons = lib_subdirs.filter_map do |p|
    match = p.to_s.match(/^python(\d+\.\d+)$/)
    next if match.blank?
    next if match.captures.blank?

    match.captures.first
  end

  return if pythons.blank?

  python_deps = deps.to_a
                    .map(&:name)
                    .grep(/^python(@.*)?$/)
                    .filter_map { |d| Formula[d].version.to_s[/^\d+\.\d+/] }

  return if python_deps.blank?
  return if pythons.intersect?(python_deps)

  pythons = pythons.map { |v| "Python #{v}" }
  python_deps = python_deps.map { |v| "Python #{v}" }

  <<~EOS
    Packages have been installed for:
      #{pythons * "\n  "}
    but this formula depends on:
      #{python_deps * "\n  "}
  EOS
end

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.

Parameters:

  • name (String)
  • keg_only (Boolean)

Returns:



302
303
304
305
306
307
308
309
310
311
312
# File 'formula_cellar_checks.rb', line 302

def check_python_symlinks(name, keg_only)
  return unless keg_only
  return unless name.start_with? "python"

  return if %w[pip3 wheel3].none? do |l|
    link = HOMEBREW_PREFIX/"bin"/l
    link.exist? && File.realpath(link).start_with?(HOMEBREW_CELLAR/name)
  end

  "Python formulae that are keg-only should not create `pip3` and `wheel3` symlinks."
end

#check_service_command(formula) ⇒ 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.

Parameters:

Returns:



315
316
317
318
319
320
321
# File 'formula_cellar_checks.rb', line 315

def check_service_command(formula)
  return unless formula.prefix.directory?
  return unless formula.service?
  return unless formula.service.command?

  "Service command does not exist" unless File.exist?(formula.service.command.first)
end

#check_shim_references(prefix) ⇒ 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.

Parameters:

Returns:



241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
# File 'formula_cellar_checks.rb', line 241

def check_shim_references(prefix)
  return unless prefix.directory?

  keg = Keg.new(prefix)

  matches = []
  keg.each_unique_file_matching(HOMEBREW_SHIMS_PATH.to_s) do |f|
    match = f.relative_path_from(keg.to_path)

    next if match.to_s.match? %r{^share/doc/.+?/INFO_BIN$}

    matches << match
  end

  return if matches.empty?

  <<~EOS
    Files were found with references to the Homebrew shims directory.
    The offending files are:
      #{matches * "\n  "}
  EOS
end

#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.

This method is abstract.

Returns:



19
# File 'formula_cellar_checks.rb', line 19

def formula; end

#problem_if_output(output) ⇒ 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 is abstract.

This method returns an undefined value.

Parameters:



22
# File 'formula_cellar_checks.rb', line 22

def problem_if_output(output); end

#valid_library_extension?(filename) ⇒ 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.

Parameters:

Returns:

  • (Boolean)


89
90
91
# File 'formula_cellar_checks.rb', line 89

def valid_library_extension?(filename)
  VALID_LIBRARY_EXTENSIONS.include? filename.extname
end