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
|
# Ignore Bundler files
|
||||||
**/.bundle/bin
|
**/.bundle/bin
|
||||||
**/.bundle/cache
|
**/.bundle/cache
|
||||||
|
**/vendor/bundle/ruby/.homebrew_gem_groups
|
||||||
**/vendor/bundle/ruby/*/bundler.lock
|
**/vendor/bundle/ruby/*/bundler.lock
|
||||||
**/vendor/bundle/ruby/*/bin
|
**/vendor/bundle/ruby/*/bin
|
||||||
**/vendor/bundle/ruby/*/build_info/
|
**/vendor/bundle/ruby/*/build_info/
|
||||||
|
@ -13,7 +13,13 @@ module Homebrew
|
|||||||
Install Homebrew's Bundler gems.
|
Install Homebrew's Bundler gems.
|
||||||
EOS
|
EOS
|
||||||
comma_array "--groups",
|
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
|
named_args :none
|
||||||
end
|
end
|
||||||
@ -22,13 +28,13 @@ module Homebrew
|
|||||||
def install_bundler_gems
|
def install_bundler_gems
|
||||||
args = install_bundler_gems_args.parse
|
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.
|
if groups.delete("all")
|
||||||
Homebrew::Settings.delete(:gemgroups) if groups
|
groups |= Homebrew.valid_gem_groups
|
||||||
|
elsif args.groups # if we have been asked to replace
|
||||||
groups ||= []
|
Homebrew.forget_user_gem_groups!
|
||||||
groups |= Homebrew.valid_gem_groups if groups.delete("all")
|
end
|
||||||
|
|
||||||
Homebrew.install_bundler_gems!(groups: groups)
|
Homebrew.install_bundler_gems!(groups: groups)
|
||||||
end
|
end
|
||||||
|
@ -31,7 +31,7 @@ module Homebrew
|
|||||||
def self.delete(setting, repo: HOMEBREW_REPOSITORY)
|
def self.delete(setting, repo: HOMEBREW_REPOSITORY)
|
||||||
return unless (repo/".git/config").exist?
|
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)
|
Kernel.system("git", "-C", repo.to_s, "config", "--unset-all", "homebrew.#{setting}", exception: true)
|
||||||
end
|
end
|
||||||
|
@ -12,6 +12,9 @@ module Homebrew
|
|||||||
# After updating this, run `brew vendor-gems --update=--bundler`.
|
# After updating this, run `brew vendor-gems --update=--bundler`.
|
||||||
HOMEBREW_BUNDLER_VERSION = "2.4.18"
|
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
|
module_function
|
||||||
|
|
||||||
# @api private
|
# @api private
|
||||||
@ -151,6 +154,33 @@ module Homebrew
|
|||||||
ENV["BUNDLER_VERSION"] = old_bundler_version
|
ENV["BUNDLER_VERSION"] = old_bundler_version
|
||||||
end
|
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: [])
|
def install_bundler_gems!(only_warn_on_failure: false, setup_path: true, groups: [])
|
||||||
old_path = ENV.fetch("PATH", nil)
|
old_path = ENV.fetch("PATH", nil)
|
||||||
old_gem_path = ENV.fetch("GEM_PATH", nil)
|
old_gem_path = ENV.fetch("GEM_PATH", nil)
|
||||||
@ -174,7 +204,7 @@ module Homebrew
|
|||||||
require "settings"
|
require "settings"
|
||||||
|
|
||||||
# Combine the passed groups with the ones stored in 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!
|
groups.sort!
|
||||||
|
|
||||||
ENV["BUNDLE_GEMFILE"] = gemfile
|
ENV["BUNDLE_GEMFILE"] = gemfile
|
||||||
@ -223,7 +253,7 @@ module Homebrew
|
|||||||
end
|
end
|
||||||
|
|
||||||
if bundle_installed
|
if bundle_installed
|
||||||
Homebrew::Settings.write(:gemgroups, groups.join(";"))
|
write_user_gem_groups(groups)
|
||||||
@bundle_installed_groups = groups
|
@bundle_installed_groups = groups
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
@ -1287,6 +1287,7 @@ _brew_install_bundler_gems() {
|
|||||||
case "${cur}" in
|
case "${cur}" in
|
||||||
-*)
|
-*)
|
||||||
__brewcomp "
|
__brewcomp "
|
||||||
|
--add-groups
|
||||||
--debug
|
--debug
|
||||||
--groups
|
--groups
|
||||||
--help
|
--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_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 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 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 quiet -d 'Make some output more quiet'
|
||||||
__fish_brew_complete_arg 'install-bundler-gems' -l verbose -d 'Make some output more verbose'
|
__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
|
||||||
_brew_install_bundler_gems() {
|
_brew_install_bundler_gems() {
|
||||||
_arguments \
|
_arguments \
|
||||||
|
'(--groups)--add-groups[Installs the specified comma-separated list of gem groups, in addition to those already installed]' \
|
||||||
'--debug[Display any debugging information]' \
|
'--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]' \
|
'--help[Show this message]' \
|
||||||
'--quiet[Make some output more quiet]' \
|
'--quiet[Make some output more quiet]' \
|
||||||
'--verbose[Make some output more verbose]'
|
'--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.
|
Generate Homebrew's manpages and shell completions.
|
||||||
|
|
||||||
### `install-bundler-gems` [`--groups=`]
|
### `install-bundler-gems` [`--groups=`] [`--add-groups=`]
|
||||||
|
|
||||||
Install Homebrew's Bundler gems.
|
Install Homebrew's Bundler gems.
|
||||||
|
|
||||||
* `--groups`:
|
* `--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`]
|
### `irb` [`--examples`] [`--pry`]
|
||||||
|
|
||||||
|
@ -1858,12 +1858,16 @@ Generate API data without writing it to files\.
|
|||||||
.SS "\fBgenerate\-man\-completions\fR"
|
.SS "\fBgenerate\-man\-completions\fR"
|
||||||
Generate Homebrew\'s manpages and shell completions\.
|
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\.
|
Install Homebrew\'s Bundler gems\.
|
||||||
.
|
.
|
||||||
.TP
|
.TP
|
||||||
\fB\-\-groups\fR
|
\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]"
|
.SS "\fBirb\fR [\fB\-\-examples\fR] [\fB\-\-pry\fR]"
|
||||||
Enter the interactive Homebrew Ruby shell\.
|
Enter the interactive Homebrew Ruby shell\.
|
||||||
|
Loading…
x
Reference in New Issue
Block a user