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.

Class Method Summary collapse

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, 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, 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!

Class Method Details

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:



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

def banner_name = "Go packages"

.check_labelString

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:



14
# File 'bundle/extensions/go.rb', line 14

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.

Parameters:



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

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:



26
27
28
# File 'bundle/extensions/go.rb', line 26

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)


82
83
84
85
86
87
88
# File 'bundle/extensions/go.rb', line 82

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:



91
92
93
94
95
96
# File 'bundle/extensions/go.rb', line 91

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:



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
69
70
71
72
73
# File 'bundle/extensions/go.rb', line 31

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.



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

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

.typeSymbol

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:



11
# File 'bundle/extensions/go.rb', line 11

def type = :go