Class: Homebrew::Bundle::Go Private
- Inherits:
-
Extension
- Object
- PackageType
- Extension
- Homebrew::Bundle::Go
- Defined in:
- bundle/extensions/go.rb
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.
Class Method Summary collapse
- .banner_name ⇒ String private
- .binary_package_path(go, binary) ⇒ String? private
- .check_label ⇒ String private
- .cleanup!(items) ⇒ void private
- .cleanup_heading ⇒ String? private
- .discovered_binaries(go) ⇒ Hash{String => String} private
- .install_package!(name, with: nil, verbose: false) ⇒ Boolean private
- .installed_packages ⇒ Array<String> private
- .package_outdated?(name, with: nil, source: nil) ⇒ Boolean private
- .packages ⇒ Array<String> private
- .reset! ⇒ void private
- .type ⇒ Symbol private
Methods inherited from Extension
add_supported?, check, cleanup_disable_description, cleanup_disable_env, cleanup_item_name, cleanup_items, cleanup_supported?, disable_predicate_method, dump, dump_disable_description, dump_disable_env, dump_disable_predicate_method, dump_disable_supported?, dump_entry, dump_name, dump_output, dump_supported?, dump_with, ensure_package_manager_installed!, entry, #failure_reason, flag, inherited, install!, install_supported?, install_verb, #installed_and_up_to_date?, legacy_check_step, package_description, package_installed?, package_manager_env, package_manager_executable, package_manager_executable!, package_manager_installed?, package_manager_name, package_record, predicate_method, preinstall!, quote, remove_supported?, switch_description, uninstall_package!, with_package_manager_env
Methods included from Utils::Output::Mixin
#issue_reporting_message, #odebug, #odeprecated, #odie, #odisabled, #ofail, #oh1, #oh1_title, #ohai, #ohai_title, #onoe, #opoo, #opoo_once, #opoo_outside_github_actions, #opoo_without_github_actions_annotation, #pretty_cannot_install, #pretty_deprecated, #pretty_disabled, #pretty_duration, #pretty_install_status, #pretty_installed, #pretty_removed, #pretty_uninstalled, #pretty_unmarked, #pretty_upgradable, #pretty_warning
Methods inherited from PackageType
batch_installable?, check, #checkable_entries, dump, dump_output, dump_supported?, #exit_early_check, #failure_reason, #find_actionable, #format_checkable, #full_check, inherited, install!, install_batch!, install_supported?, install_verb, #installed_and_up_to_date?, preinstall!
Class Method Details
.banner_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.
21 |
# File 'bundle/extensions/go.rb', line 21 def = "Go packages" |
.binary_package_path(go, binary) ⇒ 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.
79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 |
# File 'bundle/extensions/go.rb', line 79 def binary_package_path(go, binary) result = SystemCommand.run(go, args: ["version", "-m", binary], print_stderr: false) if result.exit_status == 1 && result.stdout.empty? NON_GO_EXECUTABLE_ERRORS.each do |diagnostic| if result.stderr.chomp == "#{binary}: could not read Go build info from #{binary}: #{diagnostic}" return nil end end end result.assert_success! path_line = result.stdout.each_line.find { |line| line.start_with?("\tpath\t") } return unless path_line path = path_line.delete_prefix("\tpath\t").chomp if path.empty? || path.match?(/\s/) raise "Invalid Go package path for #{binary.inspect}: #{path.inspect}" end path end |
.check_label ⇒ 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.
18 |
# File 'bundle/extensions/go.rb', line 18 def check_label = "Go Package" |
.cleanup!(items) ⇒ 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.
153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 |
# File 'bundle/extensions/go.rb', line 153 def cleanup!(items) go = package_manager_executable if go.nil? ofail "Failed to remove Go executables: go executable not found" unless items.empty? return end removed = 0 # Finish discovery before deleting anything so an inspection failure cannot leave partial cleanup. discovered_binaries(go).each do |binary, package_path| next unless items.include?(package_path) begin File.unlink(binary) rescue Errno::ENOENT next rescue SystemCallError => e ofail "Failed to remove Go executable #{binary}: #{e}" next end removed += 1 end puts "Removed #{Utils.pluralize("Go executable", removed, include_count: true)}" end |
.cleanup_heading ⇒ 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.
31 32 33 |
# File 'bundle/extensions/go.rb', line 31 def cleanup_heading end |
.discovered_binaries(go) ⇒ Hash{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.
51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 |
# File 'bundle/extensions/go.rb', line 51 def discovered_binaries(go) ENV["GOBIN"] = ENV.fetch("HOMEBREW_GOBIN", nil) ENV["GOPATH"] = ENV.fetch("HOMEBREW_GOPATH", nil) gobin = command_output(go, args: ["env", "GOBIN"], print_stderr: true).chomp gopath = command_output(go, args: ["env", "GOPATH"], print_stderr: true).chomp bin_dir = gobin.empty? ? "#{gopath}/bin" : gobin begin entries = Dir.children(bin_dir).sort rescue Errno::ENOENT return {} end entries.each_with_object({}) do |entry, binaries| next if entry.start_with?(".") binary = File.join(bin_dir, entry) next unless File.executable?(binary) next if File.directory?(binary) || File.symlink?(binary) path = binary_package_path(go, binary) binaries[binary] = path if path end end |
.install_package!(name, with: nil, verbose: false) ⇒ 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.
110 111 112 113 114 115 116 |
# File 'bundle/extensions/go.rb', line 110 def install_package!(name, with: nil, verbose: false) _ = with go = package_manager_executable! Bundle.system(go.to_s, "install", "#{name}@latest", verbose:) end |
.installed_packages ⇒ 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.
119 120 121 |
# File 'bundle/extensions/go.rb', line 119 def installed_packages @installed_packages ||= packages.dup end |
.package_outdated?(name, with: nil, source: 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.
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 |
# File 'bundle/extensions/go.rb', line 126 def package_outdated?(name, with: nil, source: nil) go = package_manager_executable! @discovered_binaries ||= discovered_binaries(go) @discovered_binaries.any? do |binary, package_path| next false if package_path != name mod = command_output(go, args: ["version", "-m", binary]).each_line.find do |line| line.start_with?("\tmod\t") end next true unless mod _, module_path, version = mod.split next true if version.nil? || version == "(devel)" latest = SystemCommand.run!(go, args: ["list", "-m", "-f", "{{.Version}}", "#{module_path}@latest"], chdir: HOMEBREW_TEMP, print_stderr: false).stdout.strip comparison = Semver.compare(latest, version) raise "Invalid Go versions for #{name}: #{version.inspect}, #{latest.inspect}" if comparison.nil? comparison.positive? end rescue ErrorDuringExecution => e opoo "Unable to check #{name} for upgrades. Using the installed version.\n#{e}" false end |
.packages ⇒ 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.
36 37 38 39 40 41 42 43 44 45 46 47 48 |
# File 'bundle/extensions/go.rb', line 36 def packages packages = @packages return packages if packages @packages = if (go = package_manager_executable) # Go uses `command-line-arguments` for binaries built from source files rather than a package. # These binaries have no package path that Bundle can reinstall. # https://github.com/golang/go/issues/36043 discovered_binaries(go).values.reject { |path| path == "command-line-arguments" }.uniq else [] end end |
.reset! ⇒ 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.
24 25 26 27 28 |
# File 'bundle/extensions/go.rb', line 24 def reset! @packages = T.let(nil, T.nilable(T::Array[String])) @installed_packages = T.let(nil, T.nilable(T::Array[String])) @discovered_binaries = T.let(nil, T.nilable(T::Hash[String, String])) end |
.type ⇒ 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.
15 |
# File 'bundle/extensions/go.rb', line 15 def type = :go |