bottle: allow to keep old bottle specification
Closes Homebrew/homebrew#43766. Signed-off-by: Xu Cheng <xucheng@me.com>
This commit is contained in:
		
							parent
							
								
									fb1789ad3d
								
							
						
					
					
						commit
						70f2b6f195
					
				@ -130,6 +130,8 @@ module Homebrew
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
    if ARGV.include? "--no-revision"
 | 
					    if ARGV.include? "--no-revision"
 | 
				
			||||||
      bottle_revision = 0
 | 
					      bottle_revision = 0
 | 
				
			||||||
 | 
					    elsif ARGV.include? "--keep-old"
 | 
				
			||||||
 | 
					      bottle_revision = f.bottle_specification.revision
 | 
				
			||||||
    else
 | 
					    else
 | 
				
			||||||
      ohai "Determining #{f.full_name} bottle revision..."
 | 
					      ohai "Determining #{f.full_name} bottle revision..."
 | 
				
			||||||
      versions = FormulaVersions.new(f)
 | 
					      versions = FormulaVersions.new(f)
 | 
				
			||||||
@ -201,6 +203,17 @@ module Homebrew
 | 
				
			|||||||
    bottle.revision bottle_revision
 | 
					    bottle.revision bottle_revision
 | 
				
			||||||
    bottle.sha256 bottle_path.sha256 => bottle_tag
 | 
					    bottle.sha256 bottle_path.sha256 => bottle_tag
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    old_spec = f.bottle_specification
 | 
				
			||||||
 | 
					    if ARGV.include?("--keep-old") && !old_spec.checksums.empty?
 | 
				
			||||||
 | 
					      bad = [:root_url, :prefix, :cellar, :revision].any? do |field|
 | 
				
			||||||
 | 
					        old_spec.send(field) != bottle.send(field)
 | 
				
			||||||
 | 
					      end
 | 
				
			||||||
 | 
					      if bad
 | 
				
			||||||
 | 
					        bottle_path.unlink if bottle_path.exist?
 | 
				
			||||||
 | 
					        odie "--keep-old is passed but at least one of fields are not the same"
 | 
				
			||||||
 | 
					      end
 | 
				
			||||||
 | 
					    end
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    output = bottle_output bottle
 | 
					    output = bottle_output bottle
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    puts "./#{filename}"
 | 
					    puts "./#{filename}"
 | 
				
			||||||
@ -221,6 +234,9 @@ module Homebrew
 | 
				
			|||||||
  end
 | 
					  end
 | 
				
			||||||
 | 
					
 | 
				
			||||||
  def merge
 | 
					  def merge
 | 
				
			||||||
 | 
					    write = ARGV.include? "--write"
 | 
				
			||||||
 | 
					    keep_old = ARGV.include? "--keep-old"
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    merge_hash = {}
 | 
					    merge_hash = {}
 | 
				
			||||||
    ARGV.named.each do |argument|
 | 
					    ARGV.named.each do |argument|
 | 
				
			||||||
      bottle_block = IO.read(argument)
 | 
					      bottle_block = IO.read(argument)
 | 
				
			||||||
@ -231,15 +247,32 @@ module Homebrew
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
    merge_hash.each do |formula_name, bottle_blocks|
 | 
					    merge_hash.each do |formula_name, bottle_blocks|
 | 
				
			||||||
      ohai formula_name
 | 
					      ohai formula_name
 | 
				
			||||||
 | 
					      f = Formulary.factory(formula_name)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
      bottle = BottleSpecification.new.extend(BottleMerger)
 | 
					      bottle = if keep_old
 | 
				
			||||||
 | 
					        f.bottle_specification.dup
 | 
				
			||||||
 | 
					      else
 | 
				
			||||||
 | 
					        BottleSpecification.new
 | 
				
			||||||
 | 
					      end
 | 
				
			||||||
 | 
					      bottle.extend(BottleMerger)
 | 
				
			||||||
      bottle_blocks.each { |block| bottle.instance_eval(block) }
 | 
					      bottle_blocks.each { |block| bottle.instance_eval(block) }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					      old_spec = f.bottle_specification
 | 
				
			||||||
 | 
					      if keep_old && !old_spec.checksums.empty?
 | 
				
			||||||
 | 
					         bad = [:root_url, :prefix, :cellar, :revision].any? do |field|
 | 
				
			||||||
 | 
					           old_spec.send(field) != bottle.send(field)
 | 
				
			||||||
 | 
					         end
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					         if bad
 | 
				
			||||||
 | 
					           ofail "--keep-old is passed but at least one of fields are not the same, skip it"
 | 
				
			||||||
 | 
					           next
 | 
				
			||||||
 | 
					         end
 | 
				
			||||||
 | 
					      end
 | 
				
			||||||
 | 
					
 | 
				
			||||||
      output = bottle_output bottle
 | 
					      output = bottle_output bottle
 | 
				
			||||||
      puts output
 | 
					      puts output
 | 
				
			||||||
 | 
					
 | 
				
			||||||
      if ARGV.include? "--write"
 | 
					      if write
 | 
				
			||||||
        f = Formulary.factory(formula_name)
 | 
					 | 
				
			||||||
        update_or_add = nil
 | 
					        update_or_add = nil
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        Utils::Inreplace.inreplace(f.path) do |s|
 | 
					        Utils::Inreplace.inreplace(f.path) do |s|
 | 
				
			||||||
 | 
				
			|||||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user