diff --git a/Library/Homebrew/compat/ENV/shared.rb b/Library/Homebrew/compat/ENV/shared.rb index 6bca25f9de..4e8cd32918 100644 --- a/Library/Homebrew/compat/ENV/shared.rb +++ b/Library/Homebrew/compat/ENV/shared.rb @@ -1,9 +1,13 @@ module SharedEnvExtension - def j1 - odisabled "ENV.j1", "ENV.deparallelize" + module Compat + def j1 + odisabled "ENV.j1", "ENV.deparallelize" + end + + def java_cache + odisabled "ENV.java_cache" + end end - def java_cache - odisabled "ENV.java_cache" - end + prepend Compat end diff --git a/Library/Homebrew/compat/dependable.rb b/Library/Homebrew/compat/dependable.rb index 1b7eec2f0c..583bf51dab 100644 --- a/Library/Homebrew/compat/dependable.rb +++ b/Library/Homebrew/compat/dependable.rb @@ -1,6 +1,10 @@ module Dependable - def run? - odeprecated "Dependable#run?" - tags.include? :run + module Compat + def run? + odeprecated "Dependable#run?" + tags.include? :run + end end + + prepend Compat end diff --git a/Library/Homebrew/compat/extend/string.rb b/Library/Homebrew/compat/extend/string.rb index b704cd2b5f..3155168149 100644 --- a/Library/Homebrew/compat/extend/string.rb +++ b/Library/Homebrew/compat/extend/string.rb @@ -1,19 +1,23 @@ class String - def undent - odisabled "<<-EOS.undent", "<<~EOS" - self - end - alias unindent undent + module Compat + def undent + odisabled "<<-EOS.undent", "<<~EOS" + self + end + alias unindent undent - # eg: - # if foo then <<-EOS.undent_________________________________________________________72 - # Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do - # eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad - # minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip - # ex ea commodo consequat. Duis aute irure dolor in reprehenderit in - # voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur - # sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt - # mollit anim id est laborum. - # EOS - alias undent_________________________________________________________72 undent + # eg: + # if foo then <<-EOS.undent_________________________________________________________72 + # Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do + # eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad + # minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip + # ex ea commodo consequat. Duis aute irure dolor in reprehenderit in + # voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur + # sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt + # mollit anim id est laborum. + # EOS + alias undent_________________________________________________________72 undent + end + + prepend Compat end diff --git a/Library/Homebrew/compat/formula.rb b/Library/Homebrew/compat/formula.rb index 397b8e12ca..7432865f12 100644 --- a/Library/Homebrew/compat/formula.rb +++ b/Library/Homebrew/compat/formula.rb @@ -1,5 +1,9 @@ class Formula - def rake(*) - odisabled "FileUtils#rake", "system \"rake\"" + module Compat + def rake(*) + odisabled "FileUtils#rake", "system \"rake\"" + end end + + prepend Compat end diff --git a/Library/Homebrew/compat/gpg.rb b/Library/Homebrew/compat/gpg.rb index 5aaecf4d31..ef2bec4028 100644 --- a/Library/Homebrew/compat/gpg.rb +++ b/Library/Homebrew/compat/gpg.rb @@ -1,24 +1,27 @@ - module Gpg - module_function + class << self + module Compat + def executable + odisabled "Gpg.executable", 'which "gpg"' + end - def executable - odisabled "Gpg.executable", 'which "gpg"' - end + def available? + odisabled "Gpg.available?", 'which "gpg"' + end - def available? - odisabled "Gpg.available?", 'which "gpg"' - end + def create_test_key(*) + odisabled "Gpg.create_test_key" + end - def create_test_key(_) - odisabled "Gpg.create_test_key" - end + def cleanup_test_processes! + odisabled "Gpg.cleanup_test_processes!" + end - def cleanup_test_processes! - odisabled "Gpg.cleanup_test_processes!" - end + def test(*) + odisabled "Gpg.test" + end + end - def test(_) - odisabled "Gpg.test" + prepend Compat end end diff --git a/Library/Homebrew/compat/hbc.rb b/Library/Homebrew/compat/hbc.rb index 608d46e376..b64c3e4377 100644 --- a/Library/Homebrew/compat/hbc.rb +++ b/Library/Homebrew/compat/hbc.rb @@ -7,17 +7,17 @@ require "compat/hbc/dsl" module Hbc class << self - prepend( - Module.new do - def init - Cache.delete_legacy_cache + module Compat + def init + Cache.delete_legacy_cache - Caskroom.migrate_caskroom_from_repo_to_prefix - Caskroom.migrate_legacy_caskroom + Caskroom.migrate_caskroom_from_repo_to_prefix + Caskroom.migrate_legacy_caskroom - super - end - end, - ) + super + end + end + + prepend Compat end end diff --git a/Library/Homebrew/compat/hbc/cache.rb b/Library/Homebrew/compat/hbc/cache.rb index 34221fcf1d..68b6d4f869 100644 --- a/Library/Homebrew/compat/hbc/cache.rb +++ b/Library/Homebrew/compat/hbc/cache.rb @@ -1,13 +1,17 @@ module Hbc module Cache - module_function + class << self + module Compat + def delete_legacy_cache + legacy_cache = HOMEBREW_CACHE.join("Casks") + return unless legacy_cache.exist? - def delete_legacy_cache - legacy_cache = HOMEBREW_CACHE.join("Casks") - return unless legacy_cache.exist? + ohai "Deleting legacy cache at #{legacy_cache}" + FileUtils.remove_entry_secure(legacy_cache) + end + end - ohai "Deleting legacy cache at #{legacy_cache}" - FileUtils.remove_entry_secure(legacy_cache) + prepend Compat end end end diff --git a/Library/Homebrew/compat/hbc/cask_loader.rb b/Library/Homebrew/compat/hbc/cask_loader.rb index e57aea71dd..c62c001a2f 100644 --- a/Library/Homebrew/compat/hbc/cask_loader.rb +++ b/Library/Homebrew/compat/hbc/cask_loader.rb @@ -1,22 +1,22 @@ -module CaskLoaderCompatibilityLayer - private - - def cask(header_token, **options, &block) - if header_token.is_a?(Hash) && header_token.key?(:v1) - odeprecated %q("cask :v1 => 'token'"), %q("cask 'token'") - header_token = header_token[:v1] - end - - super(header_token, **options, &block) - end -end - module Hbc module CaskLoader class FromContentLoader; end class FromPathLoader < FromContentLoader - prepend CaskLoaderCompatibilityLayer + module Compat + private + + def cask(header_token, **options, &block) + if header_token.is_a?(Hash) && header_token.key?(:v1) + odeprecated %q("cask :v1 => 'token'"), %q("cask 'token'") + header_token = header_token[:v1] + end + + super(header_token, **options, &block) + end + end + + prepend Compat end end end diff --git a/Library/Homebrew/compat/hbc/caskroom.rb b/Library/Homebrew/compat/hbc/caskroom.rb index 3621a35fb0..2a1d9bf48f 100644 --- a/Library/Homebrew/compat/hbc/caskroom.rb +++ b/Library/Homebrew/compat/hbc/caskroom.rb @@ -1,45 +1,49 @@ module Hbc module Caskroom - module_function + class << self + module Compat + def migrate_legacy_caskroom + return if Hbc.caskroom.exist? - def migrate_legacy_caskroom - return if Hbc.caskroom.exist? + legacy_caskroom = Pathname.new("/opt/homebrew-cask/Caskroom") + return if Hbc.caskroom == legacy_caskroom + return unless legacy_caskroom.exist? + return if legacy_caskroom.symlink? - legacy_caskroom = Pathname.new("/opt/homebrew-cask/Caskroom") - return if Hbc.caskroom == legacy_caskroom - return unless legacy_caskroom.exist? - return if legacy_caskroom.symlink? + ohai "Migrating Caskroom from #{legacy_caskroom} to #{Hbc.caskroom}." + if Hbc.caskroom.parent.writable? + FileUtils.mv legacy_caskroom, Hbc.caskroom + else + opoo "#{Hbc.caskroom.parent} is not writable, sudo is needed to move the Caskroom." + SystemCommand.run("/bin/mv", args: [legacy_caskroom, Hbc.caskroom.parent], sudo: true) + end - ohai "Migrating Caskroom from #{legacy_caskroom} to #{Hbc.caskroom}." - if Hbc.caskroom.parent.writable? - FileUtils.mv legacy_caskroom, Hbc.caskroom - else - opoo "#{Hbc.caskroom.parent} is not writable, sudo is needed to move the Caskroom." - SystemCommand.run("/bin/mv", args: [legacy_caskroom, Hbc.caskroom.parent], sudo: true) + ohai "Creating symlink from #{Hbc.caskroom} to #{legacy_caskroom}." + if legacy_caskroom.parent.writable? + FileUtils.ln_s Hbc.caskroom, legacy_caskroom + else + opoo "#{legacy_caskroom.parent} is not writable, sudo is needed to link the Caskroom." + SystemCommand.run("/bin/ln", args: ["-s", Hbc.caskroom, legacy_caskroom], sudo: true) + end + end + + def migrate_caskroom_from_repo_to_prefix + repo_caskroom = HOMEBREW_REPOSITORY.join("Caskroom") + return if Hbc.caskroom.exist? + return unless repo_caskroom.directory? + + ohai "Moving Caskroom from HOMEBREW_REPOSITORY to HOMEBREW_PREFIX" + + if Hbc.caskroom.parent.writable? + FileUtils.mv repo_caskroom, Hbc.caskroom + else + opoo "#{Hbc.caskroom.parent} is not writable, sudo is needed to move the Caskroom." + SystemCommand.run("/bin/mv", args: [repo_caskroom, Hbc.caskroom.parent], sudo: true) + end + end end - ohai "Creating symlink from #{Hbc.caskroom} to #{legacy_caskroom}." - if legacy_caskroom.parent.writable? - FileUtils.ln_s Hbc.caskroom, legacy_caskroom - else - opoo "#{legacy_caskroom.parent} is not writable, sudo is needed to link the Caskroom." - SystemCommand.run("/bin/ln", args: ["-s", Hbc.caskroom, legacy_caskroom], sudo: true) - end - end - - def migrate_caskroom_from_repo_to_prefix - repo_caskroom = HOMEBREW_REPOSITORY.join("Caskroom") - return if Hbc.caskroom.exist? - return unless repo_caskroom.directory? - - ohai "Moving Caskroom from HOMEBREW_REPOSITORY to HOMEBREW_PREFIX" - - if Hbc.caskroom.parent.writable? - FileUtils.mv repo_caskroom, Hbc.caskroom - else - opoo "#{Hbc.caskroom.parent} is not writable, sudo is needed to move the Caskroom." - SystemCommand.run("/bin/mv", args: [repo_caskroom, Hbc.caskroom.parent], sudo: true) - end + prepend Compat end end end diff --git a/Library/Homebrew/compat/hbc/cli/update.rb b/Library/Homebrew/compat/hbc/cli/update.rb index 95321e8981..348e3a2c76 100644 --- a/Library/Homebrew/compat/hbc/cli/update.rb +++ b/Library/Homebrew/compat/hbc/cli/update.rb @@ -2,22 +2,18 @@ require "cask/lib/hbc/cli/abstract_command" module Hbc class CLI - class Update < AbstractCommand - def self.run(*_ignored) - odeprecated "`brew cask update`", "`brew update`", disable_on: Time.utc(2017, 7, 1) - result = SystemCommand.run(HOMEBREW_BREW_FILE, args: ["update"], - print_stderr: true, - print_stdout: true) - exit result.exit_status - end + module Compat + class Update < AbstractCommand + def self.run(*_ignored) + odisabled "`brew cask update`", "`brew update`" + end - def self.visible - false - end - - def self.help - "a synonym for 'brew update'" + def self.visible + false + end end end + + prepend Compat end end diff --git a/Library/Homebrew/compat/hbc/dsl.rb b/Library/Homebrew/compat/hbc/dsl.rb index b550501ed5..483ca4a7e6 100644 --- a/Library/Homebrew/compat/hbc/dsl.rb +++ b/Library/Homebrew/compat/hbc/dsl.rb @@ -1,7 +1,11 @@ module Hbc class DSL - def license(*) - odeprecated "Hbc::DSL#license" + module Compat + def license(*) + odeprecated "Hbc::DSL#license" + end end + + prepend Compat end end diff --git a/Library/Homebrew/compat/os/mac.rb b/Library/Homebrew/compat/os/mac.rb index 6806fe900a..a839399c2e 100644 --- a/Library/Homebrew/compat/os/mac.rb +++ b/Library/Homebrew/compat/os/mac.rb @@ -1,10 +1,14 @@ module OS module Mac class << self - def release - odeprecated "MacOS.release", "MacOS.version" - version + module Compat + def release + odeprecated "MacOS.release", "MacOS.version" + version + end end + + prepend Compat end end end diff --git a/Library/Homebrew/test/cask/cli_spec.rb b/Library/Homebrew/test/cask/cli_spec.rb index e88b24ba2a..495aedb088 100644 --- a/Library/Homebrew/test/cask/cli_spec.rb +++ b/Library/Homebrew/test/cask/cli_spec.rb @@ -74,8 +74,8 @@ describe Hbc::CLI, :cask do end end - it "provides a help message for all commands" do - described_class.command_classes.each do |command_class| + it "provides a help message for all visible commands" do + described_class.command_classes.select(&:visible).each do |command_class| expect(command_class.help).to match(/\w+/), command_class.name end end