aboutsummaryrefslogtreecommitdiffstats
path: root/Library/Homebrew/dev-cmd
diff options
context:
space:
mode:
authorMike McQuaid2017-05-09 15:10:29 +0100
committerMike McQuaid2017-05-09 15:10:29 +0100
commitb14f1572b7ee3b04593bde5d52e14a36aea8d701 (patch)
tree0a3694ee12e132e54815605accd3c36a01553847 /Library/Homebrew/dev-cmd
parentf1d4c4be78905be0d5fd83922ff1262ed92ba4e8 (diff)
downloadbrew-b14f1572b7ee3b04593bde5d52e14a36aea8d701.tar.bz2
audit: more checks for versioned aliases.
Check that a required versioned alias has a valid name (rather than assuming it’s fine based on it’s existence alone) and check for the presence of invalid version aliases. This should handle the case where someone bumps a formula but forgets to rename the alias that’s mentioned in #2596.
Diffstat (limited to 'Library/Homebrew/dev-cmd')
-rw-r--r--Library/Homebrew/dev-cmd/audit.rb48
1 files changed, 32 insertions, 16 deletions
diff --git a/Library/Homebrew/dev-cmd/audit.rb b/Library/Homebrew/dev-cmd/audit.rb
index cb25ca794..c134441b2 100644
--- a/Library/Homebrew/dev-cmd/audit.rb
+++ b/Library/Homebrew/dev-cmd/audit.rb
@@ -307,25 +307,41 @@ class FormulaAuditor
unversioned_name = unversioned_formula.basename(".rb")
problem "#{formula} is versioned but no #{unversioned_name} formula exists"
end
- elsif ARGV.build_stable?
- versioned_formulae = Dir[formula.path.to_s.gsub(/\.rb$/, "@*.rb")]
- needs_versioned_alias = !versioned_formulae.empty? &&
- formula.tap &&
- formula.aliases.grep(/.@\d/).empty?
- if needs_versioned_alias
- _, last_alias_version = File.basename(versioned_formulae.sort.reverse.first)
- .gsub(/\.rb$/, "")
- .split("@")
- major, minor, = formula.version.to_s.split(".")
- alias_name = if last_alias_version.split(".").length == 1
- "#{formula.name}@#{major}"
+ elsif ARGV.build_stable? &&
+ !(versioned_formulae = Dir[formula.path.to_s.gsub(/\.rb$/, "@*.rb")]).empty?
+ versioned_aliases = formula.aliases.grep(/.@\d/)
+ _, last_alias_version =
+ File.basename(versioned_formulae.sort.reverse.first)
+ .gsub(/\.rb$/, "").split("@")
+ major, minor, = formula.version.to_s.split(".")
+ alias_name_major = "#{formula.name}@#{major}"
+ alias_name_major_minor = "#{alias_name_major}.#{minor}"
+ alias_name = if last_alias_version.split(".").length == 1
+ alias_name_major
+ else
+ alias_name_major_minor
+ end
+ valid_alias_names = [alias_name_major, alias_name_major_minor]
+
+ valid_versioned_aliases = versioned_aliases & valid_alias_names
+ invalid_versioned_aliases = versioned_aliases - valid_alias_names
+
+ if valid_versioned_aliases.empty?
+ if formula.tap
+ problem <<-EOS.undent
+ Formula has other versions so create a versioned alias:
+ cd #{formula.tap.alias_dir}
+ ln -s #{formula.path.to_s.gsub(formula.tap.path, "..")} #{alias_name}
+ EOS
else
- "#{formula.name}@#{major}.#{minor}"
+ problem "Formula has other versions so create an alias named #{alias_name}."
end
+ end
+
+ unless invalid_versioned_aliases.empty?
problem <<-EOS.undent
- Formula has other versions so create an alias:
- cd #{formula.tap.alias_dir}
- ln -s #{formula.path.to_s.gsub(formula.tap.path, "..")} #{alias_name}
+ Formula has invalid versioned aliases:
+ #{invalid_versioned_aliases.join("\n ")}
EOS
end
end