Detect versions in tag specs

Closes Homebrew/homebrew#18300.
Closes Homebrew/homebrew#20891.
This commit is contained in:
Jack Nagel 2013-06-28 21:17:12 -05:00
parent 74b60a561c
commit 033ef09518
4 changed files with 24 additions and 7 deletions

View File

@ -276,7 +276,7 @@ class FormulaAuditor
problem "Invalid or missing #{spec} version" problem "Invalid or missing #{spec} version"
else else
version_text = s.version unless s.version.detected_from_url? version_text = s.version unless s.version.detected_from_url?
version_url = Version.parse(s.url) version_url = Version.detect(s.url, s.specs)
if version_url.to_s == version_text.to_s && s.version.instance_of?(Version) if version_url.to_s == version_text.to_s && s.version.instance_of?(Version)
problem "#{spec} version #{version_text} is redundant with version scanned from URL" problem "#{spec} version #{version_text} is redundant with version scanned from URL"
end end

View File

@ -35,6 +35,14 @@ class SoftwareSpec
raise e raise e
end end
def detect_version(val)
case val
when nil then Version.detect(url, specs)
when String then Version.new(val)
when Hash then Version.new_with_scheme(*val.shift)
end
end
# The methods that follow are used in the block-form DSL spec methods # The methods that follow are used in the block-form DSL spec methods
Checksum::TYPES.each do |cksum| Checksum::TYPES.each do |cksum|
class_eval <<-EOS, __FILE__, __LINE__ + 1 class_eval <<-EOS, __FILE__, __LINE__ + 1
@ -52,12 +60,7 @@ class SoftwareSpec
end end
def version val=nil def version val=nil
@version ||= @version ||= detect_version(val)
case val
when nil then Version.parse(@url)
when Hash then Version.new_with_scheme(*val.shift)
else Version.new(val)
end
end end
def mirror val def mirror val

View File

@ -60,6 +60,12 @@ class SoftwareSpecTests < Test::Unit::TestCase
assert_instance_of scheme, @spec.version assert_instance_of scheme, @spec.version
end end
def test_version_from_tag
@spec.url('http://foo.com/bar-1.0.tar.gz', :tag => 'v1.0.2')
assert_version_equal '1.0.2', @spec.version
assert @spec.version.detected_from_url?
end
def test_mirrors def test_mirrors
assert_empty @spec.mirrors assert_empty @spec.mirrors
@spec.mirror('foo') @spec.mirror('foo')

View File

@ -154,6 +154,14 @@ class Version
end end
end end
def self.detect(url, specs={})
if specs.has_key?(:tag)
new(specs[:tag][/((?:\d+\.)*\d+)/, 1], true)
else
parse(url)
end
end
def initialize(val, detected=false) def initialize(val, detected=false)
@version = val.to_s @version = val.to_s
@detected_from_url = detected @detected_from_url = detected