Spec-Zone.ru › Homebrew

Модуль: CPAN Приватный

Расширен модулем:
Utils::Output::Mixin
Определён в:
utils/cpan.rb

Обзор

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

Вспомогательные функции для обновления ресурсов CPAN.

Определено в пространстве имён

Классы: Package

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

  • .update_perl_resources!(formula, print_only: false, quiet: false, verbose: false, ignore_errors: false) ⇒ Boolean? приватный

    Обновляет ресурсы CPAN в формуле.

Методы, включённые из 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_deprecated, pretty_disabled, pretty_duration, pretty_install_status, pretty_installed, pretty_uninstalled, pretty_upgradable, pretty_warning

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

.update_perl_resources!(formula, print_only: false, quiet: false, verbose: false, ignore_errors: false) ⇒ Boolean?

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

Обновляет ресурсы CPAN в формуле.

Параметры:

  • formula (Formula)
  • print_only (Boolean, nil) (по умолчанию: false)
  • quiet (Boolean, nil) (по умолчанию: false)
  • verbose (Boolean, nil) (по умолчанию: false)
  • ignore_errors (Boolean, nil) (по умолчанию: false)

Возвращает:

  • (Boolean, nil)


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 'utils/cpan.rb', line 93

def self.update_perl_resources!(formula, print_only: false, quiet: false, verbose: false, ignore_errors: false)
  cpan_resources = formula.resources.select { |resource| resource.url.start_with?(METACPAN_URL_PREFIX) }

  odie "\"#{formula.name}\" has no CPAN resources to update." if cpan_resources.empty?

  show_info = !print_only && !quiet

  non_cpan_resources = formula.resources.reject { |resource| resource.url.start_with?(METACPAN_URL_PREFIX) }
  ohai "Skipping #{non_cpan_resources.length} non-CPAN resources" if non_cpan_resources.any? && show_info
  ohai "Found #{cpan_resources.length} CPAN resources to update" if show_info

  new_resource_blocks = ""
  package_errors = ""
  updated_count = 0

  cpan_resources.each do |resource|
    package = Package.new(resource.name, resource.url)

    unless package.valid_cpan_package?
      if ignore_errors
        package_errors += "  # RESOURCE-ERROR: \"#{resource.name}\" is not a valid CPAN resource\n"
        next
      else
        odie "\"#{resource.name}\" is not a valid CPAN resource"
      end
    end

    ohai "Checking \"#{resource.name}\" for updates..." if show_info

    info = package.latest_cpan_info

    unless info
      if ignore_errors
        package_errors += "  # RESOURCE-ERROR: Unable to resolve \"#{resource.name}\"\n"
        next
      else
        odie "Unable to resolve \"#{resource.name}\""
      end
    end

    name, url, checksum, new_version = info
    current_version = package.current_version

    if current_version && new_version && current_version != new_version
      ohai "\"#{resource.name}\": #{current_version} -> #{new_version}" if show_info
      updated_count += 1
    elsif show_info
      ohai "\"#{resource.name}\": already up to date (#{current_version})" if current_version
    end

    new_resource_blocks += <<-EOS
resource "#{name}" do
  url "#{url}"
  sha256 "#{checksum}"
end

    EOS
  end

  package_errors += "\n" if package_errors.present?
  resource_section = "#{package_errors}#{new_resource_blocks}"

  if print_only
    puts resource_section.chomp
    return true
  end

  ohai "Updating resource blocks" unless quiet
  require "utils/ast"

  formula_ast = Utils::AST::FormulaAST.new(formula.path.read)
  if formula_ast.replace_resource_stanzas(
    resource_section,
    replace_existing: formula.resources.any? { |resource| !resource.name.start_with?("homebrew-") },
  ) == :multiple_groups
    odie "Unable to update resource blocks for \"#{formula.name}\" automatically. Please update them manually."
  end
  formula.path.atomic_write(formula_ast.process)

  if package_errors.present?
    ofail "Unable to resolve some dependencies. Please check #{formula.path} for RESOURCE-ERROR comments."
  elsif updated_count.positive?
    ohai "Updated #{updated_count} CPAN resource#{"s" if updated_count != 1}" unless quiet
  end

  true
end

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

Spec-Zone.ru

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