aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--Library/Homebrew/cmd/audit.rb2
-rw-r--r--Library/Homebrew/formula_support.rb15
-rw-r--r--Library/Homebrew/test/test_software_spec.rb6
-rw-r--r--Library/Homebrew/version.rb8
4 files changed, 24 insertions, 7 deletions
diff --git a/Library/Homebrew/cmd/audit.rb b/Library/Homebrew/cmd/audit.rb
index f19a461a7..603dac89b 100644
--- a/Library/Homebrew/cmd/audit.rb
+++ b/Library/Homebrew/cmd/audit.rb
@@ -276,7 +276,7 @@ class FormulaAuditor
problem "Invalid or missing #{spec} version"
else
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)
problem "#{spec} version #{version_text} is redundant with version scanned from URL"
end
diff --git a/Library/Homebrew/formula_support.rb b/Library/Homebrew/formula_support.rb
index f5936ea65..1ef4d3abc 100644
--- a/Library/Homebrew/formula_support.rb
+++ b/Library/Homebrew/formula_support.rb
@@ -35,6 +35,14 @@ class SoftwareSpec
raise e
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
Checksum::TYPES.each do |cksum|
class_eval <<-EOS, __FILE__, __LINE__ + 1
@@ -52,12 +60,7 @@ class SoftwareSpec
end
def version val=nil
- @version ||=
- case val
- when nil then Version.parse(@url)
- when Hash then Version.new_with_scheme(*val.shift)
- else Version.new(val)
- end
+ @version ||= detect_version(val)
end
def mirror val
diff --git a/Library/Homebrew/test/test_software_spec.rb b/Library/Homebrew/test/test_software_spec.rb
index 0090ec099..f3eed4769 100644
--- a/Library/Homebrew/test/test_software_spec.rb
+++ b/Library/Homebrew/test/test_software_spec.rb
@@ -60,6 +60,12 @@ class SoftwareSpecTests < Test::Unit::TestCase
assert_instance_of scheme, @spec.version
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
assert_empty @spec.mirrors
@spec.mirror('foo')
diff --git a/Library/Homebrew/version.rb b/Library/Homebrew/version.rb
index 066852b8e..e9af49844 100644
--- a/Library/Homebrew/version.rb
+++ b/Library/Homebrew/version.rb
@@ -154,6 +154,14 @@ class Version
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)
@version = val.to_s
@detected_from_url = detected