2024-06-02 15:14:25 +01:00
|
|
|
# typed: strict
|
2019-04-19 15:38:03 +09:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
2024-03-21 22:18:21 -07:00
|
|
|
require "abstract_command"
|
2024-07-14 13:07:00 -04:00
|
|
|
require "utils/git"
|
2018-12-21 20:09:08 +00:00
|
|
|
|
|
|
|
module Homebrew
|
2024-03-21 22:18:21 -07:00
|
|
|
module DevCmd
|
|
|
|
class VendorGems < AbstractCommand
|
|
|
|
cmd_args do
|
|
|
|
description <<~EOS
|
|
|
|
Install and commit Homebrew's vendored gems.
|
|
|
|
EOS
|
|
|
|
|
|
|
|
comma_array "--update",
|
|
|
|
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
|
2020-11-19 09:22:01 +01:00
|
|
|
end
|
|
|
|
|
2024-03-21 22:18:21 -07:00
|
|
|
sig { override.void }
|
|
|
|
def run
|
|
|
|
Homebrew.install_bundler!
|
2018-12-21 20:09:08 +00:00
|
|
|
|
2024-03-21 22:18:21 -07:00
|
|
|
ENV["BUNDLE_WITH"] = Homebrew.valid_gem_groups.join(":")
|
2019-03-11 12:39:06 +00:00
|
|
|
|
2024-03-21 22:18:21 -07:00
|
|
|
ohai "cd #{HOMEBREW_LIBRARY_PATH}"
|
|
|
|
HOMEBREW_LIBRARY_PATH.cd do
|
|
|
|
if args.update
|
|
|
|
ohai "bundle update"
|
|
|
|
safe_system "bundle", "update", *args.update
|
2023-11-17 16:51:03 +00:00
|
|
|
|
2024-03-21 22:18:21 -07:00
|
|
|
unless args.no_commit?
|
|
|
|
ohai "git add Gemfile.lock"
|
|
|
|
system "git", "add", "Gemfile.lock"
|
|
|
|
end
|
2024-01-31 09:28:36 -08:00
|
|
|
end
|
2024-03-21 22:18:21 -07:00
|
|
|
|
|
|
|
ohai "bundle install --standalone"
|
|
|
|
safe_system "bundle", "install", "--standalone"
|
|
|
|
|
|
|
|
ohai "bundle pristine"
|
|
|
|
safe_system "bundle", "pristine"
|
|
|
|
|
2024-05-23 06:24:24 +01:00
|
|
|
ohai "bundle clean"
|
|
|
|
safe_system "bundle", "clean"
|
|
|
|
|
2024-03-21 22:18:21 -07:00
|
|
|
# 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
|
2023-04-24 10:32:10 +01:00
|
|
|
end
|
|
|
|
|
2024-03-21 22:18:21 -07:00
|
|
|
unless args.no_commit?
|
|
|
|
ohai "git add vendor"
|
|
|
|
system "git", "add", "vendor"
|
2018-12-21 20:09:08 +00:00
|
|
|
|
2024-03-21 22:18:21 -07:00
|
|
|
Utils::Git.set_name_email!
|
|
|
|
Utils::Git.setup_gpg!
|
2018-12-21 20:09:08 +00:00
|
|
|
|
2024-03-21 22:18:21 -07:00
|
|
|
ohai "git commit"
|
|
|
|
system "git", "commit", "--message", "brew vendor-gems: commit updates."
|
|
|
|
end
|
|
|
|
end
|
2022-10-08 18:39:47 +01:00
|
|
|
end
|
2018-12-21 20:09:08 +00:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|