brew/Library/Homebrew/dev-cmd/vendor-gems.rb

89 lines
2.5 KiB
Ruby
Raw Normal View History

2023-04-04 22:13:58 -07:00
# typed: true
# frozen_string_literal: true
2019-04-17 18:25:08 +09:00
require "cli/parser"
module Homebrew
module_function
2020-10-20 12:03:48 +02:00
sig { returns(CLI::Parser) }
def vendor_gems_args
Homebrew::CLI::Parser.new do
description <<~EOS
Install and commit Homebrew's vendored gems.
EOS
2020-07-30 18:40:10 +02:00
comma_array "--update",
2023-02-10 23:15:40 -05:00
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
2021-01-10 14:26:40 -05:00
named_args :none
end
end
sig { void }
def vendor_gems
args = vendor_gems_args.parse
Homebrew.install_bundler!
2023-04-10 16:53:59 +01:00
ENV["BUNDLE_WITH"] = Homebrew.valid_gem_groups.join(":")
# System Ruby does not pick up the correct SDK by default.
ENV["SDKROOT"] = MacOS.sdk_path if ENV["HOMEBREW_MACOS_SYSTEM_RUBY_NEW_ENOUGH"]
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
ohai "bundle install --standalone"
safe_system "bundle", "install", "--standalone"
ohai "bundle pristine"
safe_system "bundle", "pristine"
if args.non_bundler_gems?
%w[
mechanize
].each do |gem|
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