Port Homebrew::DevCmd::VendorGems
This commit is contained in:
parent
084f63ef22
commit
7f9748bd03
@ -1,94 +1,92 @@
|
|||||||
# typed: true
|
# typed: true
|
||||||
# frozen_string_literal: true
|
# frozen_string_literal: true
|
||||||
|
|
||||||
|
require "abstract_command"
|
||||||
require "cli/parser"
|
require "cli/parser"
|
||||||
|
|
||||||
module Homebrew
|
module Homebrew
|
||||||
module_function
|
module DevCmd
|
||||||
|
class VendorGems < AbstractCommand
|
||||||
|
cmd_args do
|
||||||
|
description <<~EOS
|
||||||
|
Install and commit Homebrew's vendored gems.
|
||||||
|
EOS
|
||||||
|
|
||||||
sig { returns(CLI::Parser) }
|
comma_array "--update",
|
||||||
def vendor_gems_args
|
description: "Update the specified list of vendored gems to the latest version."
|
||||||
Homebrew::CLI::Parser.new do
|
switch "--no-commit",
|
||||||
description <<~EOS
|
description: "Do not generate a new commit upon completion."
|
||||||
Install and commit Homebrew's vendored gems.
|
switch "--non-bundler-gems",
|
||||||
EOS
|
description: "Update vendored gems that aren't using Bundler.",
|
||||||
|
hidden: true
|
||||||
|
|
||||||
comma_array "--update",
|
named_args :none
|
||||||
description: "Update the specified list of vendored gems to the latest version."
|
|
||||||
switch "--no-commit",
|
|
||||||
description: "Do not generate a new commit upon completion."
|
|
||||||
switch "--non-bundler-gems",
|
|
||||||
description: "Update vendored gems that aren't using Bundler.",
|
|
||||||
hidden: true
|
|
||||||
|
|
||||||
named_args :none
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
sig { void }
|
|
||||||
def vendor_gems
|
|
||||||
args = vendor_gems_args.parse
|
|
||||||
|
|
||||||
Homebrew.install_bundler!
|
|
||||||
|
|
||||||
ENV["BUNDLE_WITH"] = Homebrew.valid_gem_groups.join(":")
|
|
||||||
|
|
||||||
ohai "cd #{HOMEBREW_LIBRARY_PATH}"
|
|
||||||
HOMEBREW_LIBRARY_PATH.cd do
|
|
||||||
if args.update
|
|
||||||
ohai "bundle update"
|
|
||||||
safe_system "bundle", "update", *args.update
|
|
||||||
|
|
||||||
unless args.no_commit?
|
|
||||||
ohai "git add Gemfile.lock"
|
|
||||||
system "git", "add", "Gemfile.lock"
|
|
||||||
end
|
|
||||||
end
|
end
|
||||||
|
|
||||||
ohai "bundle install --standalone"
|
sig { override.void }
|
||||||
safe_system "bundle", "install", "--standalone"
|
def run
|
||||||
|
Homebrew.install_bundler!
|
||||||
|
|
||||||
ohai "bundle pristine"
|
ENV["BUNDLE_WITH"] = Homebrew.valid_gem_groups.join(":")
|
||||||
safe_system "bundle", "pristine"
|
|
||||||
|
|
||||||
# Workaround Bundler 2.4.21 issue where platforms may be removed.
|
ohai "cd #{HOMEBREW_LIBRARY_PATH}"
|
||||||
# Although we don't use 2.4.21, Dependabot does as it currently ignores your lockfile version.
|
HOMEBREW_LIBRARY_PATH.cd do
|
||||||
# https://github.com/rubygems/rubygems/issues/7169
|
if args.update
|
||||||
safe_system "bundle", "lock", "--add-platform", "aarch64-linux", "arm-linux"
|
ohai "bundle update"
|
||||||
system "git", "add", "Gemfile.lock" unless args.no_commit?
|
safe_system "bundle", "update", *args.update
|
||||||
|
|
||||||
if args.non_bundler_gems?
|
unless args.no_commit?
|
||||||
%w[
|
ohai "git add Gemfile.lock"
|
||||||
mechanize
|
system "git", "add", "Gemfile.lock"
|
||||||
].each do |gem|
|
end
|
||||||
(HOMEBREW_LIBRARY_PATH/"vendor/gems").cd do
|
|
||||||
Pathname.glob("#{gem}-*/").each { |path| FileUtils.rm_r(path) }
|
|
||||||
end
|
end
|
||||||
ohai "gem install #{gem}"
|
|
||||||
safe_system "gem", "install", gem, "--install-dir", "vendor",
|
|
||||||
"--no-document", "--no-wrappers", "--ignore-dependencies", "--force"
|
|
||||||
(HOMEBREW_LIBRARY_PATH/"vendor/gems").cd do
|
|
||||||
source = Pathname.glob("#{gem}-*/").first
|
|
||||||
next if source.blank?
|
|
||||||
|
|
||||||
# We cannot use `#ln_sf` here because that has unintended consequences when
|
ohai "bundle install --standalone"
|
||||||
# the symlink we want to create exists and points to an existing directory.
|
safe_system "bundle", "install", "--standalone"
|
||||||
FileUtils.rm_f gem
|
|
||||||
FileUtils.ln_s source, gem
|
ohai "bundle pristine"
|
||||||
|
safe_system "bundle", "pristine"
|
||||||
|
|
||||||
|
# Workaround Bundler 2.4.21 issue where platforms may be removed.
|
||||||
|
# Although we don't use 2.4.21, Dependabot does as it currently ignores your lockfile version.
|
||||||
|
# https://github.com/rubygems/rubygems/issues/7169
|
||||||
|
safe_system "bundle", "lock", "--add-platform", "aarch64-linux", "arm-linux"
|
||||||
|
system "git", "add", "Gemfile.lock" unless args.no_commit?
|
||||||
|
|
||||||
|
if args.non_bundler_gems?
|
||||||
|
%w[
|
||||||
|
mechanize
|
||||||
|
].each do |gem|
|
||||||
|
(HOMEBREW_LIBRARY_PATH/"vendor/gems").cd do
|
||||||
|
Pathname.glob("#{gem}-*/").each { |path| FileUtils.rm_r(path) }
|
||||||
|
end
|
||||||
|
ohai "gem install #{gem}"
|
||||||
|
safe_system "gem", "install", gem, "--install-dir", "vendor",
|
||||||
|
"--no-document", "--no-wrappers", "--ignore-dependencies", "--force"
|
||||||
|
(HOMEBREW_LIBRARY_PATH/"vendor/gems").cd do
|
||||||
|
source = Pathname.glob("#{gem}-*/").first
|
||||||
|
next if source.blank?
|
||||||
|
|
||||||
|
# We cannot use `#ln_sf` here because that has unintended consequences when
|
||||||
|
# the symlink we want to create exists and points to an existing directory.
|
||||||
|
FileUtils.rm_f gem
|
||||||
|
FileUtils.ln_s source, gem
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
unless args.no_commit?
|
||||||
|
ohai "git add vendor"
|
||||||
|
system "git", "add", "vendor"
|
||||||
|
|
||||||
|
Utils::Git.set_name_email!
|
||||||
|
Utils::Git.setup_gpg!
|
||||||
|
|
||||||
|
ohai "git commit"
|
||||||
|
system "git", "commit", "--message", "brew vendor-gems: commit updates."
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
unless args.no_commit?
|
|
||||||
ohai "git add vendor"
|
|
||||||
system "git", "add", "vendor"
|
|
||||||
|
|
||||||
Utils::Git.set_name_email!
|
|
||||||
Utils::Git.setup_gpg!
|
|
||||||
|
|
||||||
ohai "git commit"
|
|
||||||
system "git", "commit", "--message", "brew vendor-gems: commit updates."
|
|
||||||
end
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|||||||
@ -1,7 +1,8 @@
|
|||||||
# frozen_string_literal: true
|
# frozen_string_literal: true
|
||||||
|
|
||||||
require "cmd/shared_examples/args_parse"
|
require "cmd/shared_examples/args_parse"
|
||||||
|
require "dev-cmd/vendor-gems"
|
||||||
|
|
||||||
RSpec.describe "brew vendor-gems" do
|
RSpec.describe Homebrew::DevCmd::VendorGems do
|
||||||
it_behaves_like "parseable arguments"
|
it_behaves_like "parseable arguments"
|
||||||
end
|
end
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user