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"

Constants inherited from Extension

Extension::EntryOptions

Class Method Summary collapse

Methods inherited from Extension

add_supported?, banner_name, check, check_label, cleanup!, cleanup_heading, cleanup_items, cleanup_supported?, dump, dump_disable_description, dump_disable_env, dump_disable_predicate_method, dump_disable_supported?, dump_entry, dump_name, dump_supported?, dump_with, #failure_reason, flag, inherited, install!, install_supported?, #installed_and_up_to_date?, package_description, package_installed?, package_manager_executable, package_manager_installed?, package_manager_name, package_record, predicate_method, preinstall!, quote, remove_supported?, switch_description, type

Methods inherited from Checker::Base

#checkable_entries, #exit_early_check, #failure_reason, #find_actionable, #format_checkable, #full_check, #installed_and_up_to_date?

Class Method Details

.entry(name, options = {}) ⇒ Dsl::Entry

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:

Returns:



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

def entry(name, options = {})
  raise "unknown options(#{options.keys.inspect}) for go" if options.present?

  Dsl::Entry.new(:go, 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
89
# File 'bundle/extensions/go.rb', line 82

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

  go = package_manager_executable
  return false if go.nil?

  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:



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

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:



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

def packages
  packages = @packages
  return packages if packages

  @packages = if Bundle.go_installed?
    go = Bundle.which_go
    return [] if go.nil?

    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

    return [] unless 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
  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.



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

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