Skip to content

Commit

Permalink
audit: fix "version should not decrease" check.
Browse files Browse the repository at this point in the history
Fix the "version should not decrease" check so it correctly handles
`version_scheme`s.

Fixes Homebrew#1489.
  • Loading branch information
MikeMcQuaid committed Nov 13, 2016
1 parent 694cc87 commit c78aa43
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 15 deletions.
37 changes: 25 additions & 12 deletions Library/Homebrew/dev-cmd/audit.rb
Original file line number Diff line number Diff line change
Expand Up @@ -662,26 +662,39 @@ def audit_revision_and_version_scheme
return if @new_formula

fv = FormulaVersions.new(formula, max_depth: 10)
no_decrease_attributes = [:revision, :version_scheme]
attributes = no_decrease_attributes + [:version]
attributes = [:revision, :version_scheme]

attributes_map = fv.version_attributes_map(attributes, "origin/master")

no_decrease_attributes.each do |attribute|
attributes_for_version = attributes_map[attribute][formula.version]
next if attributes_for_version.empty?
if formula.send(attribute) < attributes_for_version.max
problem "#{attribute} should not decrease"
[:stable, :devel].each do |spec|
attributes.each do |attribute|
spec_attribute_map = attributes_map[attribute][spec]
next if spec_attribute_map.nil? || spec_attribute_map.empty?

attributes_for_version = spec_attribute_map[formula.version]
next if attributes_for_version.nil? || attributes_for_version.empty?

if formula.send(attribute) < attributes_for_version.max
problem "#{spec} #{attribute} should not decrease"
end
end
end

versions = attributes_map[:version].values.flatten
if !versions.empty? && formula.version < versions.max
problem "version should not decrease"
spec_version_scheme_map = attributes_map[:version_scheme][spec]
next if spec_version_scheme_map.nil? || spec_version_scheme_map.empty?

max_version_scheme = spec_version_scheme_map.values.flatten.max
max_version = spec_version_scheme_map.select do |_, version_scheme|
version_scheme.first == max_version_scheme
end.keys.max

if max_version && formula.version < max_version
problem "#{spec} version should not decrease"
end
end

return if formula.revision.zero?
if formula.stable
revision_map = attributes_map[:revision]
revision_map = attributes_map[:revision][:stable]
if revision_map[formula.stable.version].empty? # check stable spec
problem "'revision #{formula.revision}' should be removed"
end
Expand Down
15 changes: 12 additions & 3 deletions Library/Homebrew/formula_versions.rb
Original file line number Diff line number Diff line change
Expand Up @@ -61,19 +61,28 @@ def bottle_version_map(branch)
def version_attributes_map(attributes, branch)
attributes_map = {}
return attributes_map if attributes.empty?

attributes.each do |attribute|
attributes_map[attribute] = Hash.new { |h, k| h[k] = [] }
attributes_map[attribute] ||= {}
end

rev_list(branch) do |rev|
formula_at_revision(rev) do |f|
attributes.each do |attribute|
map = attributes_map[attribute]
map[f.stable.version] << f.send(attribute) if f.stable
map[f.devel.version] << f.send(attribute) if f.devel
if f.stable
map[:stable] ||= {}
map[:stable][f.stable.version] ||= []
map[:stable][f.stable.version] << f.send(attribute)
end
next unless f.devel
map[:devel] ||= {}
map[:stable][f.devel.version] ||= []
map[:devel][f.devel.version] << f.send(attribute)
end
end
end

attributes_map
end
end

0 comments on commit c78aa43

Please sign in to comment.