Replace Homebrew.args with Context.
				
					
				
			This commit is contained in:
		
							parent
							
								
									9d6350037f
								
							
						
					
					
						commit
						490e503b1b
					
				@ -4,6 +4,8 @@ require "utils/curl"
 | 
			
		||||
require "json"
 | 
			
		||||
 | 
			
		||||
class Bintray
 | 
			
		||||
  include Context
 | 
			
		||||
 | 
			
		||||
  API_URL = "https://api.bintray.com"
 | 
			
		||||
 | 
			
		||||
  class Error < RuntimeError
 | 
			
		||||
@ -13,9 +15,8 @@ class Bintray
 | 
			
		||||
    "#<Bintray: org=#{@bintray_org}>"
 | 
			
		||||
  end
 | 
			
		||||
 | 
			
		||||
  def initialize(org: "homebrew", verbose: false)
 | 
			
		||||
  def initialize(org: "homebrew")
 | 
			
		||||
    @bintray_org = org
 | 
			
		||||
    @verbose = verbose
 | 
			
		||||
 | 
			
		||||
    raise UsageError, "Must set a Bintray organisation!" unless @bintray_org
 | 
			
		||||
 | 
			
		||||
@ -33,8 +34,8 @@ class Bintray
 | 
			
		||||
    end
 | 
			
		||||
 | 
			
		||||
    curl(*args, url,
 | 
			
		||||
         show_output: @verbose,
 | 
			
		||||
         secrets:     @bintray_key)
 | 
			
		||||
         show_output: verbose?,
 | 
			
		||||
         secrets:     key)
 | 
			
		||||
  end
 | 
			
		||||
 | 
			
		||||
  def upload(local_file, repo:, package:, version:, remote_file:, sha256: nil)
 | 
			
		||||
 | 
			
		||||
@ -61,6 +61,7 @@ begin
 | 
			
		||||
 | 
			
		||||
  args = Homebrew::CLI::Parser.new.parse(ARGV.dup.freeze, ignore_invalid_options: true)
 | 
			
		||||
  Homebrew.args = args
 | 
			
		||||
  Context.current = args.context
 | 
			
		||||
 | 
			
		||||
  path = PATH.new(ENV["PATH"])
 | 
			
		||||
  homebrew_path = PATH.new(ENV["HOMEBREW_PATH"])
 | 
			
		||||
 | 
			
		||||
@ -143,8 +143,6 @@ class Build
 | 
			
		||||
        fetch:       false,
 | 
			
		||||
        keep_tmp:    args.keep_tmp?,
 | 
			
		||||
        interactive: args.interactive?,
 | 
			
		||||
        debug:       args.debug?,
 | 
			
		||||
        verbose:     args.verbose?,
 | 
			
		||||
      ) do
 | 
			
		||||
        # For head builds, HOMEBREW_FORMULA_PREFIX should include the commit,
 | 
			
		||||
        # which is not known until after the formula has been staged.
 | 
			
		||||
@ -214,9 +212,8 @@ class Build
 | 
			
		||||
end
 | 
			
		||||
 | 
			
		||||
begin
 | 
			
		||||
  Homebrew.args = Homebrew::CLI::Parser.new.parse(ARGV.dup.freeze, ignore_invalid_options: true)
 | 
			
		||||
 | 
			
		||||
  args = Homebrew.install_args.parse
 | 
			
		||||
  Context.current = args.context
 | 
			
		||||
 | 
			
		||||
  error_pipe = UNIXSocket.open(ENV["HOMEBREW_ERROR_PIPE"], &:recv_io)
 | 
			
		||||
  error_pipe.fcntl(Fcntl::F_SETFD, Fcntl::FD_CLOEXEC)
 | 
			
		||||
 | 
			
		||||
@ -35,6 +35,8 @@ require "cask/cmd/internal_stanza"
 | 
			
		||||
 | 
			
		||||
