Class: Homebrew::Bundle::Cargo Private
- Inherits:
-
Extension
- Object
- PackageType
- Extension
- Homebrew::Bundle::Cargo
- Defined in:
- bundle/extensions/cargo.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
- SourceOptions =
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.
T.type_alias { T::Hash[Symbol, String] }
- Crate =
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.
T.type_alias { { name: String, source: T.nilable(String) } }
- Checkable =
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.
T.type_alias { { name: String, options: SourceOptions } }
- CrateEntry =
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.
T.type_alias { T.any(Crate, Checkable) }
- GIT_SOURCE_REGEX =
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.
cargo install --listreports the origin of anything not installed from a registry, as either a git URL or a local path. Only a git URL that resolves from another machine is supported here, so neither a path nor thefile://scheme is accepted.--gitrejects an scp-style remote, so a scheme is required too. %r{\A(?:ssh|git|https?)://}- GIT_REFERENCE_KEYS =
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.
%w[branch tag rev].freeze
- PACKAGE_LIST_REGEX =
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.
/\A(?<name>[^\s:]+)\s+v[0-9A-Za-z.+-]+(?:\s+\((?<origin>[^)]+)\))?/
Class Method Summary collapse
- .banner_name ⇒ String private
- .batch_installable?(_name, _options = {}) ⇒ Boolean private
- .cargo_env(cargo) ⇒ Hash{String => String} private
- .check_label ⇒ String private
- .cleanup_heading ⇒ String? private
- .crate_record(name, source: nil) ⇒ Crate private
- .dump_entry(package) ⇒ String private
- .dump_name(package) ⇒ String private
- .dump_source(package) ⇒ String? private
- .entry(name, options = {}) ⇒ Dsl::Entry private
- .install!(name, with: nil, source: nil, preinstall: true, no_upgrade: false, verbose: false, force: false, **_options) ⇒ Boolean private
- .install_batch!(entries, verbose: false) ⇒ Boolean private
- .install_package!(name, with: nil, source: nil, verbose: false) ⇒ Boolean private
- .installed_packages ⇒ Array<Crate> private
-
.normalize_source(source) ⇒ String?
private
The resolved revision that
cargo install --listappends to a git origin is deliberately dropped: a dumped Brewfile has to compare equal to a hand-written one, which a pinned revision would prevent. - .package_installed?(name, with: nil, source: nil) ⇒ Boolean private
- .package_manager_env(executable) ⇒ Hash{String => String} private
- .package_manager_executable ⇒ Pathname? private
- .package_manager_name ⇒ String private
- .package_record(name, with: nil, source: nil) ⇒ Object private
- .packages ⇒ Array<Crate> private
- .parse_package_list(output) ⇒ Array<Crate> private
- .preinstall!(name, with: nil, source: nil, no_upgrade: false, verbose: false, **_options) ⇒ Boolean private
- .reset! ⇒ void private
-
.source_args(source) ⇒ Array<String>
private
A branch, tag or revision selected at install time is reported by
cargo install --listas a URL query, and never more than one of them, but--gitrejects a query: it has to be passed as the matching flag. - .type ⇒ Symbol private
- .uninstall_package!(name, executable: Pathname.new("")) ⇒ void private
Instance Method Summary collapse
- #format_checkable(entries) ⇒ Array<Object> private
- #installed_and_up_to_date?(package, no_upgrade: false) ⇒ Boolean private
Methods inherited from Extension
add_supported?, check, cleanup!, 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_output, dump_supported?, dump_with, ensure_package_manager_installed!, #failure_reason, flag, inherited, install_supported?, install_verb, legacy_check_step, package_description, package_manager_executable!, package_manager_installed?, predicate_method, quote, remove_supported?, switch_description, with_package_manager_env
Methods inherited from PackageType
check, #checkable_entries, dump, dump_output, dump_supported?, #exit_early_check, #failure_reason, #find_actionable, #full_check, inherited, install_supported?, install_verb
Class Method Details
.banner_name ⇒ 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.
31 |
# File 'bundle/extensions/cargo.rb', line 31 def = "Cargo packages" |
.batch_installable?(_name, _options = {}) ⇒ 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.
81 82 83 |
# File 'bundle/extensions/cargo.rb', line 81 def batch_installable?(_name, = {}) true end |
.cargo_env(cargo) ⇒ Hash{String => 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.
303 304 305 306 307 308 309 310 |
# File 'bundle/extensions/cargo.rb', line 303 def cargo_env(cargo) { "CARGO_HOME" => ENV.fetch("HOMEBREW_CARGO_HOME", nil), "CARGO_INSTALL_ROOT" => ENV.fetch("HOMEBREW_CARGO_INSTALL_ROOT", nil), "PATH" => "#{cargo.dirname}:#{ENV.fetch("PATH")}", "RUSTUP_HOME" => ENV.fetch("HOMEBREW_RUSTUP_HOME", nil), }.compact end |
.check_label ⇒ 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.
28 |
# File 'bundle/extensions/cargo.rb', line 28 def check_label = "Cargo Package" |
.cleanup_heading ⇒ 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.
66 67 68 |
# File 'bundle/extensions/cargo.rb', line 66 def cleanup_heading end |
.crate_record(name, source: nil) ⇒ Crate
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.
187 188 189 |
# File 'bundle/extensions/cargo.rb', line 187 def crate_record(name, source: nil) { name: name.strip, source: normalize_source(source) } end |
.dump_entry(package) ⇒ 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.
129 130 131 132 133 134 135 |
# File 'bundle/extensions/cargo.rb', line 129 def dump_entry(package) line = super source = dump_source(package) line = "#{line}, source: #{quote(source)}" if source.present? line end |
.dump_name(package) ⇒ 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.
116 117 118 |
# File 'bundle/extensions/cargo.rb', line 116 def dump_name(package) T.cast(package, CrateEntry)[:name] end |
.dump_source(package) ⇒ 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.
121 122 123 124 125 126 |
# File 'bundle/extensions/cargo.rb', line 121 def dump_source(package) package = T.cast(package, CrateEntry) return package[:source] if package.key?(:source) package[:options].fetch(:source, nil) end |
.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.
34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 |
# File 'bundle/extensions/cargo.rb', line 34 def entry(name, = {}) = .keys - [:source] raise "unknown options(#{.inspect}) for cargo" if .present? source = .fetch(:source, nil) if !source.nil? && !source.is_a?(String) raise "options[:source](#{source.inspect}) should be a String object" end = {} if source.present? normalized_source = normalize_source(source) raise "options[:source](#{source.inspect}) should be a git URL" if normalized_source.nil? selector = normalized_source.partition("?").last if selector.present? && GIT_REFERENCE_KEYS.exclude?(selector.partition("=").first) raise "options[:source](#{source.inspect}) should select a branch, tag or rev" end [:source] = normalized_source end Dsl::Entry.new(:cargo, name, ) end |
.install!(name, with: nil, source: nil, preinstall: true, no_upgrade: false, verbose: false, force: false, **_options) ⇒ 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.
238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 |
# File 'bundle/extensions/cargo.rb', line 238 def install!(name, with: nil, source: nil, preinstall: true, no_upgrade: false, verbose: false, force: false, **) _ = no_upgrade _ = force return true unless preinstall puts "Installing #{name} #{package_description}. It is not currently installed." if verbose return false unless install_package!(name, with:, source:, verbose:) package = crate_record(name, source:) installed_packages << package unless installed_packages.include?(package) packages << package unless packages.include?(package) true end |
.install_batch!(entries, 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.
86 87 88 89 90 91 92 93 94 95 96 97 |
# File 'bundle/extensions/cargo.rb', line 86 def install_batch!(entries, verbose: false) cargo = package_manager_executable! success = T.let(true, T::Boolean) entries.group_by { |entry| entry.[:source] }.each do |source, source_entries| installed = with_env(cargo_env(cargo)) do Bundle.system(cargo.to_s, "install", "--locked", *source_args(T.cast(source, T.nilable(String))), *source_entries.map(&:name), verbose:) end success &&= installed end success end |
.install_package!(name, with: nil, source: 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.
145 146 147 148 149 150 151 152 153 |
# File 'bundle/extensions/cargo.rb', line 145 def install_package!(name, with: nil, source: nil, verbose: false) _ = with cargo = package_manager_executable! with_env(cargo_env(cargo)) do Bundle.system(cargo.to_s, "install", "--locked", *source_args(source), name, verbose:) end end |
.installed_packages ⇒ Array<Crate>
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.
156 157 158 159 160 161 |
# File 'bundle/extensions/cargo.rb', line 156 def installed_packages installed_packages = @installed_packages return installed_packages if installed_packages @installed_packages = packages.dup end |
.normalize_source(source) ⇒ 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.
The resolved revision that cargo install --list appends to a git origin
is deliberately dropped: a dumped Brewfile has to compare equal to a
hand-written one, which a pinned revision would prevent. Anything that is
not a git URL has no source: to dump, whether it is a registry crate or
a local path.
293 294 295 296 297 298 299 |
# File 'bundle/extensions/cargo.rb', line 293 def normalize_source(source) source = source.presence&.strip&.sub(/#[^#]*\z/, "") return if source.blank? return source if source.match?(GIT_SOURCE_REGEX) nil end |
.package_installed?(name, with: nil, source: nil) ⇒ 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.
199 200 201 |
# File 'bundle/extensions/cargo.rb', line 199 def package_installed?(name, with: nil, source: nil) installed_packages.include?(package_record(name, with:, source:)) end |
.package_manager_env(executable) ⇒ Hash{String => 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.
169 170 171 |
# File 'bundle/extensions/cargo.rb', line 169 def package_manager_env(executable) cargo_env(executable) end |
.package_manager_executable ⇒ Pathname?
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.
76 77 78 |
# File 'bundle/extensions/cargo.rb', line 76 def package_manager_executable which("cargo", ORIGINAL_PATHS) end |
.package_manager_name ⇒ 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.
71 72 73 |
# File 'bundle/extensions/cargo.rb', line 71 def package_manager_name "rust" end |
.package_record(name, with: nil, source: nil) ⇒ 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.
180 181 182 183 184 |
# File 'bundle/extensions/cargo.rb', line 180 def package_record(name, with: nil, source: nil) _ = with crate_record(name, source:) end |
.packages ⇒ Array<Crate>
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.
100 101 102 103 104 105 106 107 108 109 110 111 112 113 |
# File 'bundle/extensions/cargo.rb', line 100 def packages packages = @packages return packages if packages @packages = if (cargo = package_manager_executable) && (!cargo.to_s.start_with?("/") || cargo.exist?) with_env(cargo_env(cargo)) do parse_package_list(Utils.popen_read_text(cargo, "install", "--list", err: :err)) end end return [] if @packages.nil? @packages end |
.parse_package_list(output) ⇒ Array<Crate>
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.
272 273 274 275 276 277 278 279 280 281 282 283 284 |
# File 'bundle/extensions/cargo.rb', line 272 def parse_package_list(output) output.lines.filter_map do |line| next if line.match?(/^\s/) match = line.match(PACKAGE_LIST_REGEX) next if match.nil? name = match[:name] next if name.nil? { name:, source: normalize_source(match[:origin]) } end.uniq end |
.preinstall!(name, with: nil, source: nil, no_upgrade: false, verbose: false, **_options) ⇒ 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.
213 214 215 216 217 218 219 220 221 222 223 224 |
# File 'bundle/extensions/cargo.rb', line 213 def preinstall!(name, with: nil, source: nil, no_upgrade: false, verbose: false, **) _ = no_upgrade ensure_package_manager_installed!(name, verbose:) if package_installed?(name, with:, source:) puts "Skipping install of #{name} #{package_description}. It is already installed." if verbose return false end true 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.
60 61 62 63 |
# File 'bundle/extensions/cargo.rb', line 60 def reset! @packages = T.let(nil, T.nilable(T::Array[Crate])) @installed_packages = T.let(nil, T.nilable(T::Array[Crate])) end |
.source_args(source) ⇒ 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.
A branch, tag or revision selected at install time is reported by
cargo install --list as a URL query, and never more than one of them,
but --git rejects a query: it has to be passed as the matching flag.
258 259 260 261 262 263 264 265 266 267 268 |
# File 'bundle/extensions/cargo.rb', line 258 def source_args(source) source = normalize_source(source) return [] if source.nil? url, _, query = source.partition("?") key, _, value = query.partition("=") args = ["--git", url] args.push("--#{key}", value) if GIT_REFERENCE_KEYS.include?(key) args end |
.type ⇒ Symbol
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.
25 |
# File 'bundle/extensions/cargo.rb', line 25 def type = :cargo |
.uninstall_package!(name, executable: Pathname.new("")) ⇒ 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.
164 165 166 |
# File 'bundle/extensions/cargo.rb', line 164 def uninstall_package!(name, executable: Pathname.new("")) Bundle.system(executable.to_s, "uninstall", name, verbose: false) end |
Instance Method Details
#format_checkable(entries) ⇒ Array<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.
315 316 317 318 319 |
# File 'bundle/extensions/cargo.rb', line 315 def format_checkable(entries) checkable_entries(entries).map do |entry| { name: entry.name, options: entry. } end end |
#installed_and_up_to_date?(package, 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.
322 323 324 325 326 327 |
# File 'bundle/extensions/cargo.rb', line 322 def installed_and_up_to_date?(package, no_upgrade: false) self.class.package_installed?( self.class.dump_name(package), source: self.class.dump_source(package), ) end |