Module: Homebrew::Bundle::Installer Private

Defined in:
bundle/installer.rb

This module is part of a private API. This module may only be used in the Homebrew/brew repository. Third parties should avoid using this module if possible, as it may be removed or changed without warning.

Class Method Summary collapse

Class Method Details

.fetchable_formulae_and_casks(entries, no_upgrade:) ⇒ 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.

Parameters:

Returns:



134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
# File 'bundle/installer.rb', line 134

def self.fetchable_formulae_and_casks(entries, no_upgrade:)
  entries.filter_map do |entry|
    name = entry.fetch(:name)
    options = entry.fetch(:options)

    case entry.fetch(:type)
    when :brew
      next unless tap_installed?(name)
      next if Homebrew::Bundle::FormulaInstaller.formula_installed_and_up_to_date?(name, no_upgrade:)

      name
    when :cask
      full_name = options.fetch(:full_name, name)
      next unless tap_installed?(full_name)
      next unless Homebrew::Bundle::CaskInstaller.installable_or_upgradable?(name, no_upgrade:, **options)

      full_name
    end
  end
end

.install!(entries, global: false, file: nil, no_lock: false, no_upgrade: false, verbose: false, force: false, quiet: 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:

  • entries (Array<Dsl::Entry>)
  • global (Boolean) (defaults to: false)
  • file (String, nil) (defaults to: nil)
  • no_lock (Boolean) (defaults to: false)
  • no_upgrade (Boolean) (defaults to: false)
  • verbose (Boolean) (defaults to: false)
  • force (Boolean) (defaults to: false)
  • quiet (Boolean) (defaults to: false)

Returns:

  • (Boolean)


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
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
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
# File 'bundle/installer.rb', line 30

def self.install!(entries, global: false, file: nil, no_lock: false, no_upgrade: false, verbose: false,
                  force: false, quiet: false)
  success = 0
  failure = 0

  installable_entries = entries.filter_map do |entry|
    next if Homebrew::Bundle::Skipper.skip? entry

    name = entry.name
    args = [name]
    options = {}
    verb = "Installing"
    type = entry.type
    cls = case type
    when :brew
      options = entry.options
      verb = "Upgrading" if Homebrew::Bundle::FormulaInstaller.formula_upgradable?(name)
      Homebrew::Bundle::FormulaInstaller
    when :cask
      options = entry.options
      verb = "Upgrading" if Homebrew::Bundle::CaskInstaller.cask_upgradable?(name)
      Homebrew::Bundle::CaskInstaller
    when :mas
      args << entry.options[:id]
      Homebrew::Bundle::MacAppStoreInstaller
    when :vscode
      Homebrew::Bundle::VscodeExtensionInstaller
    when :go
      Homebrew::Bundle::GoInstaller
    when :cargo
      Homebrew::Bundle::CargoInstaller
    when :flatpak
      options = entry.options
      Homebrew::Bundle::FlatpakInstaller
    when :tap
      verb = "Tapping"
      options = entry.options
      Homebrew::Bundle::TapInstaller
    end
    next if cls.nil?

    { name:, args:, options:, verb:, type:, cls: }
  end

  if (fetchable_names = fetchable_formulae_and_casks(installable_entries, no_upgrade:).presence)
    fetchable_names_joined = fetchable_names.join(", ")
    Formatter.success("Fetching #{fetchable_names_joined}") unless quiet
    unless Bundle.brew("fetch", *fetchable_names, verbose:)
      $stderr.puts Formatter.error "`brew bundle` failed! Failed to fetch #{fetchable_names_joined}"
      return false
    end
  end

  installable_entries.each do |entry|
    name = entry.fetch(:name)
    args = entry.fetch(:args)
    options = entry.fetch(:options)
    verb = entry.fetch(:verb)
    cls = entry.fetch(:cls)

    preinstall = if cls.preinstall!(*args, **options, no_upgrade:, verbose:)
      puts Formatter.success("#{verb} #{name}")
      true
    else
      puts "Using #{name}" unless quiet
      false
    end

    if cls.install!(*args, **options,
                   preinstall:, no_upgrade:, verbose:, force:)
      success += 1
    else
      $stderr.puts Formatter.error("#{verb} #{name} has failed!")
      failure += 1
    end
  end

  unless failure.zero?
    require "utils"
    dependency = Utils.pluralize("dependency", failure)
    $stderr.puts Formatter.error "`brew bundle` failed! #{failure} Brewfile #{dependency} failed to install"
    return false
  end

  unless quiet
    require "utils"
    dependency = Utils.pluralize("dependency", success)
    puts Formatter.success "`brew bundle` complete! #{success} Brewfile #{dependency} now installed."
  end

  true
end

.tap_installed?(package_full_name) ⇒ 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:

Returns:

  • (Boolean)


156
157
158
159
160
161
# File 'bundle/installer.rb', line 156

def self.tap_installed?(package_full_name)
  user, repository, = package_full_name.split("/", 3)
  return true if user.blank? || repository.blank?

  Homebrew::Bundle::TapInstaller.installed_taps.include?("#{user}/#{repository}")
end