module Cask
 | 
			
		||||
  class Cmd
 | 
			
		||||
    include Context
 | 
			
		||||
 | 
			
		||||
    ALIASES = {
 | 
			
		||||
      "ls"       => "list",
 | 
			
		||||
      "homepage" => "home",
 | 
			
		||||
@ -154,7 +156,7 @@ module Cask
 | 
			
		||||
      end
 | 
			
		||||
    rescue CaskError, MethodDeprecatedError, ArgumentError, OptionParser::InvalidOption => e
 | 
			
		||||
      onoe e.message
 | 
			
		||||
      $stderr.puts e.backtrace if Homebrew.args.debug?
 | 
			
		||||
      $stderr.puts e.backtrace if debug?
 | 
			
		||||
      exit 1
 | 
			
		||||
    rescue StandardError, ScriptError, NoMemoryError => e
 | 
			
		||||
      onoe e.message
 | 
			
		||||
 | 
			
		||||
@ -10,15 +10,11 @@
 | 
			
		||||
# * sets permissions on executables
 | 
			
		||||
# * removes unresolved symlinks
 | 
			
		||||
class Cleaner
 | 
			
		||||
  extend Predicable
 | 
			
		||||
 | 
			
		||||
  attr_predicate :verbose?, :debug?
 | 
			
		||||
  include Context
 | 
			
		||||
 | 
			
		||||
  # Create a cleaner for the given formula
 | 
			
		||||
  def initialize(f, verbose: false, debug: false)
 | 
			
		||||
  def initialize(f)
 | 
			
		||||
    @f = f
 | 
			
		||||
    @verbose = verbose
 | 
			
		||||
    @debug = debug
 | 
			
		||||
  end
 | 
			
		||||
 | 
			
		||||
  # Clean the keg of formula @f
 | 
			
		||||
 | 
			
		||||
@ -188,6 +188,10 @@ module Homebrew
 | 
			
		||||
        flag_with_value.delete_prefix(arg_prefix)
 | 
			
		||||
      end
 | 
			
		||||
 | 
			
		||||
      def context
 | 
			
		||||
        Context::ContextStruct.new(debug: debug?, quiet: quiet?, verbose: verbose?)
 | 
			
		||||
      end
 | 
			
		||||
 | 
			
		||||
      private
 | 
			
		||||
 | 
			
		||||
      def option_to_name(option)
 | 
			
		||||
 | 
			
		||||
@ -133,7 +133,7 @@ module Homebrew
 | 
			
		||||
    already_fetched = f.cached_download.exist?
 | 
			
		||||
 | 
			
		||||
    begin
 | 
			
		||||
      download = f.fetch(verify_download_integrity: false, verbose: args.verbose?)
 | 
			
		||||
      download = f.fetch(verify_download_integrity: false)
 | 
			
		||||
    rescue DownloadError
 | 
			
		||||
      retry if retry_fetch?(f, args: args)
 | 
			
		||||
      raise
 | 
			
		||||
@ -144,6 +144,6 @@ module Homebrew
 | 
			
		||||
    puts "Downloaded to: #{download}" unless already_fetched
 | 
			
		||||
    puts Checksum::TYPES.map { |t| "#{t.to_s.upcase}: #{download.send(t)}" }
 | 
			
		||||
 | 
			
		||||
    f.verify_download_integrity(download, verbose: args.verbose?)
 | 
			
		||||
    f.verify_download_integrity(download)
 | 
			
		||||
  end
 | 
			
		||||
end
 | 
			
		||||
 | 
			
		||||
@ -258,7 +258,7 @@ module Homebrew
 | 
			
		||||
    Install.perform_preinstall_checks(cc: args.cc)
 | 
			
		||||
 | 
			
		||||
    formulae.each do |f|
 | 
			
		||||
      Migrator.migrate_if_needed(f, force: args.force?, verbose: args.verbose?)
 | 
			
		||||
      Migrator.migrate_if_needed(f, force: args.force?)
 | 
			
		||||
      install_formula(f, args: args)
 | 
			
		||||
      Cleanup.install_formula_clean!(f)
 | 
			
		||||
    end
 | 
			
		||||
 | 
			
		||||
@ -33,7 +33,7 @@ module Homebrew
 | 
			
		||||
        raise "#{rack} is a symlink" if rack.symlink?
 | 
			
		||||
      end
 | 
			
		||||
 | 
			
		||||
      migrator = Migrator.new(f, force: args.force?, verbose: args.verbose?)
 | 
			
		||||
      migrator = Migrator.new(f, force: args.force?)
 | 
			
		||||
      migrator.migrate
 | 
			
		||||
    end
 | 
			
		||||
  end
 | 
			
		||||
 | 
			
		||||
@ -94,7 +94,7 @@ module Homebrew
 | 
			
		||||
      if formula_or_cask.is_a?(Formula)
 | 
			
		||||
        f = formula_or_cask
 | 
			
		||||
 | 
			
		||||
        if verbose? args: args
 | 
			
		||||
        if verbose?
 | 
			
		||||
          outdated_kegs = f.outdated_kegs(fetch_head: args.fetch_HEAD?)
 | 
			
		||||
 | 
			
		||||
          current_version = if f.alias_changed?
 | 
			
		||||
@ -122,7 +122,7 @@ module Homebrew
 | 
			
		||||
      else
 | 
			
		||||
        c = formula_or_cask
 | 
			
		||||
 | 
			
		||||
        puts c.outdated_info(args.greedy?, verbose?(args: args), false)
 | 
			
		||||
        puts c.outdated_info(args.greedy?, verbose?, false)
 | 
			
		||||
      end
 | 
			
		||||
    end
 | 
			
		||||
  end
 | 
			
		||||
@ -147,13 +147,13 @@ module Homebrew
 | 
			
		||||
      else
 | 
			
		||||
        c = formula_or_cask
 | 
			
		||||
 | 
			
		||||
        c.outdated_info(args.greedy?, verbose?(args: args), true)
 | 
			
		||||
        c.outdated_info(args.greedy?, verbose?, true)
 | 
			
		||||
      end
 | 
			
		||||
    end
 | 
			
		||||
  end
 | 
			
		||||
 | 
			
		||||
  def verbose?(args:)
 | 
			
		||||
    ($stdout.tty? || args.verbose?) && !args.quiet?
 | 
			
		||||
  def verbose?
 | 
			
		||||
    ($stdout.tty? || super) && !quiet?
 | 
			
		||||
  end
 | 
			
		||||
 | 
			
		||||
  def json_version(version)
 | 
			
		||||
 | 
			
		||||
@ -67,7 +67,7 @@ module Homebrew
 | 
			
		||||
        onoe "#{f.full_name} is pinned. You must unpin it to reinstall."
 | 
			
		||||
        next
 | 
			
		||||
      end
 | 
			
		||||
      Migrator.migrate_if_needed(f, force: args.force?, verbose: args.verbose?)
 | 
			
		||||
      Migrator.migrate_if_needed(f, force: args.force?)
 | 
			
		||||
      reinstall_formula(f, args: args)
 | 
			
		||||
      Cleanup.install_formula_clean!(f)
 | 
			
		||||
    end
 | 
			
		||||
 | 
			
		||||
@ -395,7 +395,7 @@ class Reporter
 | 
			
		||||
        next
 | 
			
		||||
      end
 | 
			
		||||
 | 
			
		||||
      Migrator.migrate_if_needed(f, force: force, verbose: verbose)
 | 
			
		||||
      Migrator.migrate_if_needed(f, force: force)
 | 
			
		||||
    end
 | 
			
		||||
  end
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
							
								
								
									
										71
									
								
								Library/Homebrew/context.rb
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										71
									
								
								Library/Homebrew/context.rb
									
									
									
									
									
										Normal file
									
								
							@ -0,0 +1,71 @@
 | 
			
		||||
# frozen_string_literal: true
 | 
			
		||||
 | 
			
		||||
require "monitor"
 | 
			
		||||
 | 
			
		||||
module Context
 | 
			
		||||
  extend MonitorMixin
 | 
			
		||||
 | 
			
		||||
  def self.current=(context)
 | 
			
		||||
    synchronize do
 | 
			
		||||
      @current = context
 | 
			
		||||
    end
 | 
			
		||||
  end
 | 
			
		||||
 | 
			
		||||
  def self.current
 | 
			
		||||
    if current_context = Thread.current[:context]
 | 
			
		||||
      return current_context
 | 
			
		||||
    end
 | 
			
		||||
 | 
			
		||||
    synchronize do
 | 
			
		||||
      @current ||= ContextStruct.new
 | 
			
		||||
    end
 | 
			
		||||
  end
 | 
			
		||||
 | 
			
		||||
  class ContextStruct
 | 
			
		||||
    def initialize(debug: nil, quiet: nil, verbose: nil)
 | 
			
		||||
      @debug = debug
 | 
			
		||||
      @quiet = quiet
 | 
			
		||||
      @verbose = verbose
 | 
			
		||||
    end
 | 
			
		||||
 | 
			
		||||
    def debug?
 | 
			
		||||
      @debug
 | 
			
		||||
    end
 | 
			
		||||
 | 
			
		||||
    def quiet?
 | 
			
		||||
      @quiet
 | 
			
		||||
    end
 | 
			
		||||
 | 
			
		||||
    def verbose?
 | 
			
		||||
      @verbose
 | 
			
		||||
    end
 | 
			
		||||
  end
 | 
			
		||||
 | 
			
		||||
  def debug?
 | 
			
		||||
    Context.current.debug?
 | 
			
		||||
  end
 | 
			
		||||
 | 
			
		||||
  def quiet?
 | 
			
		||||
    Context.current.quiet?
 | 
			
		||||
  end
 | 
			
		||||
 | 
			
		||||
  def verbose?
 | 
			
		||||
    Context.current.verbose?
 | 
			
		||||
  end
 | 
			
		||||
 | 
			
		||||
  def with_context(**options)
 | 
			
		||||
    old_context = Thread.current[:context]
 | 
			
		||||
 | 
			
		||||
    new_context = ContextStruct.new(
 | 
			
		||||
      debug:   options.fetch(:debug, old_context&.debug?),
 | 
			
		||||
      quiet:   options.fetch(:quiet, old_context&.quiet?),
 | 
			
		||||
      verbose: options.fetch(:verbose, old_context&.verbose?),
 | 
			
		||||
    )
 | 
			
		||||
 | 
			
		||||
    Thread.current[:context] = new_context
 | 
			
		||||
 | 
			
		||||
    yield
 | 
			
		||||
  ensure
 | 
			
		||||
    Thread.current[:context] = old_context
 | 
			
		||||
  end
 | 
			
		||||
end
 | 
			
		||||
@ -31,7 +31,7 @@ module Homebrew
 | 
			
		||||
    bintray_org = args.bintray_org || "homebrew"
 | 
			
		||||
    bintray_repo = args.bintray_repo || "mirror"
 | 
			
		||||
 | 
			
		||||
    bintray = Bintray.new(org: bintray_org, verbose: args.verbose?)
 | 
			
		||||
    bintray = Bintray.new(org: bintray_org)
 | 
			
		||||
 | 
			
		||||
    args.formulae.each do |formula|
 | 
			
		||||
      mirror_url = bintray.mirror_formula(formula, repo: bintray_repo, publish_package: !args.no_publish?)
 | 
			
		||||
 | 
			
		||||
@ -116,7 +116,7 @@ module Homebrew
 | 
			
		||||
      # git cherry-pick unfortunately has no quiet option
 | 
			
		||||
      ohai "Cherry-picking #{commit_count} commit#{"s" unless commit_count == 1} from ##{pr}"
 | 
			
		||||
      cherry_pick_args = "git", "-C", path, "cherry-pick", "--ff", "--allow-empty", "#{merge_base}..FETCH_HEAD"
 | 
			
		||||
      result = Homebrew.args.verbose? ? system(*cherry_pick_args) : quiet_system(*cherry_pick_args)
 | 
			
		||||
      result = args.verbose? ? system(*cherry_pick_args) : quiet_system(*cherry_pick_args)
 | 
			
		||||
 | 
			
		||||
      unless result
 | 
			
		||||
        if args.resolve?
 | 
			
		||||
 | 
			
		||||
@ -49,7 +49,7 @@ module Homebrew
 | 
			
		||||
    args = pr_upload_args.parse
 | 
			
		||||
 | 
			
		||||
    bintray_org = args.bintray_org || "homebrew"
 | 
			
		||||
    bintray = Bintray.new(org: bintray_org, verbose: args.verbose?)
 | 
			
		||||
    bintray = Bintray.new(org: bintray_org)
 | 
			
		||||
 | 
			
		||||
    json_files = Dir["*.json"]
 | 
			
		||||
    odie "No JSON files found in the current working directory" if json_files.empty?
 | 
			
		||||
 | 
			
		||||
@ -57,7 +57,7 @@ module Homebrew
 | 
			
		||||
 | 
			
		||||
      # show messages about tar
 | 
			
		||||
      with_env VERBOSE: "1" do
 | 
			
		||||
        f.brew(debug: args.debug?) do
 | 
			
		||||
        f.brew do
 | 
			
		||||
          f.patch if args.patch?
 | 
			
		||||
          cp_r getwd, stage_dir, preserve: true
 | 
			
		||||
        end
 | 
			
		||||
 | 
			
		||||
@ -13,6 +13,7 @@ require "mechanize/http/content_disposition_parser"
 | 
			
		||||
class AbstractDownloadStrategy
 | 
			
		||||
  extend Forwardable
 | 
			
		||||
  include FileUtils
 | 
			
		||||
  include Context
 | 
			
		||||
 | 
			
		||||
  module Pourable
 | 
			
		||||
    def stage
 | 
			
		||||
@ -21,9 +22,9 @@ class AbstractDownloadStrategy
 | 
			
		||||
    end
 | 
			
		||||
  end
 | 
			
		||||
 | 
			
		||||
  attr_reader :cache, :cached_location, :url, :meta, :name, :version, :shutup
 | 
			
		||||
  attr_reader :cache, :cached_location, :url, :meta, :name, :version
 | 
			
		||||
 | 
			
		||||
  private :meta, :name, :version, :shutup
 | 
			
		||||
  private :meta, :name, :version
 | 
			
		||||
 | 
			
		||||
  def initialize(url, name, version, **meta)
 | 
			
		||||
    @url = url
 | 
			
		||||
@ -31,24 +32,18 @@ class AbstractDownloadStrategy
 | 
			
		||||
    @version = version
 | 
			
		||||
    @cache = meta.fetch(:cache, HOMEBREW_CACHE)
 | 
			
		||||
    @meta = meta
 | 
			
		||||
    @shutup = false
 | 
			
		||||
    extend Pourable if meta[:bottle]
 | 
			
		||||
  end
 | 
			
		||||
 | 
			
		||||
  # Download and cache the resource as {#cached_location}.
 | 
			
		||||
  def fetch; end
 | 
			
		||||
 | 
			
		||||
  # Suppress output
 | 
			
		||||
  def shutup!
 | 
			
		||||
    @shutup = true
 | 
			
		||||
  end
 | 
			
		||||
 | 
			
		||||
  def puts(*args)
 | 
			
		||||
    super(*args) unless shutup
 | 
			
		||||
    super(*args) unless quiet?
 | 
			
		||||
  end
 | 
			
		||||
 | 
			
		||||
  def ohai(*args)
 | 
			
		||||
    super(*args) unless shutup
 | 
			
		||||
    super(*args) unless quiet?
 | 
			
		||||
  end
 | 
			
		||||
 | 
			
		||||
  # Unpack {#cached_location} into the current working directory, and possibly
 | 
			
		||||
@ -60,7 +55,7 @@ class AbstractDownloadStrategy
 | 
			
		||||
                          ref_type: @ref_type, ref: @ref)
 | 
			
		||||
                  .extract_nestedly(basename:             basename,
 | 
			
		||||
                                    prioritise_extension: true,
 | 
			
		||||
                                    verbose:              Homebrew.args.verbose? && !shutup)
 | 
			
		||||
                                    verbose:              verbose? && !quiet?)
 | 
			
		||||
    chdir
 | 
			
		||||
  end
 | 
			
		||||
 | 
			
		||||
