Class: Homebrew::DevCmd::VendorGems Private

Inherits:
AbstractCommand show all
Defined in:
dev-cmd/vendor-gems.rb,
sorbet/rbi/dsl/homebrew/dev_cmd/vendor_gems.rbi

This class is part of a private API. This class may only be used in the Homebrew/brew repository. Third parties should avoid using this class if possible, as it may be removed or changed without warning.

Defined Under Namespace

Classes: Args

Instance Method Summary collapse

Methods inherited from AbstractCommand

command, command_name, dev_cmd?, #initialize, parser, ruby_cmd?

Constructor Details

This class inherits a constructor from Homebrew::AbstractCommand

Instance Method Details

#argsHomebrew::DevCmd::VendorGems::Args

This method is part of a private API. This method may only be used in the Homebrew/brew repository. Third parties should avoid using this method if possible, as it may be removed or changed without warning.



10
# File 'sorbet/rbi/dsl/homebrew/dev_cmd/vendor_gems.rbi', line 10

def args; end

#runvoid

This method is part of a private API. This method may only be used in the Homebrew/brew repository. Third parties should avoid using this method if possible, as it may be removed or changed without warning.

This method returns an undefined value.



27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
# File 'dev-cmd/vendor-gems.rb', line 27

def run
  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"
      run_bundle "update", *args.update

      unless args.no_commit?
        ohai "git add Gemfile.lock"
        system "git", "add", "Gemfile.lock"
      end
    end

    ohai "bundle install --standalone"
    run_bundle "install", "--standalone"

    ohai "bundle pristine"
    run_bundle "pristine"

    ohai "bundle clean"
    run_bundle "clean"

    # 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
    run_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

#run_bundle(*args) ⇒ void

This method is part of a private API. This method may only be used in the Homebrew/brew repository. Third parties should avoid using this method if possible, as it may be removed or changed without warning.

This method returns an undefined value.

Parameters:

Raises:



95
96
97
98
99
100
101
102
103
# File 'dev-cmd/vendor-gems.rb', line 95

def run_bundle(*args)
  Process.wait(fork do
    # Native build scripts fail if EUID != UID
    Process::UID.change_privilege(Process.euid) if Process.euid != Process.uid
    exec "bundle", *args
  end)

  raise ErrorDuringExecution.new(["bundle", *args], status: $CHILD_STATUS) unless $CHILD_STATUS.success?
end