Class: Homebrew::Bundle::BrewInstaller Private
- Defined in:
- bundle/brew_installer.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
- .formula_in_array?(formula, array) ⇒ Boolean private
- .formula_installed?(formula) ⇒ Boolean private
- .formula_installed_and_up_to_date?(formula, no_upgrade: false) ⇒ Boolean private
- .formula_upgradable?(formula) ⇒ Boolean private
- .formulae ⇒ Object private
- .install(name, preinstall: true, no_upgrade: false, verbose: false, force: false, **options) ⇒ Object private
- .installed_formulae ⇒ Object private
- .no_upgrade_with_args?(no_upgrade, formula_name) ⇒ Boolean private
- .outdated_formulae ⇒ Object private
- .pinned_formulae ⇒ Object private
- .preinstall(name, no_upgrade: false, verbose: false, **options) ⇒ Object private
- .reset! ⇒ Object private
- .upgradable_formulae ⇒ Object private
Instance Method Summary collapse
- #changed? ⇒ Boolean private
-
#initialize(name, options = {}) ⇒ BrewInstaller
constructor
private
A new instance of BrewInstaller.
- #install(preinstall: true, no_upgrade: false, verbose: false, force: false) ⇒ Object private
- #install_change_state!(no_upgrade:, verbose:, force:) ⇒ Object private
- #link_change_state!(verbose: false) ⇒ Object private
- #postinstall_change_state!(verbose:) ⇒ Object private
- #preinstall(no_upgrade: false, verbose: false) ⇒ Object private
- #restart_service? ⇒ Boolean private
- #restart_service_needed? ⇒ Boolean private
- #service_change_state!(verbose:) ⇒ Object private
- #start_service? ⇒ Boolean private
- #start_service_needed? ⇒ Boolean private
Constructor Details
#initialize(name, options = {}) ⇒ BrewInstaller
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 a new instance of BrewInstaller.
21 22 23 24 25 26 27 28 29 30 31 32 |
# File 'bundle/brew_installer.rb', line 21 def initialize(name, = {}) @full_name = name @name = name.split("/").last @args = .fetch(:args, []).map { |arg| "--#{arg}" } @conflicts_with_arg = .fetch(:conflicts_with, []) @restart_service = [:restart_service] @start_service = .fetch(:start_service, @restart_service) @link = .fetch(:link, nil) @postinstall = .fetch(:postinstall, nil) @version_file = .fetch(:version_file, nil) @changed = nil end |
Class Method Details
.formula_in_array?(formula, array) ⇒ 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.
178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 |
# File 'bundle/brew_installer.rb', line 178 def self.formula_in_array?(formula, array) return true if array.include?(formula) return true if array.include?(formula.split("/").last) require "bundle/brew_dumper" old_names = Homebrew::Bundle::BrewDumper.formula_oldnames old_name = old_names[formula] old_name ||= old_names[formula.split("/").last] return true if old_name && array.include?(old_name) resolved_full_name = Homebrew::Bundle::BrewDumper.formula_aliases[formula] return false unless resolved_full_name return true if array.include?(resolved_full_name) return true if array.include?(resolved_full_name.split("/").last) false end |
.formula_installed?(formula) ⇒ 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.
196 197 198 |
# File 'bundle/brew_installer.rb', line 196 def self.formula_installed?(formula) formula_in_array?(formula, installed_formulae) end |
.formula_installed_and_up_to_date?(formula, no_upgrade: 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.
167 168 169 170 171 172 |
# File 'bundle/brew_installer.rb', line 167 def self.formula_installed_and_up_to_date?(formula, no_upgrade: false) return false unless formula_installed?(formula) return true if no_upgrade_with_args?(no_upgrade, formula) !formula_upgradable?(formula) end |
.formula_upgradable?(formula) ⇒ 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.
200 201 202 203 |
# File 'bundle/brew_installer.rb', line 200 def self.formula_upgradable?(formula) # Check local cache first and then authoritative Homebrew source. formula_in_array?(formula, upgradable_formulae) && Formula[formula].outdated? end |
.formulae ⇒ Object
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.
221 222 223 224 |
# File 'bundle/brew_installer.rb', line 221 def self.formulae require "bundle/brew_dumper" Homebrew::Bundle::BrewDumper.formulae end |
.install(name, preinstall: true, no_upgrade: false, verbose: false, force: false, **options) ⇒ Object
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.
17 18 19 |
# File 'bundle/brew_installer.rb', line 17 def self.install(name, preinstall: true, no_upgrade: false, verbose: false, force: false, **) new(name, ).install(preinstall:, no_upgrade:, verbose:, force:) end |
.installed_formulae ⇒ Object
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.
205 206 207 |
# File 'bundle/brew_installer.rb', line 205 def self.installed_formulae @installed_formulae ||= formulae.map { |f| f[:name] } end |
.no_upgrade_with_args?(no_upgrade, formula_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.
174 175 176 |
# File 'bundle/brew_installer.rb', line 174 def self.no_upgrade_with_args?(no_upgrade, formula_name) no_upgrade && Bundle.upgrade_formulae.exclude?(formula_name) end |
.outdated_formulae ⇒ Object
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.
213 214 215 |
# File 'bundle/brew_installer.rb', line 213 def self.outdated_formulae @outdated_formulae ||= formulae.filter_map { |f| f[:name] if f[:outdated?] } end |
.pinned_formulae ⇒ Object
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.
217 218 219 |
# File 'bundle/brew_installer.rb', line 217 def self.pinned_formulae @pinned_formulae ||= formulae.filter_map { |f| f[:name] if f[:pinned?] } end |
.preinstall(name, no_upgrade: false, verbose: false, **options) ⇒ Object
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.
13 14 15 |
# File 'bundle/brew_installer.rb', line 13 def self.preinstall(name, no_upgrade: false, verbose: false, **) new(name, ).preinstall(no_upgrade:, verbose:) end |
.reset! ⇒ Object
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.
7 8 9 10 11 |
# File 'bundle/brew_installer.rb', line 7 def self.reset! @installed_formulae = nil @outdated_formulae = nil @pinned_formulae = nil end |
.upgradable_formulae ⇒ Object
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.
209 210 211 |
# File 'bundle/brew_installer.rb', line 209 def self.upgradable_formulae outdated_formulae - pinned_formulae end |
Instance Method Details
#changed? ⇒ 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.
109 110 111 |
# File 'bundle/brew_installer.rb', line 109 def changed? @changed.present? end |
#install(preinstall: true, no_upgrade: false, verbose: false, force: false) ⇒ Object
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.
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 |
# File 'bundle/brew_installer.rb', line 44 def install(preinstall: true, no_upgrade: false, verbose: false, force: false) install_result = if preinstall install_change_state!(no_upgrade:, verbose:, force:) else true end result = install_result if installed? service_result = service_change_state!(verbose:) result &&= service_result link_result = link_change_state!(verbose:) result &&= link_result postinstall_result = postinstall_change_state!(verbose:) result &&= postinstall_result if result && @version_file.present? # Use the version from the environment if it hasn't changed. # Strip the revision number because it's not part of the non-Homebrew version. version = if !changed? && (env_version = Bundle.formula_versions_from_env(@name)) PkgVersion.parse(env_version).version else Formula[@full_name].version end.to_s File.write(@version_file, "#{version}\n") puts "Wrote #{@name} version #{version} to #{@version_file}" if verbose end end result end |
#install_change_state!(no_upgrade:, verbose:, force:) ⇒ Object
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 |
# File 'bundle/brew_installer.rb', line 79 def install_change_state!(no_upgrade:, verbose:, force:) return false unless resolve_conflicts!(verbose:) if installed? upgrade!(verbose:, force:) else install!(verbose:, force:) end end |
#link_change_state!(verbose: false) ⇒ Object
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.
129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 |
# File 'bundle/brew_installer.rb', line 129 def link_change_state!(verbose: false) link_args = [] link_args << "--force" if unlinked_and_keg_only? cmd = case @link when :overwrite link_args << "--overwrite" "link" unless linked? when true "link" unless linked? when false "unlink" if linked? when nil if keg_only? "unlink" if linked? else "link" unless linked? end end if cmd.present? verb = "#{cmd}ing".capitalize with_args = " with #{link_args.join(" ")}" if link_args.present? puts "#{verb} #{@name} formula#{with_args}." if verbose return Bundle.brew(cmd, *link_args, @name, verbose:) end true end |
#postinstall_change_state!(verbose:) ⇒ Object
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.
159 160 161 162 163 164 165 |
# File 'bundle/brew_installer.rb', line 159 def postinstall_change_state!(verbose:) return true if @postinstall.blank? return true unless changed? puts "Running postinstall for #{@name}: #{@postinstall}" if verbose Kernel.system(@postinstall) end |
#preinstall(no_upgrade: false, verbose: false) ⇒ Object
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.
34 35 36 37 38 39 40 41 42 |
# File 'bundle/brew_installer.rb', line 34 def preinstall(no_upgrade: false, verbose: false) if installed? && (self.class.no_upgrade_with_args?(no_upgrade, @name) || !upgradable?) puts "Skipping install of #{@name} formula. It is already installed." if verbose @changed = nil return false end true end |
#restart_service? ⇒ 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.
98 99 100 |
# File 'bundle/brew_installer.rb', line 98 def restart_service? @restart_service.present? end |
#restart_service_needed? ⇒ 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.
102 103 104 105 106 107 |
# File 'bundle/brew_installer.rb', line 102 def restart_service_needed? return false unless restart_service? # Restart if `restart_service: :always`, or if the formula was installed or upgraded @restart_service.to_s == "always" || changed? end |
#service_change_state!(verbose:) ⇒ Object
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.
113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 |
# File 'bundle/brew_installer.rb', line 113 def service_change_state!(verbose:) require "bundle/brew_services" file = Bundle::BrewServices.versioned_service_file(@name) if restart_service_needed? puts "Restarting #{@name} service." if verbose BrewServices.restart(@full_name, file:, verbose:) elsif start_service_needed? puts "Starting #{@name} service." if verbose BrewServices.start(@full_name, file:, verbose:) else true end end |
#start_service? ⇒ 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.
89 90 91 |
# File 'bundle/brew_installer.rb', line 89 def start_service? @start_service.present? end |
#start_service_needed? ⇒ 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.
93 94 95 96 |
# File 'bundle/brew_installer.rb', line 93 def start_service_needed? require "bundle/brew_services" start_service? && !BrewServices.started?(@full_name) end |