Pass args to build instead of using global args.

This commit is contained in:
Markus Reiter 2020-07-23 02:06:38 +02:00
parent cfbe1fb3c7
commit 9176c62246

View File

@ -16,13 +16,14 @@ require "socket"
require "cmd/install" require "cmd/install"
class Build class Build
attr_reader :formula, :deps, :reqs attr_reader :formula, :deps, :reqs, :args
def initialize(formula, options) def initialize(formula, options, args:)
@formula = formula @formula = formula
@formula.build = BuildOptions.new(options, formula.options) @formula.build = BuildOptions.new(options, formula.options)
@args = args
if Homebrew.args.ignore_deps? if args.ignore_deps?
@deps = [] @deps = []
@reqs = [] @reqs = []
else else
@ -125,19 +126,19 @@ class Build
# which is not known until after the formula has been staged. # which is not known until after the formula has been staged.
ENV["HOMEBREW_FORMULA_PREFIX"] = formula.prefix ENV["HOMEBREW_FORMULA_PREFIX"] = formula.prefix
staging.retain! if Homebrew.args.keep_tmp? staging.retain! if args.keep_tmp?
formula.patch formula.patch
if Homebrew.args.git? if args.git?
system "git", "init" system "git", "init"
system "git", "add", "-A" system "git", "add", "-A"
end end
if Homebrew.args.interactive? if args.interactive?
ohai "Entering interactive mode" ohai "Entering interactive mode"
puts "Type `exit` to return and finalize the installation." puts "Type `exit` to return and finalize the installation."
puts "Install to this prefix: #{formula.prefix}" puts "Install to this prefix: #{formula.prefix}"
if Homebrew.args.git? if args.git?
puts "This directory is now a git repo. Make your changes and then use:" puts "This directory is now a git repo. Make your changes and then use:"
puts " git diff | pbcopy" puts " git diff | pbcopy"
puts "to copy the diff to the clipboard." puts "to copy the diff to the clipboard."
@ -190,15 +191,15 @@ class Build
end end
begin begin
Homebrew.install_args.parse args = Homebrew.install_args.parse
error_pipe = UNIXSocket.open(ENV["HOMEBREW_ERROR_PIPE"], &:recv_io) error_pipe = UNIXSocket.open(ENV["HOMEBREW_ERROR_PIPE"], &:recv_io)
error_pipe.fcntl(Fcntl::F_SETFD, Fcntl::FD_CLOEXEC) error_pipe.fcntl(Fcntl::F_SETFD, Fcntl::FD_CLOEXEC)
trap("INT", old_trap) trap("INT", old_trap)
formula = Homebrew.args.formulae.first formula = args.formulae.first
options = Options.create(Homebrew.args.flags_only) options = Options.create(args.flags_only)
build = Build.new(formula, options) build = Build.new(formula, options, args: args)
build.install build.install
rescue Exception => e # rubocop:disable Lint/RescueException rescue Exception => e # rubocop:disable Lint/RescueException
error_hash = JSON.parse e.to_json error_hash = JSON.parse e.to_json