Module: Readall Private
- Extended by:
- Cachable, SystemCommand::Mixin, T::Generic, Utils::Output::Mixin
- Defined in:
- readall.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.
Helper module for validating syntax in taps.
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] } }
Class Method Summary collapse
- .valid_aliases?(alias_dir, formula_dir) ⇒ Boolean private
- .valid_casks?(tap, os_name: nil, arch: nil) ⇒ Boolean private
- .valid_formulae?(tap, bottle_tag: nil) ⇒ Boolean private
- .valid_ruby_syntax?(ruby_files) ⇒ Boolean private
- .valid_tap?(tap, aliases: false, no_simulate: false, os_arch_combinations: OnSystem::ALL_OS_ARCH_COMBINATIONS) ⇒ Boolean private
Methods included from Cachable
Methods included from SystemCommand::Mixin
system_command, system_command!
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
Class Method Details
.valid_aliases?(alias_dir, formula_dir) ⇒ 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.
37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 |
# File 'readall.rb', line 37 def self.valid_aliases?(alias_dir, formula_dir) return true unless alias_dir.directory? failed = T.let(false, T::Boolean) alias_dir.each_child do |f| if !f.symlink? onoe "Non-symlink alias: #{f}" failed = true elsif !f.file? onoe "Non-file alias: #{f}" failed = true end if formula_dir.glob("**/#{f.basename}.rb").any?(&:exist?) onoe "Formula duplicating alias: #{f}" failed = true end end !failed end |
.valid_casks?(tap, os_name: nil, arch: nil) ⇒ 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.
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 |
# File 'readall.rb', line 94 def self.valid_casks?(tap, os_name: nil, arch: nil) validating_linux = if os_name.nil? Homebrew::SimulateSystem.current_os == :linux else os_name == :linux end return true unless validating_linux success = T.let(true, T::Boolean) tap.cask_files.each do |file| next if file.read.match?(/^\s*depends_on(?:\s*\(\s*|\s+)(?::macos\b|macos:)/) cask = if arch Homebrew::SimulateSystem.with(os: :macos, arch:) do loaded_cask = Cask::CaskLoader.load(file) loaded_cask if loaded_cask.supports_linux? end else Homebrew::SimulateSystem.with(os: :macos) do loaded_cask = Cask::CaskLoader.load(file) loaded_cask if loaded_cask.supports_linux? end end next unless cask if arch Homebrew::SimulateSystem.with(os: :linux, arch:) { cask.refresh } else Homebrew::SimulateSystem.with(os: :linux) { cask.refresh } end rescue Interrupt raise # Handle all possible exceptions reading casks. rescue Exception => e # rubocop:disable Lint/RescueException os_and_arch = "Linux" os_and_arch += " on #{(arch == :intel) ? "Intel x86_64" : "ARM64"}" if arch onoe "Invalid cask (#{os_and_arch}): #{file}" if e..include?("invalid 'sha256' value: nil") $stderr.puts "Missing Linux stanzas can leave Linux `sha256` as nil. " \ "Add `depends_on :macos` if this cask is macOS-only." end $stderr.puts e success = false end success end |
.valid_formulae?(tap, bottle_tag: nil) ⇒ 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.
59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 |
# File 'readall.rb', line 59 def self.valid_formulae?(tap, bottle_tag: nil) cache[:valid_formulae] ||= {} success = T.let(true, T::Boolean) tap.formula_files.each do |file| valid = cache[:valid_formulae][file] next if valid == true || valid&.include?(bottle_tag) formula_name = file.basename(".rb").to_s formula_contents = file.read.force_encoding("UTF-8") readall_namespace = "ReadallNamespace" readall_formula_class = Formulary.load_formula(formula_name, file, formula_contents, readall_namespace, flags: [], ignore_errors: false) readall_formula = readall_formula_class.new(formula_name, file, :stable, tap:) readall_formula.to_hash # TODO: Remove check for MACOS_MODULE_REGEX once the `MacOS` module is undefined on Linux cache[:valid_formulae][file] = if readall_formula.on_system_blocks_exist? || formula_contents.match?(MACOS_MODULE_REGEX) [bottle_tag, *cache[:valid_formulae][file]] else true end rescue Interrupt raise # Handle all possible exceptions reading formulae. rescue Exception => e # rubocop:disable Lint/RescueException onoe "Invalid formula (#{bottle_tag}): #{file}" $stderr.puts e success = false end success end |
.valid_ruby_syntax?(ruby_files) ⇒ 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.
27 28 29 30 31 32 33 34 |
# File 'readall.rb', line 27 def self.valid_ruby_syntax?(ruby_files) failed = T.let(false, T::Boolean) ruby_files.each do |ruby_file| # As a side effect, print syntax errors/warnings to `$stderr`. failed = true if syntax_errors_or_warnings?(ruby_file) end !failed end |
.valid_tap?(tap, aliases: false, no_simulate: false, os_arch_combinations: OnSystem::ALL_OS_ARCH_COMBINATIONS) ⇒ 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.
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 171 |
# File 'readall.rb', line 146 def self.valid_tap?(tap, aliases: false, no_simulate: false, os_arch_combinations: OnSystem::ALL_OS_ARCH_COMBINATIONS) success = true if aliases valid_aliases = valid_aliases?(tap.alias_dir, tap.formula_dir) success = false unless valid_aliases end if no_simulate success = false unless valid_formulae?(tap) success = false unless valid_casks?(tap) else os_arch_combinations.each do |os, arch| bottle_tag = Utils::Bottles::Tag.new(system: os, arch:) next unless bottle_tag.valid_combination? Homebrew::SimulateSystem.with(os:, arch:) do success = false unless valid_formulae?(tap, bottle_tag:) success = false unless valid_casks?(tap, os_name: os, arch:) end end end success end |