@ -102,9 +97,9 @@ class AbstractDownloadStrategy
 | 
			
		||||
  def system_command!(*args, **options)
 | 
			
		||||
    super(
 | 
			
		||||
      *args,
 | 
			
		||||
      print_stdout: !shutup,
 | 
			
		||||
      print_stderr: !shutup,
 | 
			
		||||
      verbose:      Homebrew.args.verbose? && !shutup,
 | 
			
		||||
      print_stdout: !quiet?,
 | 
			
		||||
      print_stderr: !quiet?,
 | 
			
		||||
      verbose:      verbose? && !quiet?,
 | 
			
		||||
      env:          env,
 | 
			
		||||
      **options,
 | 
			
		||||
    )
 | 
			
		||||
@ -498,7 +493,7 @@ class NoUnzipCurlDownloadStrategy < CurlDownloadStrategy
 | 
			
		||||
  def stage
 | 
			
		||||
    UnpackStrategy::Uncompressed.new(cached_location)
 | 
			
		||||
                                .extract(basename: basename,
 | 
			
		||||
                                         verbose:  Homebrew.args.verbose? && !shutup)
 | 
			
		||||
                                         verbose:  verbose? && !quiet?)
 | 
			
		||||
  end
 | 
			
		||||
end
 | 
			
		||||
 | 
			
		||||
@ -553,7 +548,7 @@ class SubversionDownloadStrategy < VCSDownloadStrategy
 | 
			
		||||
    # This saves on bandwidth and will have a similar effect to verifying the
 | 
			
		||||
    # cache as it will make any changes to get the right revision.
 | 
			
		||||
    args = []
 | 
			
		||||
    args << "--quiet" unless Homebrew.args.verbose?
 | 
			
		||||
    args << "--quiet" unless verbose?
 | 
			
		||||
 | 
			
		||||
    if revision
 | 
			
		||||
      ohai "Checking out #{@ref}"
 | 
			
		||||
