Class: Homebrew::Cmd::FetchCmd Private
- Inherits:
-
AbstractCommand
- Object
- AbstractCommand
- Homebrew::Cmd::FetchCmd
- Includes:
- Fetch
- Defined in:
- cmd/fetch.rb,
sorbet/rbi/dsl/homebrew/cmd/fetch_cmd.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: Args
Constant Summary collapse
- FETCH_MAX_TRIES =
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.
5
Instance Method Summary collapse
- #args ⇒ Homebrew::Cmd::FetchCmd::Args private
- #cask_downloads(cask) ⇒ Array<Cask::Download> private
- #run ⇒ void private
-
#run_fetch_hook(formula) ⇒ void
private
A formula's
fetchruns in the build environment, so it needs the dependencies thatbuild.rbwould put onPATHto be installed.
Methods included from Fetch
Methods inherited from AbstractCommand
command, command_name, dev_cmd?, #initialize, parser, ruby_cmd?
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, #opoo_without_github_actions_annotation, #pretty_cannot_install, #pretty_deprecated, #pretty_disabled, #pretty_duration, #pretty_install_status, #pretty_installed, #pretty_uninstalled, #pretty_unmarked, #pretty_upgradable, #pretty_warning
Constructor Details
This class inherits a constructor from Homebrew::AbstractCommand
Instance Method Details
#args ⇒ Homebrew::Cmd::FetchCmd::Args
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/homebrew/cmd/fetch_cmd.rbi', line 10 def args; end |
#cask_downloads(cask) ⇒ Array<Cask::Download>
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.
182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 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 239 240 |
# File 'cmd/fetch.rb', line 182 def cask_downloads(cask) ref = cask.reloadable_ref if args.all_platforms? && cask.loaded_from_api? opoo "Cask #{cask} was loaded from the API; cannot fetch all operating system and " \ "architecture variants. Set `HOMEBREW_NO_INSTALL_FROM_API=1` to fetch them all." end # With `--all-platforms`, a cask without `on_system` blocks resolves # identically everywhere, so one combination covers the whole matrix. cask_combinations = args.os_arch_combinations cask_combinations = cask_combinations.first(1) if args.all_platforms? && !cask.on_system_blocks_exist? downloads = T.let([], T::Array[Cask::Download]) enqueued_urls = Set.new cask_combinations.each do |os, arch| SimulateSystem.with(os:, arch:) do loaded_cask = begin Cask::CaskLoader.load(ref) rescue Cask::CaskInvalidError, Cask::CaskUnreadableError raise unless cask.on_system_blocks_exist? end if loaded_cask.nil? || loaded_cask.depends_on.arch&.none? { |dep_arch| dep_arch[:type] == arch } opoo "Cask #{cask} is not supported on os #{os} and arch #{arch}" next end languages = (loaded_cask.languages if args.all_platforms?) languages = [nil] if languages.blank? languages.each do |language| localized_cask = loaded_cask if language # Reload per language: `Cask::Download` reads `sha256`/`url` # lazily, so each download needs its own cask instance. localized_cask = Cask::CaskLoader.load(ref) localized_cask.config = localized_cask.config.merge( Cask::Config.new(explicit: { languages: [language] }), ) end if localized_cask.url.nil? || localized_cask.sha256.nil? opoo "Cask #{cask} is not supported on os #{os} and arch #{arch}" next end next unless enqueued_urls.add?(localized_cask.url.to_s) downloads << Cask::Download.new( localized_cask, require_sha: Homebrew::EnvConfig.cask_opts_require_sha?, ) end end end downloads end |
#run ⇒ 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.
80 81 82 83 84 85 86 87 88 89 90 91 92 93 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 142 143 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 171 172 173 174 175 176 177 178 179 |
# File 'cmd/fetch.rb', line 80 def run Formulary.enable_factory_cache! if enqueue_api_formula_bottles? || enqueue_api_cask_downloads? download_queue.fetch return end bucket = if args.deps? args.named.to_formulae_and_casks.flat_map do |formula_or_cask| case formula_or_cask when Formula formula = formula_or_cask [formula, *formula.recursive_dependencies.map(&:to_formula)] else formula_or_cask end end else args.named.to_formulae_and_casks end.uniq os_arch_combinations = args.os_arch_combinations current_os_arch = [SimulateSystem.current_os, SimulateSystem.current_arch] fetch_hook_formulae = T.let([], T::Array[Formula]) puts "Fetching: #{bucket * ", "}" if bucket.size > 1 bucket.each do |formula_or_cask| case formula_or_cask when Formula formula = formula_or_cask ref = formula.reloadable_ref os_arch_combinations.each do |os, arch| SimulateSystem.with(os:, arch:) do formula = Formulary.factory(ref, args.HEAD? ? :head : :stable) formula.print_tap_action verb: "Fetching" fetched_bottle = false if fetch_bottle?( formula, force_bottle: args.force_bottle?, bottle_tag: args.bottle_tag&.to_sym, build_from_source_formulae: args.build_from_source_formulae, os: args.os&.to_sym, arch: args.arch&.to_sym, ) begin formula.clear_cache if args.force? bottle_tag = Utils::Bottles::Tag.from_arg(args.bottle_tag&.to_sym, os:, arch:) bottle = formula.bottle_for_tag(bottle_tag) if bottle.nil? opoo "Bottle for tag #{bottle_tag.to_sym.inspect} is unavailable." next end if (manifest_resource = bottle.github_packages_manifest_resource) download_queue.enqueue(manifest_resource) end download_queue.enqueue(bottle) rescue Interrupt raise rescue => e raise if Homebrew::EnvConfig.developer? fetched_bottle = false onoe e. opoo "Bottle fetch failed, fetching the source instead." else fetched_bottle = true end end next if fetched_bottle if (resource = formula.resource) download_queue.enqueue(resource) end formula.enqueue_resources_and_patches(download_queue:) fetch_hook_formulae << formula if [os, arch] == current_os_arch end end when Cask::Cask cask_downloads(formula_or_cask).each { |download| download_queue.enqueue(download) } else odie "Invalid formula or cask: #{formula_or_cask}" end end download_queue.fetch fetch_hook_formulae.each { |formula| run_fetch_hook(formula) } ensure download_queue.shutdown end |
#run_fetch_hook(formula) ⇒ 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.
A formula's fetch runs in the build environment, so it needs the
dependencies that build.rb would put on PATH to be installed.
245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 |
# File 'cmd/fetch.rb', line 245 def run_fetch_hook(formula) formula = Homebrew::API::Formula.source_download_formula(formula) if formula.loaded_from_api? return unless formula.fetch_defined? missing_dependencies = formula.recursive_dependencies do |_dependent, dependency| next Dependable::PRUNE if dependency.implicit? || dependency.optional? next Dependable::PRUNE if dependency.test? && !dependency.build? end.map(&:to_formula).reject(&:any_version_installed?) if missing_dependencies.present? opoo <<~EOS Not running #{formula.full_name}'s `fetch` as these dependencies are not installed: #{missing_dependencies.map(&:full_name).join(", ")} Install them first with: brew install --only-dependencies #{formula.full_name} EOS return end FormulaInstaller.new( formula, build_from_source_formulae: args.build_from_source_formulae, force_bottle: args.force_bottle?, **{ debug: args.debug?, quiet: args.quiet?, verbose: args.verbose? }.compact, ).run_fetch end |