From 0f84b976bab94d66af1f8eb658b5ca824f8d49d4 Mon Sep 17 00:00:00 2001 From: Xu Cheng Date: Sat, 19 Dec 2015 19:10:22 +0800 Subject: [PATCH] move CoreFormulaRepository into separate file For users whose local brew is at around 2015-06-11 to 2015-08-06, running `brew update` will emit following error: Error: uninitialized constant Formulary::CoreFormulaRepository This is caused by the same bug described in Homebrew/homebrew#42553. This commit workarounds this issue and restores `brew update` compatibility for users mentioned above. Also cleanup legacy `require "cmd/tap"`. --- Library/Homebrew/cmd/install.rb | 3 +- Library/Homebrew/cmd/pull.rb | 3 +- Library/Homebrew/cmd/readall.rb | 3 +- Library/Homebrew/cmd/tap.rb | 1 + Library/Homebrew/cmd/test-bot.rb | 3 +- Library/Homebrew/core_formula_repository.rb | 80 +++++++++++++++++++ Library/Homebrew/formula.rb | 1 + Library/Homebrew/formulary.rb | 1 + Library/Homebrew/tap.rb | 87 ++------------------- 9 files changed, 96 insertions(+), 86 deletions(-) create mode 100644 Library/Homebrew/core_formula_repository.rb diff --git a/Library/Homebrew/cmd/install.rb b/Library/Homebrew/cmd/install.rb index 4eb6f1660f..dbd8f5c04e 100644 --- a/Library/Homebrew/cmd/install.rb +++ b/Library/Homebrew/cmd/install.rb @@ -1,8 +1,9 @@ require "blacklist" require "cmd/doctor" require "cmd/search" -require "cmd/tap" require "formula_installer" +require "tap" +require "core_formula_repository" require "hardware" module Homebrew diff --git a/Library/Homebrew/cmd/pull.rb b/Library/Homebrew/cmd/pull.rb index bcfcb7d117..1454f99383 100644 --- a/Library/Homebrew/cmd/pull.rb +++ b/Library/Homebrew/cmd/pull.rb @@ -3,7 +3,8 @@ require "utils" require "formula" -require "cmd/tap" +require "tap" +require "core_formula_repository" module Homebrew def pull_url(url) diff --git a/Library/Homebrew/cmd/readall.rb b/Library/Homebrew/cmd/readall.rb index 4d74a6f410..7775c29238 100644 --- a/Library/Homebrew/cmd/readall.rb +++ b/Library/Homebrew/cmd/readall.rb @@ -4,7 +4,8 @@ # or to determine if any current formulae have Ruby issues require "formula" -require "cmd/tap" +require "tap" +require "core_formula_repository" require "thread" module Homebrew diff --git a/Library/Homebrew/cmd/tap.rb b/Library/Homebrew/cmd/tap.rb index a7fd3f5001..5c1ff089cc 100644 --- a/Library/Homebrew/cmd/tap.rb +++ b/Library/Homebrew/cmd/tap.rb @@ -1,4 +1,5 @@ require "tap" +require "core_formula_repository" module Homebrew def tap diff --git a/Library/Homebrew/cmd/test-bot.rb b/Library/Homebrew/cmd/test-bot.rb index b6b167f3f6..b297c71d82 100644 --- a/Library/Homebrew/cmd/test-bot.rb +++ b/Library/Homebrew/cmd/test-bot.rb @@ -29,7 +29,8 @@ require "date" require "rexml/document" require "rexml/xmldecl" require "rexml/cdata" -require "cmd/tap" +require "tap" +require "core_formula_repository" module Homebrew BYTES_IN_1_MEGABYTE = 1024*1024 diff --git a/Library/Homebrew/core_formula_repository.rb b/Library/Homebrew/core_formula_repository.rb new file mode 100644 index 0000000000..0c9994327e --- /dev/null +++ b/Library/Homebrew/core_formula_repository.rb @@ -0,0 +1,80 @@ +require "tap" + +# A specialized {Tap} class to mimic the core formula file system, which shares many +# similarities with normal {Tap}. +# TODO Separate core formulae with core codes. See discussion below for future plan: +# https://github.com/Homebrew/homebrew/pull/46735#discussion_r46820565 +class CoreFormulaRepository < Tap + # @private + def initialize + @user = "Homebrew" + @repo = "homebrew" + @name = "Homebrew/homebrew" + @path = HOMEBREW_REPOSITORY + end + + def self.instance + @instance ||= CoreFormulaRepository.new + end + + # @private + def uninstall + raise "Tap#uninstall is not available for CoreFormulaRepository" + end + + # @private + def pin + raise "Tap#pin is not available for CoreFormulaRepository" + end + + # @private + def unpin + raise "Tap#unpin is not available for CoreFormulaRepository" + end + + # @private + def pinned? + false + end + + # @private + def command_files + [] + end + + # @private + def custom_remote? + remote != "https://github.com/#{user}/#{repo}.git" + end + + # @private + def core_formula_repository? + true + end + + # @private + def formula_dir + HOMEBREW_LIBRARY/"Formula" + end + + # @private + def alias_dir + HOMEBREW_LIBRARY/"Aliases" + end + + # @private + def formula_renames + require "formula_renames" + FORMULA_RENAMES + end + + private + + def formula_file_to_name(file) + file.basename(".rb").to_s + end + + def alias_file_to_name(file) + file.basename.to_s + end +end diff --git a/Library/Homebrew/formula.rb b/Library/Homebrew/formula.rb index d7e5ffc49c..68c836f2b3 100644 --- a/Library/Homebrew/formula.rb +++ b/Library/Homebrew/formula.rb @@ -10,6 +10,7 @@ require "software_spec" require "install_renamed" require "pkg_version" require "tap" +require "core_formula_repository" require "formula_renames" require "keg" require "migrator" diff --git a/Library/Homebrew/formulary.rb b/Library/Homebrew/formulary.rb index e71656224d..56f221f330 100644 --- a/Library/Homebrew/formulary.rb +++ b/Library/Homebrew/formulary.rb @@ -1,6 +1,7 @@ require "digest/md5" require "formula_renames" require "tap" +require "core_formula_repository" # The Formulary is responsible for creating instances of Formula. # It is not meant to be used directy from formulae. diff --git a/Library/Homebrew/tap.rb b/Library/Homebrew/tap.rb index 03b702569a..59a4429a16 100644 --- a/Library/Homebrew/tap.rb +++ b/Library/Homebrew/tap.rb @@ -1,6 +1,3 @@ -require "utils/json" -require "descriptions" - # a {Tap} is used to extend the formulae provided by Homebrew core. # Usually, it's synced with a remote git repository. And it's likely # a Github repository with the name of `user/homebrew-repo`. In such @@ -32,6 +29,7 @@ class Tap repo = repo.strip_prefix "homebrew-" if user == "Homebrew" && repo == "homebrew" + require "core_formula_repository" return CoreFormulaRepository.instance end @@ -119,6 +117,7 @@ class Tap # @option options [String] :clone_targe If passed, it will be used as the clone remote. # @option options [Boolean] :full_clone If set as true, full clone will be used. def install(options = {}) + require "descriptions" raise TapAlreadyTappedError, name if installed? # ensure git is installed @@ -180,6 +179,7 @@ class Tap # uninstall this {Tap}. def uninstall + require "descriptions" raise TapUnavailableError, name unless installed? puts "Untapping #{name}... (#{path.abv})" @@ -326,6 +326,8 @@ class Tap # Hash with tap formula renames def formula_renames + require "utils/json" + @formula_renames ||= if (rename_file = path/"formula_renames.json").file? Utils::JSON.load(rename_file.read) else @@ -363,82 +365,3 @@ class Tap "#{name}/#{file.basename}" end end - -# A specialized {Tap} class to mimic the core formula file system, which shares many -# similarities with normal {Tap}. -# TODO Separate core formulae with core codes. See discussion below for future plan: -# https://github.com/Homebrew/homebrew/pull/46735#discussion_r46820565 -class CoreFormulaRepository < Tap - # @private - def initialize - @user = "Homebrew" - @repo = "homebrew" - @name = "Homebrew/homebrew" - @path = HOMEBREW_REPOSITORY - end - - def self.instance - @instance ||= CoreFormulaRepository.new - end - - # @private - def uninstall - raise "Tap#uninstall is not available for CoreFormulaRepository" - end - - # @private - def pin - raise "Tap#pin is not available for CoreFormulaRepository" - end - - # @private - def unpin - raise "Tap#unpin is not available for CoreFormulaRepository" - end - - # @private - def pinned? - false - end - - # @private - def command_files - [] - end - - # @private - def custom_remote? - remote != "https://github.com/#{user}/#{repo}.git" - end - - # @private - def core_formula_repository? - true - end - - # @private - def formula_dir - HOMEBREW_LIBRARY/"Formula" - end - - # @private - def alias_dir - HOMEBREW_LIBRARY/"Aliases" - end - - # @private - def formula_renames - require "formula_renames" - FORMULA_RENAMES - end - - private - - def formula_file_to_name(file) - file.basename(".rb").to_s - end - - def alias_file_to_name(file) - file.basename.to_s - end -end