brew/Library/Homebrew/dev-cmd/vendor-gems.rb
Gibson Fahnestock 07d571bebc
fix(vendor-gems): redirect bundler stdout to stderr
When running brew commands and interpreting the output, e.g. running
`brew livecheck --json`, it's necessary to stop other programs Homebrew
happens to execute from writing logging output to stdout. Most programs
don't do this, but `bundle install` does seem to.

To reproduce the issue you can run:

```shell
git -C "$(brew --prefix)" clean -ffdx Library/Homebrew/vendor
stdout=$(HOMEBREW_FORCE_VENDOR_RUBY=1 brew livecheck --newer-only --json --cask $(brew --repo homebrew/cask)/Casks/grid.rb)
echo "^^^ was stderr, >>> is stdout: $stdout"
```

If you run it without this change it will print a bunch of output like
this to the stdout before printing out the livecheck JSON output:

```text
Using bundler 1.17.3
Fetching byebug 11.1.3
Fetching coderay 1.1.3
Installing byebug 11.1.3 with native extensions
Installing coderay 1.1.3
Fetching colorize 0.8.1
Installing colorize 0.8.1

[
  # Contents of the JSON block.
]
```

With this change the stdout from `bundle install` will be redirected to
brew's stderr, meaning only the JSON goes to stdout, and the rest goes
to stderr.
2021-06-03 11:18:23 +01:00

59 lines
1.3 KiB
Ruby

# typed: false
# frozen_string_literal: true
require "formula"
require "cli/parser"
module Homebrew
extend T::Sig
module_function
sig { returns(CLI::Parser) }
def vendor_gems_args
Homebrew::CLI::Parser.new do
description <<~EOS
Install and commit Homebrew's vendored gems.
EOS
comma_array "--update",
description: "Update all vendored Gems to the latest version."
named_args :none
end
end
sig { void }
def vendor_gems
args = vendor_gems_args.parse
Homebrew.install_bundler!
ohai "cd #{HOMEBREW_LIBRARY_PATH}"
HOMEBREW_LIBRARY_PATH.cd do
if args.update
ohai "bundle update"
safe_system "bundle", "update", *args.update
ohai "git add Gemfile.lock"
system "git", "add", "Gemfile.lock"
end
ohai "bundle install --standalone"
safe_system_redirect_stdout_to_stderr "bundle", "install", "--standalone"
ohai "bundle pristine"
safe_system "bundle", "pristine"
ohai "git add vendor/bundle"
system "git", "add", "vendor/bundle"
Utils::Git.set_name_email!
Utils::Git.setup_gpg!
ohai "git commit"
system "git", "commit", "--message", "brew vendor-gems: commit updates."
end
end
end