Class: Homebrew::Bundle::Go Private

Inherits:
Extension show all
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.

Constant Summary collapse

PACKAGE_TYPE =

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.

:go
PACKAGE_TYPE_NAME =

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.

"Go Package"
"Go packages"

Class Method Summary collapse

Methods inherited from Extension

add_supported?, banner_name, check, check_label, cleanup_items, cleanup_supported?, dump, dump_disable_description, dump_disable_env, dump_disable_predicate_method, dump_disable_supported?, dump_entry, dump_name, dump_output, dump_supported?, dump_with, entry, #failure_reason, fetchable_name, 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, type, uninstall_package!, with_package_manager_env

Methods inherited from PackageType

check, #checkable_entries, dump, dump_output, dump_supported?, #exit_early_check, #failure_reason, fetchable_name, #find_actionable, #format_checkable, #full_check, inherited, install!, install_supported?, install_verb, #installed_and_up_to_date?, preinstall!, type

Class Method Details

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

Parameters:



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
# File 'bundle/extensions/go.rb', line 94

def cleanup!(items)
  go = package_manager_executable
  return if go.nil?

  gobin = `#{go} env GOBIN`.chomp
  gopath = `#{go} env GOPATH`.chomp
  bin_dir = gobin.empty? ? "#{gopath}/bin" : gobin
  return unless File.directory?(bin_dir)

  removed = 0
  Dir.glob("#{bin_dir}/*").each do |binary|
    next if !File.executable?(binary) || File.directory?(binary) || File.symlink?(binary)

    output = `#{go} version -m "#{binary}" 2>/dev/null`
    next if output.empty?

    path_line = output.split("\n").find { |line| line.strip.start_with?("path\t") }
    next unless path_line

    module_path = path_line.split("\t")[2]&.strip
    next unless items.include?(module_path)

    FileUtils.rm_f(binary)
    removed += 1
  end
  puts "Uninstalled #{removed} #{banner_name}#{"s" if removed != 1}"
end

.cleanup_headingString?

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:



21
22
23
# File 'bundle/extensions/go.rb', line 21

def cleanup_heading
  banner_name
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.

Parameters:

  • name (String)
  • with (Array<String>, nil) (defaults to: nil)
  • verbose (Boolean) (defaults to: false)

Returns:

  • (Boolean)


77
78
79
80
81
82
83
# File 'bundle/extensions/go.rb', line 77

def install_package!(name, with: nil, verbose: false)
  _ = with

  go = package_manager_executable!

  Bundle.system(go.to_s, "install", "#{name}@latest", verbose:)
end

.installed_packagesArray<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:



86
87
88
89
90
91
# File 'bundle/extensions/go.rb', line 86

def installed_packages
  installed_packages = @installed_packages
  return installed_packages if installed_packages

  @installed_packages = packages.dup
end

.packagesArray<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:



26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
# File 'bundle/extensions/go.rb', line 26

def packages
  packages = @packages
  return packages if packages

  @packages = if (go = package_manager_executable)
    ENV["GOBIN"] = ENV.fetch("HOMEBREW_GOBIN", nil)
    ENV["GOPATH"] = ENV.fetch("HOMEBREW_GOPATH", nil)
    gobin = `#{go} env GOBIN`.chomp
    gopath = `#{go} env GOPATH`.chomp
    bin_dir = gobin.empty? ? "#{gopath}/bin" : gobin
    if File.directory?(bin_dir)
      binaries = Dir.glob("#{bin_dir}/*").select do |file|
        File.executable?(file) && !File.directory?(file) && !File.symlink?(file)
      end

      binaries.filter_map do |binary|
        output = `#{go} version -m "#{binary}" 2>/dev/null`
        next if output.empty?

        lines = output.split("\n")
        path_line = lines.find { |line| line.strip.start_with?("path\t") }
        next unless path_line

        # Parse the output to find the path line
        # Format: "\tpath\tgithub.com/user/repo"
        parts = path_line.split("\t")
        # Extract the package path (second field after splitting by tab)
        # The line format is: "\tpath\tgithub.com/user/repo"
        path = parts[2]&.strip

        # `command-line-arguments` is a dummy package name for binaries built
        # from a list of source files instead of a specific package name.
        # https://github.com/golang/go/issues/36043
        next if path == "command-line-arguments"

        path
      end.uniq
    end
  end
  return [] if @packages.nil?

  @packages
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.



15
16
17
18
# File 'bundle/extensions/go.rb', line 15

def reset!
  @packages = T.let(nil, T.nilable(T::Array[String]))
  @installed_packages = T.let(nil, T.nilable(T::Array[String]))
end