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
- .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_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, fetchable_name, 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, fetchable_name, #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" |
.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.
284 285 286 287 288 289 290 291 |
# File 'bundle/extensions/cargo.rb', line 284 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.
168 169 170 |
# File 'bundle/extensions/cargo.rb', line 168 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.
110 111 112 113 114 115 116 |
# File 'bundle/extensions/cargo.rb', line 110 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.
97 98 99 |
# File 'bundle/extensions/cargo.rb', line 97 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.
102 103 104 105 106 107 |
# File 'bundle/extensions/cargo.rb', line 102 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.
219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 |
# File 'bundle/extensions/cargo.rb', line 219 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_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.
126 127 128 129 130 131 132 133 134 |
# File 'bundle/extensions/cargo.rb', line 126 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.
137 138 139 140 141 142 |
# File 'bundle/extensions/cargo.rb', line 137 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.
274 275 276 277 278 279 280 |
# File 'bundle/extensions/cargo.rb', line 274 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.
180 181 182 |
# File 'bundle/extensions/cargo.rb', line 180 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.
150 151 152 |
# File 'bundle/extensions/cargo.rb', line 150 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.
161 162 163 164 165 |
# File 'bundle/extensions/cargo.rb', line 161 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.
81 82 83 84 85 86 87 88 89 90 91 92 93 94 |
# File 'bundle/extensions/cargo.rb', line 81 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(`#{cargo} install --list`) 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.
253 254 255 256 257 258 259 260 261 262 263 264 265 |
# File 'bundle/extensions/cargo.rb', line 253 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.
194 195 196 197 198 199 200 201 202 203 204 205 |
# File 'bundle/extensions/cargo.rb', line 194 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.
239 240 241 242 243 244 245 246 247 248 249 |
# File 'bundle/extensions/cargo.rb', line 239 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.
145 146 147 |
# File 'bundle/extensions/cargo.rb', line 145 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.
296 297 298 299 300 |
# File 'bundle/extensions/cargo.rb', line 296 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.
303 304 305 306 307 308 |
# File 'bundle/extensions/cargo.rb', line 303 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 |