bottle: add old_checksums helper function

This commit is contained in:
Seeker 2021-01-01 15:23:09 -08:00
parent e5eb6a2646
commit ec841e7b62

View File

@ -489,36 +489,21 @@ module Homebrew
bottle.sha256 tag_hash["sha256"] => tag.to_sym bottle.sha256 tag_hash["sha256"] => tag.to_sym
end end
output = bottle_output bottle
if args.write? if args.write?
path = Pathname.new((HOMEBREW_REPOSITORY/bottle_hash["formula"]["path"]).to_s) path = Pathname.new((HOMEBREW_REPOSITORY/bottle_hash["formula"]["path"]).to_s)
update_or_add = T.let(nil, T.nilable(String)) checksums = old_checksums(path, bottle_hash, args: args)
update_or_add = checksums.nil? ? "add" : "update"
checksums&.each(&bottle.method(:sha256))
output = bottle_output(bottle)
puts output
Utils::Inreplace.inreplace(path) do |s| Utils::Inreplace.inreplace(path) do |s|
formula_contents = s.inreplace_string formula_contents = s.inreplace_string
bottle_node = Utils::AST.bottle_block(formula_contents) case update_or_add
if bottle_node.present? when "update"
update_or_add = "update"
if args.keep_old?
old_keys = Utils::AST.body_children(bottle_node.body).map(&:method_name)
old_bottle_spec = Formulary.factory(path).bottle_specification
mismatches, checksums = merge_bottle_spec(old_keys, old_bottle_spec, bottle_hash["bottle"])
if mismatches.present?
odie <<~EOS
--keep-old was passed but there are changes in:
#{mismatches.join("\n")}
EOS
end
checksums.each { |cksum| bottle.sha256(cksum) }
output = bottle_output bottle
end
puts output
Utils::AST.replace_bottle_stanza!(formula_contents, output) Utils::AST.replace_bottle_stanza!(formula_contents, output)
else when "add"
odie "--keep-old was passed but there was no existing bottle block!" if args.keep_old?
puts output
update_or_add = "add"
Utils::AST.add_bottle_stanza!(formula_contents, output) Utils::AST.add_bottle_stanza!(formula_contents, output)
end end
end end
@ -537,7 +522,7 @@ module Homebrew
end end
end end
else else
puts output puts bottle_output(bottle)
end end
end end
end end
@ -564,7 +549,7 @@ module Homebrew
mismatches << "#{key}: old: #{old_value.inspect}, new: #{new_value.inspect}" mismatches << "#{key}: old: #{old_value.inspect}, new: #{new_value.inspect}"
end end
return [mismatches, checksums] unless old_keys.include? :sha256 return [mismatches, checksums] if old_keys.exclude? :sha256
old_bottle_spec.collector.each_key do |tag| old_bottle_spec.collector.each_key do |tag|
old_value = old_bottle_spec.collector[tag].hexdigest old_value = old_bottle_spec.collector[tag].hexdigest
@ -578,4 +563,24 @@ module Homebrew
[mismatches, checksums] [mismatches, checksums]
end end
def old_checksums(formula_path, bottle_hash, args:)
bottle_node = Utils::AST.bottle_block(formula_path.read)
if bottle_node.nil?
odie "--keep-old was passed but there was no existing bottle block!" if args.keep_old?
return
end
return [] unless args.keep_old?
old_keys = Utils::AST.body_children(bottle_node.body).map(&:method_name)
old_bottle_spec = Formulary.factory(formula_path).bottle_specification
mismatches, checksums = merge_bottle_spec(old_keys, old_bottle_spec, bottle_hash["bottle"])
if mismatches.present?
odie <<~EOS
--keep-old was passed but there are changes in:
#{mismatches.join("\n")}
EOS
end
checksums
end
end end