diff --git a/Library/Homebrew/download_strategy.rb b/Library/Homebrew/download_strategy.rb index a14556da3c..9ea88cae70 100644 --- a/Library/Homebrew/download_strategy.rb +++ b/Library/Homebrew/download_strategy.rb @@ -357,7 +357,8 @@ end class NoUnzipCurlDownloadStrategy < CurlDownloadStrategy def stage UnpackStrategy::Uncompressed.new(cached_location) - .extract(basename: basename_without_params) + .extract(basename: basename_without_params, + verbose: ARGV.verbose? && !shutup) end end diff --git a/Library/Homebrew/system_command.rb b/Library/Homebrew/system_command.rb index 4f010217de..afa721547f 100644 --- a/Library/Homebrew/system_command.rb +++ b/Library/Homebrew/system_command.rb @@ -28,8 +28,9 @@ class SystemCommand end def run! + puts command.shelljoin.gsub(/\\=/, "=") if verbose? || ARGV.debug? + @merged_output = [] - odebug command.shelljoin each_output_line do |type, line| case type @@ -46,13 +47,16 @@ class SystemCommand result end - def initialize(executable, args: [], sudo: false, input: [], print_stdout: false, print_stderr: true, must_succeed: false, env: {}, **options) + def initialize(executable, args: [], sudo: false, env: {}, input: [], must_succeed: false, + print_stdout: false, print_stderr: true, verbose: false, **options) + @executable = executable @args = args @sudo = sudo @input = [*input] @print_stdout = print_stdout @print_stderr = print_stderr + @verbose = verbose @must_succeed = must_succeed options.assert_valid_keys!(:chdir) @options = options @@ -71,7 +75,7 @@ class SystemCommand attr_reader :executable, :args, :input, :options, :env - attr_predicate :sudo?, :print_stdout?, :print_stderr?, :must_succeed? + attr_predicate :sudo?, :print_stdout?, :print_stderr?, :verbose?, :must_succeed? def env_args set_variables = env.reject { |_, value| value.nil? } diff --git a/Library/Homebrew/unpack_strategy/air.rb b/Library/Homebrew/unpack_strategy/air.rb index 1b12e221b0..7ef51b4b95 100644 --- a/Library/Homebrew/unpack_strategy/air.rb +++ b/Library/Homebrew/unpack_strategy/air.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + module UnpackStrategy class Air include UnpackStrategy @@ -17,13 +19,17 @@ module UnpackStrategy @dependencies ||= [Hbc::CaskLoader.load("adobe-air")] end + AIR_APPLICATION_INSTALLER = + "/Applications/Utilities/Adobe AIR Application Installer.app/Contents/MacOS/Adobe AIR Application Installer" + + private_constant :AIR_APPLICATION_INSTALLER + private def extract_to_dir(unpack_dir, basename:, verbose:) - system_command!( - "/Applications/Utilities/Adobe AIR Application Installer.app/Contents/MacOS/Adobe AIR Application Installer", - args: ["-silent", "-location", unpack_dir, path], - ) + system_command! AIR_APPLICATION_INSTALLER, + args: ["-silent", "-location", unpack_dir, path], + verbose: verbose end end end diff --git a/Library/Homebrew/unpack_strategy/bzip2.rb b/Library/Homebrew/unpack_strategy/bzip2.rb index e47cc062df..12ce68ad49 100644 --- a/Library/Homebrew/unpack_strategy/bzip2.rb +++ b/Library/Homebrew/unpack_strategy/bzip2.rb @@ -17,7 +17,9 @@ module UnpackStrategy def extract_to_dir(unpack_dir, basename:, verbose:) FileUtils.cp path, unpack_dir/basename, preserve: true quiet_flags = verbose ? [] : ["-q"] - system_command! "bunzip2", args: [*quiet_flags, unpack_dir/basename] + system_command! "bunzip2", + args: [*quiet_flags, unpack_dir/basename], + verbose: verbose end end end diff --git a/Library/Homebrew/unpack_strategy/cab.rb b/Library/Homebrew/unpack_strategy/cab.rb index afbf9e3784..dcbe0e6113 100644 --- a/Library/Homebrew/unpack_strategy/cab.rb +++ b/Library/Homebrew/unpack_strategy/cab.rb @@ -15,7 +15,8 @@ module UnpackStrategy def extract_to_dir(unpack_dir, basename:, verbose:) system_command! "cabextract", args: ["-d", unpack_dir, "--", path], - env: { "PATH" => PATH.new(Formula["cabextract"].opt_bin, ENV["PATH"]) } + env: { "PATH" => PATH.new(Formula["cabextract"].opt_bin, ENV["PATH"]) }, + verbose: verbose end def dependencies diff --git a/Library/Homebrew/unpack_strategy/dmg.rb b/Library/Homebrew/unpack_strategy/dmg.rb index b15ec3c44d..55730bc02b 100644 --- a/Library/Homebrew/unpack_strategy/dmg.rb +++ b/Library/Homebrew/unpack_strategy/dmg.rb @@ -4,8 +4,6 @@ module UnpackStrategy class Dmg include UnpackStrategy - using Magic - module Bom DMG_METADATA = Set.new %w[ .background @@ -51,7 +49,7 @@ module UnpackStrategy class Mount include UnpackStrategy - def eject + def eject(verbose: false) tries ||= 3 return unless path.exist? @@ -59,11 +57,13 @@ module UnpackStrategy if tries > 1 system_command! "diskutil", args: ["eject", path], - print_stderr: false + print_stderr: false, + verbose: verbose else system_command! "diskutil", args: ["unmount", "force", path], - print_stderr: false + print_stderr: false, + verbose: verbose end rescue ErrorDuringExecution => e raise e if (tries -= 1).zero? @@ -81,10 +81,14 @@ module UnpackStrategy filelist.puts(path.bom) filelist.close - system_command! "mkbom", args: ["-s", "-i", filelist.path, "--", bomfile.path] + system_command! "mkbom", + args: ["-s", "-i", filelist.path, "--", bomfile.path], + verbose: verbose end - system_command! "ditto", args: ["--bom", bomfile.path, "--", path, unpack_dir] + system_command! "ditto", + args: ["--bom", bomfile.path, "--", path, unpack_dir], + verbose: verbose FileUtils.chmod "u+w", Pathname.glob(unpack_dir/"**/*").reject(&:symlink?) end @@ -111,7 +115,7 @@ module UnpackStrategy raise "No mounts found in '#{path}'; perhaps it is a bad disk image?" if mounts.empty? mounts.each do |mount| - mount.extract(to: unpack_dir) + mount.extract(to: unpack_dir, verbose: verbose) end end end @@ -120,10 +124,11 @@ module UnpackStrategy Dir.mktmpdir do |mount_dir| mount_dir = Pathname(mount_dir) - without_eula = system_command("hdiutil", + without_eula = system_command "hdiutil", args: ["attach", "-plist", "-nobrowse", "-readonly", "-noidme", "-mountrandom", mount_dir, path], input: "qn\n", - print_stderr: false) + print_stderr: false, + verbose: verbose # If mounting without agreeing to EULA succeeded, there is none. plist = if without_eula.success? @@ -131,12 +136,13 @@ module UnpackStrategy else cdr_path = mount_dir/path.basename.sub_ext(".cdr") - system_command!("hdiutil", args: ["convert", "-quiet", "-format", "UDTO", "-o", cdr_path, path]) + system_command! "hdiutil", + args: ["convert", "-quiet", "-format", "UDTO", "-o", cdr_path, path], + verbose: verbose - with_eula = system_command!( - "/usr/bin/hdiutil", - args: ["attach", "-plist", "-nobrowse", "-readonly", "-noidme", "-mountrandom", mount_dir, cdr_path], - ) + with_eula = system_command! "hdiutil", + args: ["attach", "-plist", "-nobrowse", "-readonly", "-noidme", "-mountrandom", mount_dir, cdr_path], + verbose: verbose if verbose && !(eula_text = without_eula.stdout).empty? ohai "Software License Agreement for '#{path}':" @@ -158,7 +164,9 @@ module UnpackStrategy begin yield mounts ensure - mounts.each(&:eject) + mounts.each do |mount| + mount.eject(verbose: verbose) + end end end end diff --git a/Library/Homebrew/unpack_strategy/fossil.rb b/Library/Homebrew/unpack_strategy/fossil.rb index 5bc5e5e78f..846219e137 100644 --- a/Library/Homebrew/unpack_strategy/fossil.rb +++ b/Library/Homebrew/unpack_strategy/fossil.rb @@ -28,7 +28,8 @@ module UnpackStrategy system_command! "fossil", args: ["open", path, *args], chdir: unpack_dir, - env: { "PATH" => PATH.new(Formula["fossil"].opt_bin, ENV["PATH"]) } + env: { "PATH" => PATH.new(Formula["fossil"].opt_bin, ENV["PATH"]) }, + verbose: verbose end end end diff --git a/Library/Homebrew/unpack_strategy/generic_unar.rb b/Library/Homebrew/unpack_strategy/generic_unar.rb index f9e65b9dec..6a1403b533 100644 --- a/Library/Homebrew/unpack_strategy/generic_unar.rb +++ b/Library/Homebrew/unpack_strategy/generic_unar.rb @@ -21,7 +21,8 @@ module UnpackStrategy def extract_to_dir(unpack_dir, basename:, verbose:) system_command! "unar", args: ["-force-overwrite", "-quiet", "-no-directory", "-output-directory", unpack_dir, "--", path], - env: { "PATH" => PATH.new(Formula["unar"].opt_bin, ENV["PATH"]) } + env: { "PATH" => PATH.new(Formula["unar"].opt_bin, ENV["PATH"]) }, + verbose: verbose end end end diff --git a/Library/Homebrew/unpack_strategy/gzip.rb b/Library/Homebrew/unpack_strategy/gzip.rb index d575721d74..2ea64b9ba9 100644 --- a/Library/Homebrew/unpack_strategy/gzip.rb +++ b/Library/Homebrew/unpack_strategy/gzip.rb @@ -18,7 +18,8 @@ module UnpackStrategy FileUtils.cp path, unpack_dir/basename, preserve: true quiet_flags = verbose ? [] : ["-q"] system_command! "gunzip", - args: [*quiet_flags, "-N", "--", unpack_dir/basename] + args: [*quiet_flags, "-N", "--", unpack_dir/basename], + verbose: verbose end end end diff --git a/Library/Homebrew/unpack_strategy/lha.rb b/Library/Homebrew/unpack_strategy/lha.rb index b3671b0a60..1e69bad8ea 100644 --- a/Library/Homebrew/unpack_strategy/lha.rb +++ b/Library/Homebrew/unpack_strategy/lha.rb @@ -21,7 +21,8 @@ module UnpackStrategy def extract_to_dir(unpack_dir, basename:, verbose:) system_command! "lha", args: ["xq2w=#{unpack_dir}", path], - env: { "PATH" => PATH.new(Formula["lha"].opt_bin, ENV["PATH"]) } + env: { "PATH" => PATH.new(Formula["lha"].opt_bin, ENV["PATH"]) }, + verbose: verbose end end end diff --git a/Library/Homebrew/unpack_strategy/lzip.rb b/Library/Homebrew/unpack_strategy/lzip.rb index f96e0ab2da..c18079f77f 100644 --- a/Library/Homebrew/unpack_strategy/lzip.rb +++ b/Library/Homebrew/unpack_strategy/lzip.rb @@ -23,7 +23,8 @@ module UnpackStrategy quiet_flags = verbose ? [] : ["-q"] system_command! "lzip", args: ["-d", *quiet_flags, unpack_dir/basename], - env: { "PATH" => PATH.new(Formula["lzip"].opt_bin, ENV["PATH"]) } + env: { "PATH" => PATH.new(Formula["lzip"].opt_bin, ENV["PATH"]) }, + verbose: verbose end end end diff --git a/Library/Homebrew/unpack_strategy/lzma.rb b/Library/Homebrew/unpack_strategy/lzma.rb index a9a60a0b9a..961731c6bd 100644 --- a/Library/Homebrew/unpack_strategy/lzma.rb +++ b/Library/Homebrew/unpack_strategy/lzma.rb @@ -17,7 +17,8 @@ module UnpackStrategy quiet_flags = verbose ? [] : ["-q"] system_command! "unlzma", args: [*quiet_flags, "--", unpack_dir/basename], - env: { "PATH" => PATH.new(Formula["xz"].opt_bin, ENV["PATH"]) } + env: { "PATH" => PATH.new(Formula["xz"].opt_bin, ENV["PATH"]) }, + verbose: verbose end def dependencies diff --git a/Library/Homebrew/unpack_strategy/mercurial.rb b/Library/Homebrew/unpack_strategy/mercurial.rb index 34e897857c..15ca078930 100644 --- a/Library/Homebrew/unpack_strategy/mercurial.rb +++ b/Library/Homebrew/unpack_strategy/mercurial.rb @@ -13,7 +13,8 @@ module UnpackStrategy def extract_to_dir(unpack_dir, basename:, verbose:) system_command! "hg", args: ["--cwd", path, "archive", "--subrepos", "-y", "-t", "files", unpack_dir], - env: { "PATH" => PATH.new(Formula["mercurial"].opt_bin, ENV["PATH"]) } + env: { "PATH" => PATH.new(Formula["mercurial"].opt_bin, ENV["PATH"]) }, + verbose: verbose end end end diff --git a/Library/Homebrew/unpack_strategy/p7zip.rb b/Library/Homebrew/unpack_strategy/p7zip.rb index cfb76d08c9..d5fd3a181f 100644 --- a/Library/Homebrew/unpack_strategy/p7zip.rb +++ b/Library/Homebrew/unpack_strategy/p7zip.rb @@ -21,7 +21,8 @@ module UnpackStrategy def extract_to_dir(unpack_dir, basename:, verbose:) system_command! "7zr", args: ["x", "-y", "-bd", "-bso0", path, "-o#{unpack_dir}"], - env: { "PATH" => PATH.new(Formula["p7zip"].opt_bin, ENV["PATH"]) } + env: { "PATH" => PATH.new(Formula["p7zip"].opt_bin, ENV["PATH"]) }, + verbose: verbose end end end diff --git a/Library/Homebrew/unpack_strategy/rar.rb b/Library/Homebrew/unpack_strategy/rar.rb index 648c79e972..c8fa5df29e 100644 --- a/Library/Homebrew/unpack_strategy/rar.rb +++ b/Library/Homebrew/unpack_strategy/rar.rb @@ -21,7 +21,8 @@ module UnpackStrategy def extract_to_dir(unpack_dir, basename:, verbose:) system_command! "unrar", args: ["x", "-inul", path, unpack_dir], - env: { "PATH" => PATH.new(Formula["unrar"].opt_bin, ENV["PATH"]) } + env: { "PATH" => PATH.new(Formula["unrar"].opt_bin, ENV["PATH"]) }, + verbose: verbose end end end diff --git a/Library/Homebrew/unpack_strategy/subversion.rb b/Library/Homebrew/unpack_strategy/subversion.rb index 3824dce378..4c215e2672 100644 --- a/Library/Homebrew/unpack_strategy/subversion.rb +++ b/Library/Homebrew/unpack_strategy/subversion.rb @@ -13,7 +13,8 @@ module UnpackStrategy def extract_to_dir(unpack_dir, basename:, verbose:) system_command! "svn", args: ["export", "--force", ".", unpack_dir], - chdir: path.to_s + chdir: path.to_s, + verbose: verbose end end end diff --git a/Library/Homebrew/unpack_strategy/tar.rb b/Library/Homebrew/unpack_strategy/tar.rb index a21682050d..d4b63a7d4f 100644 --- a/Library/Homebrew/unpack_strategy/tar.rb +++ b/Library/Homebrew/unpack_strategy/tar.rb @@ -35,11 +35,13 @@ module UnpackStrategy if DependencyCollector.tar_needs_xz_dependency? && Xz.can_extract?(path) tmpdir = Pathname(tmpdir) - Xz.new(path).extract(to: tmpdir) + Xz.new(path).extract(to: tmpdir, verbose: verbose) tar_path = tmpdir.children.first end - system_command! "tar", args: ["xf", tar_path, "-C", unpack_dir] + system_command! "tar", + args: ["xf", tar_path, "-C", unpack_dir], + verbose: verbose end end end diff --git a/Library/Homebrew/unpack_strategy/xar.rb b/Library/Homebrew/unpack_strategy/xar.rb index 043c6a5f49..0ebb198bfe 100644 --- a/Library/Homebrew/unpack_strategy/xar.rb +++ b/Library/Homebrew/unpack_strategy/xar.rb @@ -15,7 +15,9 @@ module UnpackStrategy private def extract_to_dir(unpack_dir, basename:, verbose:) - system_command! "xar", args: ["-x", "-f", path, "-C", unpack_dir] + system_command! "xar", + args: ["-x", "-f", path, "-C", unpack_dir], + verbose: verbose end end end diff --git a/Library/Homebrew/unpack_strategy/xz.rb b/Library/Homebrew/unpack_strategy/xz.rb index 99673e6159..0f980a4887 100644 --- a/Library/Homebrew/unpack_strategy/xz.rb +++ b/Library/Homebrew/unpack_strategy/xz.rb @@ -23,7 +23,8 @@ module UnpackStrategy quiet_flags = verbose ? [] : ["-q"] system_command! "unxz", args: [*quiet_flags, "-T0", "--", unpack_dir/basename], - env: { "PATH" => PATH.new(Formula["xz"].opt_bin, ENV["PATH"]) } + env: { "PATH" => PATH.new(Formula["xz"].opt_bin, ENV["PATH"]) }, + verbose: verbose end end end diff --git a/Library/Homebrew/unpack_strategy/zip.rb b/Library/Homebrew/unpack_strategy/zip.rb index ade45f6302..53abf291cd 100644 --- a/Library/Homebrew/unpack_strategy/zip.rb +++ b/Library/Homebrew/unpack_strategy/zip.rb @@ -16,7 +16,9 @@ module UnpackStrategy def extract_to_dir(unpack_dir, basename:, verbose:) quiet_flags = verbose ? [] : ["-qq"] - system_command! "unzip", args: [*quiet_flags, path, "-d", unpack_dir] + system_command! "unzip", + args: [*quiet_flags, path, "-d", unpack_dir], + verbose: verbose end end end