2014-06-19 17:57:36 -05:00
|
|
|
require "formula"
|
|
|
|
|
2014-05-28 16:23:33 -05:00
|
|
|
class FormulaVersions
|
|
|
|
IGNORED_EXCEPTIONS = [
|
|
|
|
ArgumentError, NameError, SyntaxError, TypeError,
|
|
|
|
FormulaSpecificationError, FormulaValidationError,
|
2016-10-08 12:04:38 +02:00
|
|
|
ErrorDuringExecution, LoadError, MethodDeprecatedError
|
2016-09-17 15:17:27 +01:00
|
|
|
].freeze
|
2014-05-28 16:23:33 -05:00
|
|
|
|
2017-04-23 18:56:22 +01:00
|
|
|
MAX_VERSIONS_DEPTH = 2
|
|
|
|
|
2015-09-02 16:42:54 +08:00
|
|
|
attr_reader :name, :path, :repository, :entry_name
|
2014-05-28 16:23:33 -05:00
|
|
|
|
2017-04-23 18:56:22 +01:00
|
|
|
def initialize(formula)
|
2015-04-01 21:06:03 -04:00
|
|
|
@name = formula.name
|
2015-09-02 16:42:54 +08:00
|
|
|
@path = formula.path
|
2015-12-06 22:45:03 +08:00
|
|
|
@repository = formula.tap.path
|
2015-09-02 16:42:54 +08:00
|
|
|
@entry_name = @path.relative_path_from(repository).to_s
|
2017-04-23 18:56:22 +01:00
|
|
|
@current_formula = formula
|
2014-05-28 16:23:33 -05:00
|
|
|
end
|
|
|
|
|
2015-05-29 00:16:50 -04:00
|
|
|
def rev_list(branch)
|
2014-05-28 16:23:33 -05:00
|
|
|
repository.cd do
|
2014-07-05 13:50:54 -05:00
|
|
|
Utils.popen_read("git", "rev-list", "--abbrev-commit", "--remove-empty", branch, "--", entry_name) do |io|
|
2017-04-23 18:56:22 +01:00
|
|
|
yield io.readline.chomp until io.eof?
|
2014-05-28 16:23:33 -05:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
def file_contents_at_revision(rev)
|
2015-03-06 22:30:22 +08:00
|
|
|
repository.cd { Utils.popen_read("git", "cat-file", "blob", "#{rev}:#{entry_name}") }
|
2014-05-28 16:23:33 -05:00
|
|
|
end
|
|
|
|
|
2015-01-04 14:29:00 -05:00
|
|
|
def formula_at_revision(rev)
|
2015-09-02 16:42:54 +08:00
|
|
|
contents = file_contents_at_revision(rev)
|
|
|
|
|
|
|
|
begin
|
2016-08-12 21:06:51 +01:00
|
|
|
Homebrew.raise_deprecation_exceptions = true
|
2016-08-11 17:07:31 +01:00
|
|
|
nostdout { yield Formulary.from_contents(name, path, contents) }
|
2015-09-02 16:42:54 +08:00
|
|
|
rescue *IGNORED_EXCEPTIONS => e
|
|
|
|
# We rescue these so that we can skip bad versions and
|
|
|
|
# continue walking the history
|
|
|
|
ohai "#{e} in #{name} at revision #{rev}", e.backtrace if ARGV.debug?
|
|
|
|
rescue FormulaUnavailableError
|
|
|
|
# Suppress this error
|
2016-08-12 21:06:51 +01:00
|
|
|
ensure
|
|
|
|
Homebrew.raise_deprecation_exceptions = false
|
2014-05-28 16:23:33 -05:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2015-05-29 00:20:05 -04:00
|
|
|
def bottle_version_map(branch)
|
2014-05-28 16:23:33 -05:00
|
|
|
map = Hash.new { |h, k| h[k] = [] }
|
2017-04-23 18:56:22 +01:00
|
|
|
|
|
|
|
versions_seen = 0
|
2014-05-28 16:23:33 -05:00
|
|
|
rev_list(branch) do |rev|
|
|
|
|
formula_at_revision(rev) do |f|
|
2015-01-20 22:25:24 -05:00
|
|
|
bottle = f.bottle_specification
|
2016-09-23 11:01:40 +02:00
|
|
|
map[f.pkg_version] << bottle.rebuild unless bottle.checksums.empty?
|
2017-04-23 18:56:22 +01:00
|
|
|
versions_seen = (map.keys + [f.pkg_version]).uniq.length
|
2014-05-28 16:23:33 -05:00
|
|
|
end
|
2017-04-23 18:56:22 +01:00
|
|
|
return map if versions_seen > MAX_VERSIONS_DEPTH
|
2014-05-28 16:23:33 -05:00
|
|
|
end
|
|
|
|
map
|
|
|
|
end
|
2016-01-14 13:33:56 +08:00
|
|
|
|
2017-05-10 20:45:34 +02:00
|
|
|
def previous_version_and_checksum(branch)
|
|
|
|
map = {}
|
|
|
|
|
|
|
|
rev_list(branch) do |rev|
|
|
|
|
formula_at_revision(rev) do |f|
|
|
|
|
[:stable, :devel].each do |spec_sym|
|
|
|
|
next unless spec = f.send(spec_sym)
|
|
|
|
map[spec_sym] ||= { version: spec.version, checksum: spec.checksum }
|
|
|
|
end
|
|
|
|
|
|
|
|
break if map[:stable] && map[:devel]
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
map[:stable] ||= {}
|
|
|
|
map[:devel] ||= {}
|
|
|
|
|
|
|
|
map
|
|
|
|
end
|
|
|
|
|
2016-08-18 12:52:25 +01:00
|
|
|
def version_attributes_map(attributes, branch)
|
|
|
|
attributes_map = {}
|
|
|
|
return attributes_map if attributes.empty?
|
2016-11-13 13:35:25 +00:00
|
|
|
|
2017-04-26 11:33:13 +01:00
|
|
|
attributes.each do |attribute|
|
|
|
|
attributes_map[attribute] ||= {
|
|
|
|
stable: {},
|
|
|
|
devel: {},
|
|
|
|
}
|
|
|
|
end
|
|
|
|
|
2017-04-23 18:56:22 +01:00
|
|
|
stable_versions_seen = 0
|
2016-01-14 13:33:56 +08:00
|
|
|
rev_list(branch) do |rev|
|
|
|
|
formula_at_revision(rev) do |f|
|
2016-08-18 12:52:25 +01:00
|
|
|
attributes.each do |attribute|
|
2017-02-22 08:49:49 +00:00
|
|
|
map = attributes_map[attribute]
|
2017-04-23 18:56:22 +01:00
|
|
|
set_attribute_map(map, f, attribute)
|
|
|
|
|
|
|
|
stable_keys_length = (map[:stable].keys + [f.version]).uniq.length
|
|
|
|
stable_versions_seen = [stable_versions_seen, stable_keys_length].max
|
2016-08-18 12:52:25 +01:00
|
|
|
end
|
2016-01-14 13:33:56 +08:00
|
|
|
end
|
2017-04-23 18:56:22 +01:00
|
|
|
break if stable_versions_seen > MAX_VERSIONS_DEPTH
|
2016-01-14 13:33:56 +08:00
|
|
|
end
|
2016-11-13 13:35:25 +00:00
|
|
|
|
2016-08-18 12:52:25 +01:00
|
|
|
attributes_map
|
2016-01-14 13:33:56 +08:00
|
|
|
end
|
2017-04-23 18:56:22 +01:00
|
|
|
|
|
|
|
private
|
|
|
|
|
|
|
|
def set_attribute_map(map, f, attribute)
|
|
|
|
if f.stable
|
|
|
|
map[:stable][f.stable.version] ||= []
|
|
|
|
map[:stable][f.stable.version] << f.send(attribute)
|
|
|
|
end
|
|
|
|
return unless f.devel
|
|
|
|
map[:devel][f.devel.version] ||= []
|
|
|
|
map[:devel][f.devel.version] << f.send(attribute)
|
|
|
|
end
|
2014-05-28 16:23:33 -05:00
|
|
|
end
|