@ -897,7 +892,7 @@ class CVSDownloadStrategy < VCSDownloadStrategy
 | 
			
		||||
  end
 | 
			
		||||
 | 
			
		||||
  def quiet_flag
 | 
			
		||||
    "-Q" unless Homebrew.args.verbose?
 | 
			
		||||
    "-Q" unless verbose?
 | 
			
		||||
  end
 | 
			
		||||
 | 
			
		||||
  def clone_repo
 | 
			
		||||
 | 
			
		||||
@ -419,6 +419,8 @@ require "extend/os/pathname"
 | 
			
		||||
# @private
 | 
			
		||||
module ObserverPathnameExtension
 | 
			
		||||
  class << self
 | 
			
		||||
    include Context
 | 
			
		||||
 | 
			
		||||
    attr_accessor :n, :d
 | 
			
		||||
 | 
			
		||||
    def reset_counts!
 | 
			
		||||
@ -437,8 +439,8 @@ module ObserverPathnameExtension
 | 
			
		||||
    MAXIMUM_VERBOSE_OUTPUT = 100
 | 
			
		||||
 | 
			
		||||
    def verbose?
 | 
			
		||||
      return Homebrew.args.verbose? unless ENV["CI"]
 | 
			
		||||
      return false unless Homebrew.args.verbose?
 | 
			
		||||
      return super unless ENV["CI"]
 | 
			
		||||
      return false unless super
 | 
			
		||||
 | 
			
		||||
      if total < MAXIMUM_VERBOSE_OUTPUT
 | 
			
		||||
        true
 | 
			
		||||
 | 
			
		||||
@ -54,6 +54,7 @@ class Formula
 | 
			
		||||
  include Utils::Inreplace
 | 
			
		||||
  include Utils::Shebang
 | 
			
		||||
  include Utils::Shell
 | 
			
		||||
  include Context
 | 
			
		||||
  extend Enumerable
 | 
			
		||||
  extend Forwardable
 | 
			
		||||
  extend Cachable
 | 
			
		||||
@ -537,8 +538,10 @@ class Formula
 | 
			
		||||
    return false unless head&.downloader.is_a?(VCSDownloadStrategy)
 | 
			
		||||
 | 
			
		||||
    downloader = head.downloader
 | 
			
		||||
    downloader.shutup! unless Homebrew.args.verbose?
 | 
			
		||||
    downloader.commit_outdated?(version.version.commit)
 | 
			
		||||
 | 
			
		||||
    with_context quiet: true do
 | 
			
		||||
      downloader.commit_outdated?(version.version.commit)
 | 
			
		||||
    end
 | 
			
		||||
  end
 | 
			
		||||
 | 
			
		||||
  # The latest prefix for this formula. Checks for {#head}, then {#devel}
 | 
			
		||||
@ -1168,35 +1171,28 @@ class Formula
 | 
			
		||||
    patchlist.each(&:apply)
 | 
			
		||||
  end
 | 
			
		||||
 | 
			
		||||
  # @private
 | 
			
		||||
  attr_predicate :debug?, :verbose?
 | 
			
		||||
 | 
			
		||||
  # yields |self,staging| with current working directory set to the uncompressed tarball
 | 
			
		||||
  # where staging is a Mktemp staging context
 | 
			
		||||
  # @private
 | 
			
		||||
  def brew(fetch: true, keep_tmp: false, interactive: false, debug: false, verbose: false)
 | 
			
		||||
    @debug = debug
 | 
			
		||||
    @verbose = verbose
 | 
			
		||||
  def brew(fetch: true, keep_tmp: false, interactive: false)
 | 
			
		||||
    @prefix_returns_versioned_prefix = true
 | 
			
		||||
    active_spec.fetch if fetch
 | 
			
		||||
    stage(interactive: interactive) do |staging|
 | 
			
		||||
      staging.retain! if keep_tmp
 | 
			
		||||
 | 
			
		||||
      prepare_patches
 | 
			
		||||
      fetch_patches(verbose: verbose) if fetch
 | 
			
		||||
      fetch_patches if fetch
 | 
			
		||||
 | 
			
		||||
      begin
 | 
			
		||||
        yield self, staging
 | 
			
		||||
      rescue
 | 
			
		||||
        staging.retain! if interactive || debug
 | 
			
		||||
        staging.retain! if interactive || debug?
 | 
			
		||||
        raise
 | 
			
		||||
      ensure
 | 
			
		||||
        cp Dir["config.log", "CMakeCache.txt"], logs
 | 
			
		||||
      end
 | 
			
		||||
    end
 | 
			
		||||
  ensure
 | 
			
		||||
    @debug = nil
 | 
			
		||||
    @verbose = nil
 | 
			
		||||
    @prefix_returns_versioned_prefix = false
 | 
			
		||||
  end
 | 
			
		||||
 | 
			
		||||
