mirror of
https://github.com/Homebrew/brew.git
synced 2025-07-14 16:09:03 +08:00
Move gem group setting to separate, cacheable file
This commit is contained in:
parent
34eb4f8a94
commit
9cf0d34ee0
1
.gitignore
vendored
1
.gitignore
vendored
@ -26,6 +26,7 @@
|
||||
# Ignore Bundler files
|
||||
**/.bundle/bin
|
||||
**/.bundle/cache
|
||||
**/vendor/bundle/ruby/.homebrew_gem_groups
|
||||
**/vendor/bundle/ruby/*/bundler.lock
|
||||
**/vendor/bundle/ruby/*/bin
|
||||
**/vendor/bundle/ruby/*/build_info/
|
||||
|
@ -13,7 +13,13 @@ module Homebrew
|
||||
Install Homebrew's Bundler gems.
|
||||
EOS
|
||||
comma_array "--groups",
|
||||
description: "Installs the specified comma-separated list of gem groups (default: last used)."
|
||||
description: "Installs the specified comma-separated list of gem groups (default: last used). " \
|
||||
"Replaces any previously installed groups."
|
||||
comma_array "--add-groups",
|
||||
description: "Installs the specified comma-separated list of gem groups, " \
|
||||
"in addition to those already installed."
|
||||
|
||||
conflicts "--groups", "--add-groups"
|
||||
|
||||
named_args :none
|
||||
end
|
||||
@ -22,13 +28,13 @@ module Homebrew
|
||||
def install_bundler_gems
|
||||
args = install_bundler_gems_args.parse
|
||||
|
||||
groups = args.groups
|
||||
groups = args.groups || args.add_groups || []
|
||||
|
||||
# Clear previous settings. We want to fully replace - not append.
|
||||
Homebrew::Settings.delete(:gemgroups) if groups
|
||||
|
||||
groups ||= []
|
||||
groups |= Homebrew.valid_gem_groups if groups.delete("all")
|
||||
if groups.delete("all")
|
||||
groups |= Homebrew.valid_gem_groups
|
||||
elsif args.groups # if we have been asked to replace
|
||||
Homebrew.forget_user_gem_groups!
|
||||
end
|
||||
|
||||
Homebrew.install_bundler_gems!(groups: groups)
|
||||
end
|
||||
|
@ -31,7 +31,7 @@ module Homebrew
|
||||
def self.delete(setting, repo: HOMEBREW_REPOSITORY)
|
||||
return unless (repo/".git/config").exist?
|
||||
|
||||
return if read(setting, repo: repo).blank?
|
||||
return if read(setting, repo: repo).nil?
|
||||
|
||||
Kernel.system("git", "-C", repo.to_s, "config", "--unset-all", "homebrew.#{setting}", exception: true)
|
||||
end
|
||||
|
@ -12,6 +12,9 @@ module Homebrew
|
||||
# After updating this, run `brew vendor-gems --update=--bundler`.
|
||||
HOMEBREW_BUNDLER_VERSION = "2.4.18"
|
||||
|
||||
GEM_GROUPS_FILE = (HOMEBREW_LIBRARY_PATH/"vendor/bundle/ruby/.homebrew_gem_groups").freeze
|
||||
private_constant :GEM_GROUPS_FILE
|
||||
|
||||
module_function
|
||||
|
||||
# @api private
|
||||
@ -151,6 +154,33 @@ module Homebrew
|
||||
ENV["BUNDLER_VERSION"] = old_bundler_version
|
||||
end
|
||||
|
||||
def user_gem_groups
|
||||
@user_gem_groups ||= if GEM_GROUPS_FILE.exist?
|
||||
GEM_GROUPS_FILE.readlines(chomp: true)
|
||||
else
|
||||
# Backwards compatibility. This else block can be replaced by `[]` by the end of 2023.
|
||||
require "settings"
|
||||
groups = Homebrew::Settings.read(:gemgroups)&.split(";") || []
|
||||
write_user_gem_groups(groups)
|
||||
Homebrew::Settings.delete(:gemgroups)
|
||||
groups
|
||||
end
|
||||
end
|
||||
|
||||
def write_user_gem_groups(groups)
|
||||
GEM_GROUPS_FILE.write(groups.join("\n"))
|
||||
end
|
||||
|
||||
def forget_user_gem_groups!
|
||||
if GEM_GROUPS_FILE.exist?
|
||||
GEM_GROUPS_FILE.truncate(0)
|
||||
else
|
||||
# Backwards compatibility. This else block can be removed by the end of 2023.
|
||||
require "settings"
|
||||
Homebrew::Settings.delete(:gemgroups)
|
||||
end
|
||||
end
|
||||
|
||||
def install_bundler_gems!(only_warn_on_failure: false, setup_path: true, groups: [])
|
||||
old_path = ENV.fetch("PATH", nil)
|
||||
old_gem_path = ENV.fetch("GEM_PATH", nil)
|
||||
@ -174,7 +204,7 @@ module Homebrew
|
||||
require "settings"
|
||||
|
||||
# Combine the passed groups with the ones stored in settings
|
||||
groups |= (Homebrew::Settings.read(:gemgroups)&.split(";") || [])
|
||||
groups |= (user_gem_groups & valid_gem_groups)
|
||||
groups.sort!
|
||||
|
||||
ENV["BUNDLE_GEMFILE"] = gemfile
|
||||
@ -223,7 +253,7 @@ module Homebrew
|
||||
end
|
||||
|
||||
if bundle_installed
|
||||
Homebrew::Settings.write(:gemgroups, groups.join(";"))
|
||||
write_user_gem_groups(groups)
|
||||
@bundle_installed_groups = groups
|
||||
end
|
||||
end
|
||||
|
@ -1287,6 +1287,7 @@ _brew_install_bundler_gems() {
|
||||
case "${cur}" in
|
||||
-*)
|
||||
__brewcomp "
|
||||
--add-groups
|
||||
--debug
|
||||
--groups
|
||||
--help
|
||||
|
@ -919,8 +919,9 @@ __fish_brew_complete_arg 'install; and not __fish_seen_argument -l formula -l fo
|
||||
|
||||
|
||||
__fish_brew_complete_cmd 'install-bundler-gems' 'Install Homebrew\'s Bundler gems'
|
||||
__fish_brew_complete_arg 'install-bundler-gems' -l add-groups -d 'Installs the specified comma-separated list of gem groups, in addition to those already installed'
|
||||
__fish_brew_complete_arg 'install-bundler-gems' -l debug -d 'Display any debugging information'
|
||||
__fish_brew_complete_arg 'install-bundler-gems' -l groups -d 'Installs the specified comma-separated list of gem groups (default: last used)'
|
||||
__fish_brew_complete_arg 'install-bundler-gems' -l groups -d 'Installs the specified comma-separated list of gem groups (default: last used). Replaces any previously installed groups'
|
||||
__fish_brew_complete_arg 'install-bundler-gems' -l help -d 'Show this message'
|
||||
__fish_brew_complete_arg 'install-bundler-gems' -l quiet -d 'Make some output more quiet'
|
||||
__fish_brew_complete_arg 'install-bundler-gems' -l verbose -d 'Make some output more verbose'
|
||||
|
@ -1139,8 +1139,9 @@ _brew_install() {
|
||||
# brew install-bundler-gems
|
||||
_brew_install_bundler_gems() {
|
||||
_arguments \
|
||||
'(--groups)--add-groups[Installs the specified comma-separated list of gem groups, in addition to those already installed]' \
|
||||
'--debug[Display any debugging information]' \
|
||||
'--groups[Installs the specified comma-separated list of gem groups (default: last used)]' \
|
||||
'(--add-groups)--groups[Installs the specified comma-separated list of gem groups (default: last used). Replaces any previously installed groups]' \
|
||||
'--help[Show this message]' \
|
||||
'--quiet[Make some output more quiet]' \
|
||||
'--verbose[Make some output more verbose]'
|
||||
|
@ -1300,12 +1300,14 @@ The generated files are written to the current directory.
|
||||
|
||||
Generate Homebrew's manpages and shell completions.
|
||||
|
||||
### `install-bundler-gems` [`--groups=`]
|
||||
### `install-bundler-gems` [`--groups=`] [`--add-groups=`]
|
||||
|
||||
Install Homebrew's Bundler gems.
|
||||
|
||||
* `--groups`:
|
||||
Installs the specified comma-separated list of gem groups (default: last used).
|
||||
Installs the specified comma-separated list of gem groups (default: last used). Replaces any previously installed groups.
|
||||
* `--add-groups`:
|
||||
Installs the specified comma-separated list of gem groups, in addition to those already installed.
|
||||
|
||||
### `irb` [`--examples`] [`--pry`]
|
||||
|
||||
|
@ -1858,12 +1858,16 @@ Generate API data without writing it to files\.
|
||||
.SS "\fBgenerate\-man\-completions\fR"
|
||||
Generate Homebrew\'s manpages and shell completions\.
|
||||
.
|
||||
.SS "\fBinstall\-bundler\-gems\fR [\fB\-\-groups=\fR]"
|
||||
.SS "\fBinstall\-bundler\-gems\fR [\fB\-\-groups=\fR] [\fB\-\-add\-groups=\fR]"
|
||||
Install Homebrew\'s Bundler gems\.
|
||||
.
|
||||
.TP
|
||||
\fB\-\-groups\fR
|
||||
Installs the specified comma\-separated list of gem groups (default: last used)\.
|
||||
Installs the specified comma\-separated list of gem groups (default: last used)\. Replaces any previously installed groups\.
|
||||
.
|
||||
.TP
|
||||
\fB\-\-add\-groups\fR
|
||||
Installs the specified comma\-separated list of gem groups, in addition to those already installed\.
|
||||
.
|
||||
.SS "\fBirb\fR [\fB\-\-examples\fR] [\fB\-\-pry\fR]"
|
||||
Enter the interactive Homebrew Ruby shell\.
|
||||
|
Loading…
x
Reference in New Issue
Block a user