diff --git a/Library/Homebrew/formula.rb b/Library/Homebrew/formula.rb index 3730b135c87ca..0acca654631e9 100644 --- a/Library/Homebrew/formula.rb +++ b/Library/Homebrew/formula.rb @@ -114,6 +114,9 @@ class Formula # @see .revision attr_reader :revision + # Used to change version schemes for packages + attr_reader :version_scheme + # The current working directory during builds. # Will only be non-`nil` inside {#install}. attr_reader :buildpath @@ -139,6 +142,7 @@ def initialize(name, path, spec) @name = name @path = path @revision = self.class.revision || 0 + @version_scheme = self.class.version_scheme || 0 if path == Formulary.core_path(name) @tap = CoreTap.instance @@ -432,6 +436,7 @@ def latest_head_prefix def head_version_outdated?(version, options={}) tab = Tab.for_keg(prefix(version)) + return true if tab.version_scheme < version_scheme return true if stable && tab.stable_version && tab.stable_version < stable.version return true if devel && tab.devel_version && tab.devel_version < devel.version @@ -1014,8 +1019,12 @@ def _outdated_versions(options = {}) installed_kegs.each do |keg| version = keg.version all_versions << version + next if version.head? - return [] if pkg_version <= version && !version.head? + tab = Tab.for_keg(keg) + next if version_scheme > tab.version_scheme + next if version_scheme == tab.version_scheme && pkg_version > version + return [] end head_version = latest_head_version @@ -1288,6 +1297,7 @@ def to_hash "head" => (head.version.to_s if head) }, "revision" => revision, + "version_scheme" => version_scheme, "installed" => [], "linked_keg" => (linked_keg.resolved_path.basename.to_s if linked_keg.exist?), "pinned" => pinned?, @@ -1695,6 +1705,18 @@ class << self #
revision 1attr_rw :revision + # @!attribute [w] version_scheme + # Used for creating new Homebrew versions schemes. For example, if we want + # to change version scheme from one to another, then we may need to update + # `version_scheme` of this {Formula} to be able to use new version scheme. + # E.g. to move from 20151020 scheme to 1.0.0 we need to increment + # `version_scheme`. Without this, the prior scheme will always equate to a + # higher version. + # `0` if unset. + # + #
version_scheme 1+ attr_rw :version_scheme + # A list of the {.stable}, {.devel} and {.head} {SoftwareSpec}s. # @private def specs diff --git a/Library/Homebrew/tab.rb b/Library/Homebrew/tab.rb index d5a95e05dd471..cf398fcbfa31a 100644 --- a/Library/Homebrew/tab.rb +++ b/Library/Homebrew/tab.rb @@ -37,6 +37,7 @@ def self.create(formula, compiler, stdlib) "stable" => formula.stable ? formula.stable.version.to_s : nil, "devel" => formula.devel ? formula.devel.version.to_s : nil, "head" => formula.head ? formula.head.version.to_s : nil, + "version_scheme" => formula.version_scheme, } } } @@ -78,6 +79,7 @@ def self.from_file_content(content, path) "stable" => nil, "devel" => nil, "head" => nil, + "version_scheme" => 0, } end @@ -142,6 +144,7 @@ def self.for_formula(f) "stable" => f.stable ? f.stable.version.to_s : nil, "devel" => f.devel ? f.devel.version.to_s : nil, "head" => f.head ? f.head.version.to_s : nil, + "version_scheme" => f.version_scheme, } } end @@ -168,6 +171,7 @@ def self.empty "stable" => nil, "devel" => nil, "head" => nil, + "version_scheme" => 0, } } } @@ -271,6 +275,10 @@ def head_version Version.create(versions["head"]) if versions["head"] end + def version_scheme + versions["version_scheme"] || 0 + end + def source_modified_time Time.at(super) end diff --git a/Library/Homebrew/test/test_formula.rb b/Library/Homebrew/test/test_formula.rb index af98c358f0fb3..7ebb178841a38 100644 --- a/Library/Homebrew/test/test_formula.rb +++ b/Library/Homebrew/test/test_formula.rb @@ -583,7 +583,6 @@ def setup_tab_for_prefix(prefix, options = {}) def reset_outdated_versions f.instance_variable_set(:@outdated_versions, nil) - f.instance_variable_set(:@outdated_versions_head_fetched, nil) end def test_greater_different_tap_installed @@ -732,4 +731,69 @@ def test_outdated_fetch_head FileUtils.rm_rf HOMEBREW_CACHE/"testball--git" FileUtils.rm_rf HOMEBREW_CELLAR/"testball" end + + def test_outdated_versions_version_scheme_changed + @f = formula("testball") do + url "foo" + version "20141010" + version_scheme 1 + end + + prefix = HOMEBREW_CELLAR.join("testball/0.1") + setup_tab_for_prefix(prefix, :versions => { "stable" => "0.1" }) + + refute_predicate f.outdated_versions, :empty? + ensure + prefix.rmtree + end + + def test_outdated_versions_mixed_version_schemes + @f = formula("testball") do + url "foo" + version "20141010" + version_scheme 3 + end + + prefix_a = HOMEBREW_CELLAR.join("testball/20141009") + setup_tab_for_prefix(prefix_a, :versions => { "stable" => "20141009", "version_scheme" => 1 }) + + prefix_b = HOMEBREW_CELLAR.join("testball/2.14") + setup_tab_for_prefix(prefix_b, :versions => { "stable" => "2.14", "version_scheme" => 2 }) + + refute_predicate f.outdated_versions, :empty? + reset_outdated_versions + + prefix_c = HOMEBREW_CELLAR.join("testball/20141009") + setup_tab_for_prefix(prefix_c, :versions => { "stable" => "20141009", "version_scheme" => 3 }) + + refute_predicate f.outdated_versions, :empty? + reset_outdated_versions + + prefix_d = HOMEBREW_CELLAR.join("testball/20141011") + setup_tab_for_prefix(prefix_d, :versions => { "stable" => "20141009", "version_scheme" => 3 }) + assert_predicate f.outdated_versions, :empty? + ensure + f.rack.rmtree + end + + def test_outdated_versions_head_with_version_scheme + @f = formula("testball") do + url "foo" + version "1.0" + version_scheme 2 + end + + head_prefix = HOMEBREW_CELLAR.join("testball/HEAD") + + setup_tab_for_prefix(head_prefix, :versions => { "stable" => "1.0", "version_scheme" => 1 }) + refute_predicate f.outdated_versions, :empty? + + reset_outdated_versions + head_prefix.rmtree + + setup_tab_for_prefix(head_prefix, :versions => { "stable" => "1.0", "version_scheme" => 2 }) + assert_predicate f.outdated_versions, :empty? + ensure + head_prefix.rmtree + end end