@ -1801,19 +1797,17 @@ class Formula
 | 
			
		||||
  end
 | 
			
		||||
 | 
			
		||||
  # @private
 | 
			
		||||
  def fetch(verify_download_integrity: true, verbose: false)
 | 
			
		||||
    active_spec.fetch(verify_download_integrity: verify_download_integrity, verbose: verbose)
 | 
			
		||||
  def fetch(verify_download_integrity: true)
 | 
			
		||||
    active_spec.fetch(verify_download_integrity: verify_download_integrity)
 | 
			
		||||
  end
 | 
			
		||||
 | 
			
		||||
  # @private
 | 
			
		||||
  def verify_download_integrity(fn, verbose: false)
 | 
			
		||||
    active_spec.verify_download_integrity(fn, verbose: verbose)
 | 
			
		||||
  def verify_download_integrity(fn)
 | 
			
		||||
    active_spec.verify_download_integrity(fn)
 | 
			
		||||
  end
 | 
			
		||||
 | 
			
		||||
  # @private
 | 
			
		||||
  def run_test(keep_tmp: false, debug: false, verbose: false)
 | 
			
		||||
    @debug = debug
 | 
			
		||||
    @verbose = verbose
 | 
			
		||||
  def run_test(keep_tmp: false)
 | 
			
		||||
    @prefix_returns_versioned_prefix = true
 | 
			
		||||
 | 
			
		||||
    test_env = {
 | 
			
		||||
@ -1841,13 +1835,11 @@ class Formula
 | 
			
		||||
          end
 | 
			
		||||
        end
 | 
			
		||||
      rescue Exception # rubocop:disable Lint/RescueException
 | 
			
		||||
        staging.retain! if debug
 | 
			
		||||
        staging.retain! if debug?
 | 
			
		||||
        raise
 | 
			
		||||
      end
 | 
			
		||||
    end
 | 
			
		||||
  ensure
 | 
			
		||||
    @debug = nil
 | 
			
		||||
    @verbose = nil
 | 
			
		||||
    @prefix_returns_versioned_prefix = false
 | 
			
		||||
    @testpath = nil
 | 
			
		||||
  end
 | 
			
		||||
@ -2103,10 +2095,8 @@ class Formula
 | 
			
		||||
    ENV.update(removed)
 | 
			
		||||
  end
 | 
			
		||||
 | 
			
		||||
  def fetch_patches(verbose: false)
 | 
			
		||||
    patchlist.select(&:external?).each do |p|
 | 
			
		||||
      p.fetch(verbose: verbose)
 | 
			
		||||
    end
 | 
			
		||||
  def fetch_patches
 | 
			
		||||
    patchlist.select(&:external?).each(&:fetch)
 | 
			
		||||
  end
 | 
			
		||||
 | 
			
		||||
  private
 | 
			
		||||
 | 
			
		||||
@ -2,6 +2,8 @@
 | 
			
		||||
 | 
			
		||||
module Homebrew
 | 
			
		||||
  module Assertions
 | 
			
		||||
    include Context
 | 
			
		||||
 | 
			
		||||
    require "test/unit/assertions"
 | 
			
		||||
    include ::Test::Unit::Assertions
 | 
			
		||||
 | 
			
		||||
@ -12,7 +14,7 @@ module Homebrew
 | 
			
		||||
      assert_equal result, $CHILD_STATUS.exitstatus
 | 
			
		||||
      output
 | 
			
		||||
    rescue Test::Unit::AssertionFailedError
 | 
			
		||||
      puts output if Homebrew.args.verbose?
 | 
			
		||||
      puts output if verbose?
 | 
			
		||||
      raise
 | 
			
		||||
    end
 | 
			
		||||
 | 
			
		||||
@ -28,7 +30,7 @@ module Homebrew
 | 
			
		||||
      assert_equal result, $CHILD_STATUS.exitstatus unless result.nil?
 | 
			
		||||
      output
 | 
			
		||||
    rescue Test::Unit::AssertionFailedError
 | 
			
		||||
      puts output if Homebrew.args.verbose?
 | 
			
		||||
      puts output if verbose?
 | 
			
		||||
      raise
 | 
			
		||||
    end
 | 
			
		||||
  end
 | 
			
		||||
 | 
			
		||||
@ -952,7 +952,7 @@ class FormulaInstaller
 | 
			
		||||
 | 
			
		||||
  def clean
 | 
			
		||||
    ohai "Cleaning" if verbose?
 | 
			
		||||
    Cleaner.new(formula, verbose: verbose?, debug: debug?).clean
 | 
			
		||||
    Cleaner.new(formula).clean
 | 
			
		||||
  rescue Exception => e # rubocop:disable Lint/RescueException
 | 
			
		||||
    opoo "The cleaning step did not complete successfully"
 | 
			
		||||
    puts "Still, the installation was successful, so we will link it into your prefix"
 | 
			
		||||
@ -1027,10 +1027,8 @@ class FormulaInstaller
 | 
			
		||||
    end
 | 
			
		||||
    return if pour_bottle?
 | 
			
		||||
 | 
			
		||||
    formula.fetch_patches(verbose: verbose?)
 | 
			
		||||
    formula.resources.each do |r|
 | 
			
		||||
      r.fetch(verbose: verbose?)
 | 
			
		||||
    end
 | 
			
		||||
    formula.fetch_patches
 | 
			
		||||
    formula.resources.each(&:fetch)
 | 
			
		||||
    downloader.fetch
 | 
			
		||||
  end
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
@ -3,6 +3,8 @@
 | 
			
		||||
require "formula"
 | 
			
		||||
 | 
			
		||||
class FormulaVersions
 | 
			
		||||
  include Context
 | 
			
		||||
 | 
			
		||||
  IGNORED_EXCEPTIONS = [
 | 
			
		||||
    ArgumentError, NameError, SyntaxError, TypeError,
 | 
			
		||||
    FormulaSpecificationError, FormulaValidationError,
 | 
			
		||||
@ -44,7 +46,7 @@ class FormulaVersions
 | 
			
		||||
  rescue *IGNORED_EXCEPTIONS => e
 | 
			
		||||
    # We rescue these so that we can skip bad versions and
 | 
			
		||||
    # continue walking the history
 | 
			
		||||
    odebug "#{e} in #{name} at revision #{rev}", e.backtrace if Homebrew.args.debug?
 | 
			
		||||
    odebug "#{e} in #{name} at revision #{rev}", e.backtrace if debug?
 | 
			
		||||
  rescue FormulaUnavailableError
 | 
			
		||||
    nil
 | 
			
		||||
  ensure
 | 
			
		||||
 | 
			
		||||
@ -109,6 +109,8 @@ module Formulary
 | 
			
		||||
  # A FormulaLoader returns instances of formulae.
 | 
			
		||||
  # Subclasses implement loaders for particular sources of formulae.
 | 
			
		||||
  class FormulaLoader
 | 
			
		||||
    include Context
 | 
			
		||||
 | 
			
		||||
    # The formula's name
 | 
			
		||||
    attr_reader :name
 | 
			
		||||
    # The formula's ruby file's path or filename
 | 
			
		||||
@ -138,7 +140,7 @@ module Formulary
 | 
			
		||||
    private
 | 
			
		||||
 | 
			
		||||
    def load_file(flags:)
 | 
			
		||||
      $stderr.puts "#{$PROGRAM_NAME} (#{self.class.name}): loading #{path}" if Homebrew.args.debug?
 | 
			
		||||
      $stderr.puts "#{$PROGRAM_NAME} (#{self.class.name}): loading #{path}" if debug?
 | 
			
		||||
      raise FormulaUnavailableError, name unless path.file?
 | 
			
		||||
 | 
			
		||||
      Formulary.load_formula_from_path(name, path, flags: flags)
 | 
			
		||||
@ -314,7 +316,7 @@ module Formulary
 | 
			
		||||
    end
 | 
			
		||||
 | 
			
		||||
    def klass(flags:)
 | 
			
		||||
      $stderr.puts "#{$PROGRAM_NAME} (#{self.class.name}): loading #{path}" if Homebrew.args.debug?
 | 
			
		||||
      $stderr.puts "#{$PROGRAM_NAME} (#{self.class.name}): loading #{path}" if debug?
 | 
			
		||||
      namespace = "FormulaNamespace#{Digest::MD5.hexdigest(contents.to_s)}"
 | 
			
		||||
      Formulary.load_formula(name, path, contents, namespace, flags: flags)
 | 
			
		||||
    end
 | 
			
		||||
 | 
			
		||||
@ -37,7 +37,6 @@ require "config"
 | 
			
		||||
require "os"
 | 
			
		||||
require "cli/args"
 | 
			
		||||
require "messages"
 | 
			
		||||
require "system_command"
 | 
			
		||||
 | 
			
		||||
HOMEBREW_PRODUCT = ENV["HOMEBREW_PRODUCT"]
 | 
			
		||||
HOMEBREW_VERSION = ENV["HOMEBREW_VERSION"]
 | 
			
		||||
@ -116,6 +115,7 @@ end.compact.freeze
 | 
			
		||||
 | 
			
		||||
require "set"
 | 
			
		||||
 | 
			
		||||
require "context"
 | 
			
		||||
require "extend/pathname"
 | 
			
		||||
 | 
			
		||||
require "extend/module"
 | 
			
		||||
@ -125,6 +125,7 @@ require "active_support/core_ext/object/blank"
 | 
			
		||||
require "active_support/core_ext/hash/deep_merge"
 | 
			
		||||
require "active_support/core_ext/file/atomic"
 | 
			
		||||
 | 
			
		||||
require "system_command"
 | 
			
		||||
require "exceptions"
 | 
			
		||||
require "utils"
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
@ -5,7 +5,7 @@ require "keg"
 | 
			
		||||
require "tab"
 | 
			
		||||
 | 
			
		||||
class Migrator
 | 
			
		||||
  extend Predicable
 | 
			
		||||
  include Context
 | 
			
		||||
 | 
			
		||||
  class MigrationNeededError < RuntimeError
 | 
			
		||||
    def initialize(formula)
 | 
			
		||||
@ -88,8 +88,6 @@ class Migrator
 | 
			
		||||
  # path to newname keg that will be linked if old_linked_keg isn't nil
 | 
			
		||||
  attr_reader :new_linked_keg_record
 | 
			
		||||
 | 
			
		||||
  attr_predicate :verbose?
 | 
			
		||||
 | 
			
		||||
  def self.needs_migration?(formula)
 | 
			
		||||
    oldname = formula.oldname
 | 
			
		||||
    return false unless oldname
 | 
			
		||||
@ -101,20 +99,18 @@ class Migrator
 | 
			
		||||
    true
 | 
			
		||||
  end
 | 
			
		||||
 | 
			
		||||
  def self.migrate_if_needed(formula, force:, verbose:)
 | 
			
		||||
  def self.migrate_if_needed(formula, force:)
 | 
			
		||||
    return unless Migrator.needs_migration?(formula)
 | 
			
		||||
 | 
			
		||||
    begin
 | 
			
		||||
      migrator = Migrator.new(formula, force: force, verbose: verbose)
 | 
			
		||||
      migrator = Migrator.new(formula, force: force)
 | 
			
		||||
      migrator.migrate
 | 
			
		||||
    rescue => e
 | 
			
		||||
      onoe e
 | 
			
		||||
    end
 | 
			
		||||
  end
 | 
			
		||||
 | 
			
		||||
  def initialize(formula, force: false, verbose: false)
 | 
			
		||||
    @verbose = verbose
 | 
			
		||||
 | 
			
		||||
  def initialize(formula, force: false)
 | 
			
		||||
    @oldname = formula.oldname
 | 
			
		||||
    @newname = formula.name
 | 
			
		||||
    raise MigratorNoOldnameError, formula unless oldname
 | 
			
		||||
@ -215,7 +211,7 @@ class Migrator
 | 
			
		||||
  rescue Exception => e # rubocop:disable Lint/RescueException
 | 
			
		||||
    onoe "Error occurred while migrating."
 | 
			
		||||
    puts e
 | 
			
		||||
    puts e.backtrace if Homebrew.args.debug?
 | 
			
		||||
    puts e.backtrace if debug?
 | 
			
		||||
    puts "Backing up..."
 | 
			
		||||
    ignore_interrupts { backup_oldname }
 | 
			
		||||
  ensure
 | 
			
		||||
@ -322,7 +318,7 @@ class Migrator
 | 
			
		||||
    rescue Exception => e # rubocop:disable Lint/RescueException
 | 
			
		||||
      onoe "An unexpected error occurred during linking"
 | 
			
		||||
      puts e
 | 
			
		||||
      puts e.backtrace if Homebrew.args.debug?
 | 
			
		||||
      puts e.backtrace if debug?
 | 
			
		||||
      ignore_interrupts { new_keg.unlink(verbose: verbose?) }
 | 
			
		||||
      raise
 | 
			
		||||
    end
 | 
			
		||||
 | 
			
		||||
@ -5,7 +5,7 @@ class Keg
 | 
			
		||||
    return if file.dylib_id == id
 | 
			
		||||
 | 
			
		||||
    @require_relocation = true
 | 
			
		||||
    odebug "Changing dylib ID of #{file}\n  from #{file.dylib_id}\n    to #{id}" if Homebrew.args.debug?
 | 
			
		||||
    odebug "Changing dylib ID of #{file}\n  from #{file.dylib_id}\n    to #{id}"
 | 
			
		||||
    MachO::Tools.change_dylib_id(file, id, strict: false)
 | 
			
		||||
  rescue MachO::MachOError
 | 
			
		||||
    onoe <<~EOS
 | 
			
		||||
@ -20,7 +20,7 @@ class Keg
 | 
			
		||||
    return if old == new
 | 
			
		||||
 | 
			
		||||
    @require_relocation = true
 | 
			
		||||
    odebug "Changing install name in #{file}\n  from #{old}\n    to #{new}" if Homebrew.args.debug?
 | 
			
		||||
    odebug "Changing install name in #{file}\n  from #{old}\n    to #{new}"
 | 
			
		||||
    MachO::Tools.change_install_name(file, old, new, strict: false)
 | 
			
		||||
  rescue MachO::MachOError
 | 
			
		||||
    onoe <<~EOS
 | 
			
		||||
 | 
			
		||||
@ -179,12 +179,12 @@ class LegacyPatch < ExternalPatch
 | 
			
		||||
    resource.download_strategy = CurlDownloadStrategy
 | 
			
		||||
  end
 | 
			
		||||
 | 
			
		||||
  def fetch(verbose: false)
 | 
			
		||||
  def fetch
 | 
			
		||||
    clear_cache
 | 
			
		||||
    super
 | 
			
		||||
  end
 | 
			
		||||
 | 
			
		||||
  def verify_download_integrity(_fn, verbose: false)
 | 
			
		||||
  def verify_download_integrity(_fn)
 | 
			
		||||
    # no-op
 | 
			
		||||
  end
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
@ -17,7 +17,7 @@ begin
 | 
			
		||||
  trap("INT", old_trap)
 | 
			
		||||
 | 
			
		||||
  formula = args.resolved_formulae.first
 | 
			
		||||
  formula.extend(Debrew::Formula) if Homebrew.args.debug?
 | 
			
		||||
  formula.extend(Debrew::Formula) if args.debug?
 | 
			
		||||
  formula.run_post_install
 | 
			
		||||
rescue Exception => e # rubocop:disable Lint/RescueException
 | 
			
		||||
  error_pipe.puts e.to_json
 | 
			
		||||
 | 
			
		||||
@ -9,6 +9,7 @@ require "mktemp"
 | 
			
		||||
# primary formula download, along with other declared resources, are instances
 | 
			
		||||
# of this class.
 | 
			
		||||
class Resource
 | 
			
		||||
  include Context
 | 
			
		||||
  include FileUtils
 | 
			
		||||
 | 
			
		||||
  attr_reader :mirrors, :specs, :using, :source_modified_time, :patches, :owner
 | 
			
		||||
@ -74,10 +75,9 @@ class Resource
 | 
			
		||||
  def stage(target = nil, &block)
 | 
			
		||||
    raise ArgumentError, "target directory or block is required" if !target && block.blank?
 | 
			
		||||
 | 
			
		||||
    verbose = owner.owner.verbose?
 | 
			
		||||
    prepare_patches
 | 
			
		||||
    fetch_patches(skip_downloaded: true, verbose: verbose)
 | 
			
		||||
    fetch(verbose: owner.owner.verbose?) unless downloaded?
 | 
			
		||||
    fetch_patches(skip_downloaded: true)
 | 
			
		||||
    fetch unless downloaded?
 | 
			
		||||
 | 
			
		||||
    unpack(target, &block)
 | 
			
		||||
  end
 | 
			
		||||
@ -86,12 +86,10 @@ class Resource
 | 
			
		||||
    patches.grep(DATAPatch) { |p| p.path = owner.owner.path }
 | 
			
		||||
  end
 | 
			
		||||
 | 
			
		||||
  def fetch_patches(skip_downloaded: false, verbose: false)
 | 
			
		||||
  def fetch_patches(skip_downloaded: false)
 | 
			
		||||
    external_patches = patches.select(&:external?)
 | 
			
		||||
    external_patches.reject!(&:downloaded?) if skip_downloaded
 | 
			
		||||
    external_patches.each do |p|
 | 
			
		||||
      p.fetch(verbose: verbose)
 | 
			
		||||
    end
 | 
			
		||||
    external_patches.each(&:fetch)
 | 
			
		||||
  end
 | 
			
		||||
 | 
			
		||||
  def apply_patches
 | 
			
		||||
@ -125,10 +123,10 @@ class Resource
 | 
			
		||||
    Partial.new(self, files)
 | 
			
		||||
  end
 | 
			
		||||
 | 
			
		||||
  def fetch(verify_download_integrity: true, verbose: false)
 | 
			
		||||
  def fetch(verify_download_integrity: true)
 | 
			
		||||
    HOMEBREW_CACHE.mkpath
 | 
			
		||||
 | 
			
		||||
    fetch_patches(verbose: verbose)
 | 
			
		||||
    fetch_patches
 | 
			
		||||
 | 
			
		||||
    begin
 | 
			
		||||
      downloader.fetch
 | 
			
		||||
@ -137,13 +135,13 @@ class Resource
 | 
			
		||||
    end
 | 
			
		||||
 | 
			
		||||
    download = cached_download
 | 
			
		||||
    verify_download_integrity(download, verbose: verbose) if verify_download_integrity
 | 
			
		||||
    verify_download_integrity(download) if verify_download_integrity
 | 
			
		||||
    download
 | 
			
		||||
  end
 | 
			
		||||
 | 
			
		||||
  def verify_download_integrity(fn, verbose: false)
 | 
			
		||||
  def verify_download_integrity(fn)
 | 
			
		||||
    if fn.file?
 | 
			
		||||
      ohai "Verifying #{fn.basename} checksum" if verbose
 | 
			
		||||
      ohai "Verifying #{fn.basename} checksum" if verbose?
 | 
			
		||||
      fn.verify_checksum(checksum)
 | 
			
		||||
    end
 | 
			
		||||
  rescue ChecksumMissingError
 | 
			
		||||
 | 
			
		||||
@ -239,7 +239,7 @@ class HeadSoftwareSpec < SoftwareSpec
 | 
			
		||||
    @resource.version = Version.create("HEAD")
 | 
			
		||||
  end
 | 
			
		||||
 | 
			
		||||
  def verify_download_integrity(_fn, verbose: false)
 | 
			
		||||
  def verify_download_integrity(_fn)
 | 
			
		||||
    # no-op
 | 
			
		||||
  end
 | 
			
		||||
end
 | 
			
		||||
 | 
			
		||||
@ -8,7 +8,6 @@ require "shellwords"
 | 
			
		||||
require "extend/io"
 | 
			
		||||
require "extend/hash_validator"
 | 
			
		||||
using HashValidator
 | 
			
		||||
require "extend/predicable"
 | 
			
		||||
 | 
			
		||||
module Kernel
 | 
			
		||||
  def system_command(*args)
 | 
			
		||||
@ -21,6 +20,7 @@ module Kernel
 | 
			
		||||
end
 | 
			
		||||
 | 
			
		||||
class SystemCommand
 | 
			
		||||
  include Context
 | 
			
		||||
  extend Predicable
 | 
			
		||||
 | 
			
		||||
  attr_reader :pid
 | 
			
		||||
@ -34,7 +34,7 @@ class SystemCommand
 | 
			
		||||
  end
 | 
			
		||||
 | 
			
		||||
  def run!
 | 
			
		||||
    puts redact_secrets(command.shelljoin.gsub('\=', "="), @secrets) if verbose? || Homebrew.args.debug?
 | 
			
		||||
    puts redact_secrets(command.shelljoin.gsub('\=', "="), @secrets) if verbose? || debug?
 | 
			
		||||
 | 
			
		||||
    @output = []
 | 
			
		||||
 | 
			
		||||
@ -84,7 +84,13 @@ class SystemCommand
 | 
			
		||||
 | 
			
		||||
  attr_reader :executable, :args, :input, :options, :env
 | 
			
		||||
 | 
			
		||||
  attr_predicate :sudo?, :print_stdout?, :print_stderr?, :verbose?, :must_succeed?
 | 
			
		||||
  attr_predicate :sudo?, :print_stdout?, :print_stderr?, :must_succeed?
 | 
			
		||||
 | 
			
		||||
  def verbose?
 | 
			
		||||
    return super if @verbose.nil?
 | 
			
		||||
 | 
			
		||||
    @verbose
 | 
			
		||||
  end
 | 
			
		||||
 | 
			
		||||
  def env_args
 | 
			
		||||
    set_variables = env.reject { |_, value| value.nil? }
 | 
			
		||||
@ -160,6 +166,8 @@ class SystemCommand
 | 
			
		||||
  end
 | 
			
		||||
 | 
			
		||||
  class Result
 | 
			
		||||
    include Context
 | 
			
		||||
 | 
			
		||||
    attr_accessor :command, :status, :exit_status
 | 
			
		||||
 | 
			
		||||
    def initialize(command, output, status, secrets:)
 | 
			
		||||
@ -222,7 +230,7 @@ class SystemCommand
 | 
			
		||||
    end
 | 
			
		||||
 | 
			
		||||
    def warn_plist_garbage(garbage)
 | 
			
		||||
      return unless Homebrew.args.verbose?
 | 
			
		||||
      return unless verbose?
 | 
			
		||||
      return unless garbage.match?(/\S/)
 | 
			
		||||
 | 
			
		||||
      opoo "Received non-XML output from #{Formatter.identifier(command.first)}:"
 | 
			
		||||
 | 
			
		||||
@ -16,9 +16,9 @@ require "dev-cmd/test"
 | 
			
		||||
TEST_TIMEOUT_SECONDS = 5 * 60
 | 
			
		||||
 | 
			
		||||
begin
 | 
			
		||||
  Homebrew.args = Homebrew::CLI::Parser.new.parse(ARGV.dup.freeze, ignore_invalid_options: true)
 | 
			
		||||
 | 
			
		||||
  args = Homebrew.test_args.parse
 | 
			
		||||
  Context.current = args.context
 | 
			
		||||
 | 
			
		||||
  error_pipe = UNIXSocket.open(ENV["HOMEBREW_ERROR_PIPE"], &:recv_io)
 | 
			
		||||
  error_pipe.fcntl(Fcntl::F_SETFD, Fcntl::FD_CLOEXEC)
 | 
			
		||||
 | 
			
		||||
@ -34,9 +34,7 @@ begin
 | 
			
		||||
 | 
			
		||||
  # tests can also return false to indicate failure
 | 
			
		||||
  Timeout.timeout TEST_TIMEOUT_SECONDS do
 | 
			
		||||
    if formula.run_test(keep_tmp: args.keep_tmp?, debug: args.debug?, verbose: args.verbose?) == false
 | 
			
		||||
      raise "test returned false"
 | 
			
		||||
    end
 | 
			
		||||
    raise "test returned false" if formula.run_test(keep_tmp: args.keep_tmp?) == false
 | 
			
		||||
  end
 | 
			
		||||
rescue Exception => e # rubocop:disable Lint/RescueException
 | 
			
		||||
  error_pipe.puts e.to_json
 | 
			
		||||
 | 
			
		||||
@ -120,7 +120,7 @@ describe SystemCommand::Result do
 | 
			
		||||
 | 
			
		||||
      context "when verbose" do
 | 
			
		||||
        before do
 | 
			
		||||
          allow(Homebrew).to receive(:args).and_return(OpenStruct.new("verbose?" => true))
 | 
			
		||||
          allow(Context).to receive(:current).and_return(Context::ContextStruct.new(verbose: true))
 | 
			
		||||
        end
 | 
			
		||||
 | 
			
		||||
        it "warns about garbage" do
 | 
			
		||||
@ -144,7 +144,7 @@ describe SystemCommand::Result do
 | 
			
		||||
 | 
			
		||||
      context "when verbose" do
 | 
			
		||||
        before do
 | 
			
		||||
          allow(Homebrew).to receive(:args).and_return(OpenStruct.new("verbose?" => true))
 | 
			
		||||
          allow(Context).to receive(:current).and_return(Context::ContextStruct.new(verbose: true))
 | 
			
		||||
        end
 | 
			
		||||
 | 
			
		||||
        it "warns about garbage" do
 | 
			
		||||
 | 
			
		||||
@ -26,7 +26,7 @@ module Homebrew
 | 
			
		||||
    end
 | 
			
		||||
 | 
			
		||||
    formulae_to_install.each do |f|
 | 
			
		||||
      Migrator.migrate_if_needed(f, force: args.force?, verbose: args.verbose?)
 | 
			
		||||
      Migrator.migrate_if_needed(f, force: args.force?)
 | 
			
		||||
      begin
 | 
			
		||||
        upgrade_formula(f, args: args)
 | 
			
		||||
        Cleanup.install_formula_clean!(f)
 | 
			
		||||
 | 
			
		||||
@ -16,6 +16,8 @@ require "tap_constants"
 | 
			
		||||
require "time"
 | 
			
		||||
 | 
			
		||||
module Homebrew
 | 
			
		||||
  extend Context
 | 
			
		||||
 | 
			
		||||
  module_function
 | 
			
		||||
 | 
			
		||||
  def _system(cmd, *args, **options)
 | 
			
		||||
@ -34,7 +36,7 @@ module Homebrew
 | 
			
		||||
  end
 | 
			
		||||
 | 
			
		||||
  def system(cmd, *args, **options)
 | 
			
		||||
    if Homebrew.args.verbose?
 | 
			
		||||
    if verbose?
 | 
			
		||||
      puts "#{cmd} #{args * " "}".gsub(RUBY_PATH, "ruby")
 | 
			
		||||
                                 .gsub($LOAD_PATH.join(File::PATH_SEPARATOR).to_s, "$LOAD_PATH")
 | 
			
		||||
    end
 | 
			
		||||
@ -89,7 +91,7 @@ module Kernel
 | 
			
		||||
    verbose = if respond_to?(:verbose?)
 | 
			
		||||
      verbose?
 | 
			
		||||
    else
 | 
			
		||||
      Homebrew.args.verbose?
 | 
			
		||||
      Context.current.verbose?
 | 
			
		||||
    end
 | 
			
		||||
 | 
			
		||||
    title = Tty.truncate(title) if $stdout.tty? && !verbose
 | 
			
		||||
@ -102,10 +104,10 @@ module Kernel
 | 
			
		||||
  end
 | 
			
		||||
 | 
			
		||||
  def odebug(title, *sput, always_display: false)
 | 
			
		||||
    debug = if respond_to?(:debug?)
 | 
			
		||||
    debug = if respond_to?(:debug)
 | 
			
		||||
      debug?
 | 
			
		||||
    else
 | 
			
		||||
      Homebrew.args.debug?
 | 
			
		||||
      Context.current.debug?
 | 
			
		||||
    end
 | 
			
		||||
 | 
			
		||||
    return unless debug || always_display
 | 
			
		||||
@ -118,7 +120,7 @@ module Kernel
 | 
			
		||||
    verbose = if respond_to?(:verbose?)
 | 
			
		||||
      verbose?
 | 
			
		||||
    else
 | 
			
		||||
      Homebrew.args.verbose?
 | 
			
		||||
      Context.current.verbose?
 | 
			
		||||
    end
 | 
			
		||||
 | 
			
		||||
    title = Tty.truncate(title) if $stdout.tty? && !verbose && truncate == :auto
 | 
			
		||||
@ -387,12 +389,12 @@ module Kernel
 | 
			
		||||
  end
 | 
			
		||||
 | 
			
		||||
  def nostdout
 | 
			
		||||
    if Homebrew.args.verbose?
 | 
			
		||||
    if verbose?
 | 
			
		||||
      yield
 | 
			
		||||
    else
 | 
			
		||||
      begin
 | 
			
		||||
        out = $stdout.dup
 | 
			
		||||
        $stdout.reopen("/dev/null")
 | 
			
		||||
        $stdout.reopen(File::NULL)
 | 
			
		||||
        yield
 | 
			
		||||
      ensure
 | 
			
		||||
        $stdout.reopen(out)
 | 
			
		||||
 | 
			
		||||
@ -5,6 +5,8 @@ require "erb"
 | 
			
		||||
module Utils
 | 
			
		||||
  module Analytics
 | 
			
		||||
    class << self
 | 
			
		||||
      include Context
 | 
			
		||||
 | 
			
		||||
      def report(type, metadata = {})
 | 
			
		||||
        return if not_this_run?
 | 
			
		||||
        return if disabled?
 | 
			
		||||
@ -148,7 +150,7 @@ module Utils
 | 
			
		||||
      end
 | 
			
		||||
 | 
			
		||||
      def get_analytics(json, args:)
 | 
			
		||||
        full_analytics = args.analytics? || Homebrew.args.verbose?
 | 
			
		||||
        full_analytics = args.analytics? || verbose?
 | 
			
		||||
 | 
			
		||||
        ohai "Analytics"
 | 
			
		||||
        json["analytics"].each do |category, value|
 | 
			
		||||
 | 
			
		||||
@ -34,7 +34,7 @@ def curl_args(*extra_args, show_output: false, user_agent: :default)
 | 
			
		||||
 | 
			
		||||
  unless show_output
 | 
			
		||||
    args << "--fail"
 | 
			
		||||
    args << "--progress-bar" unless Homebrew.args.verbose?
 | 
			
		||||
    args << "--progress-bar" unless Context.current.verbose?
 | 
			
		||||
    args << "--verbose" if Homebrew::EnvConfig.curl_verbose?
 | 
			
		||||
    args << "--silent" unless $stdout.tty?
 | 
			
		||||
  end
 | 
			
		||||
 | 
			
		||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user