Detect versions in tag specs
Closes Homebrew/homebrew#18300. Closes Homebrew/homebrew#20891.
This commit is contained in:
		
							parent
							
								
									74b60a561c
								
							
						
					
					
						commit
						033ef09518
					
				@ -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
 | 
			
		||||
 | 
			
		||||
@ -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
 | 
			
		||||
 | 
			
		||||
@ -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')
 | 
			
		||||
 | 
			
		||||
@ -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
 | 
			
		||||
 | 
			
		||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user