| 1 |
# Checks that must be done over ebuilds
|
| 2 |
require("set")
|
| 3 |
|
| 4 |
class BaseCheck
|
| 5 |
def init(log, msg)
|
| 6 |
@log = File.new(log, "w")
|
| 7 |
@msg = msg
|
| 8 |
|
| 9 |
@herds = Set.new
|
| 10 |
@maintainers = Set.new
|
| 11 |
end
|
| 12 |
|
| 13 |
# special_msg is used for custom messages for more complex checks
|
| 14 |
def positive(ebuild, pkg, special_msg = nil)
|
| 15 |
special_msg = @msg unless special_msg
|
| 16 |
str = "#{ebuild}: #{special_msg}"
|
| 17 |
str << " [" unless pkg.herds.empty? and pkg.maintainers.empty?
|
| 18 |
str << pkg.herds.join(", ")
|
| 19 |
str << " | " unless pkg.herds.empty? or pkg.maintainers.empty?
|
| 20 |
str << pkg.maintainers.join(", ")
|
| 21 |
str << "]" unless pkg.herds.empty? and pkg.maintainers.empty?
|
| 22 |
|
| 23 |
@log.puts str
|
| 24 |
puts str
|
| 25 |
|
| 26 |
@herds.merge(pkg.herds)
|
| 27 |
@maintainers.merge(pkg.maintainers)
|
| 28 |
end
|
| 29 |
|
| 30 |
def summarize()
|
| 31 |
@log.puts "Affected herds: #{@herds.to_a.join(", ")}"
|
| 32 |
@log.puts "Affected devs: #{@maintainers.to_a.join(", ")}"
|
| 33 |
end
|
| 34 |
end
|
| 35 |
|
| 36 |
class Check_regexp < BaseCheck
|
| 37 |
def initialize(log, re, msg) # Regular expression check (true/false)
|
| 38 |
@re = re # Regular expression to check
|
| 39 |
init(log, msg)
|
| 40 |
end
|
| 41 |
|
| 42 |
def check(pkg, ebuild, ebcontent)
|
| 43 |
positive(ebuild, pkg, @msg.sub("<PARAM>", $1 ? $1 : "")) if ebcontent =~ @re
|
| 44 |
end
|
| 45 |
end
|
| 46 |
|
| 47 |
##
|
| 48 |
# Check for options on a commandline
|
| 49 |
#
|
| 50 |
# This class allows to check for given (short) commandline options
|
| 51 |
# for example -a or -d in cp commandlines.
|
| 52 |
#
|
| 53 |
# The options paramter is an array of options to check against.
|
| 54 |
# In msg string, <PARAM> is replaced with the parameter found.
|
| 55 |
class Check_options < BaseCheck
|
| 56 |
def initialize(log, command, options, msg)
|
| 57 |
@command = command
|
| 58 |
@options = options
|
| 59 |
init(log, msg)
|
| 60 |
end
|
| 61 |
|
| 62 |
def check(pkg, ebuild, ebcontent)
|
| 63 |
ebcontent.split("\n").each { |line|
|
| 64 |
if line =~ /\s#{@command}\s(.*)$/ then
|
| 65 |
$1.split(/\s+/).each { |tok|
|
| 66 |
if tok =~ /^-([a-z0-9A-Z]+)/ then
|
| 67 |
opts = $1
|
| 68 |
@options.each { |opt|
|
| 69 |
positive(ebuild, pkg, @msg.sub("<PARAM>", opt)) if opts =~ /#{opt}/
|
| 70 |
}
|
| 71 |
end
|
| 72 |
}
|
| 73 |
end
|
| 74 |
}
|
| 75 |
end
|
| 76 |
end
|
| 77 |
|
| 78 |
##
|
| 79 |
# Check for the use of a function without a given eclass
|
| 80 |
class Check_missingfunction < BaseCheck
|
| 81 |
def initialize(log, function, eclass, msg)
|
| 82 |
@function = function
|
| 83 |
@eclass = eclass
|
| 84 |
init(log, msg)
|
| 85 |
end
|
| 86 |
|
| 87 |
def check(pkg, ebuild, ebcontent)
|
| 88 |
positive(ebuild, pkg) if ebcontent =~ /\s#{@function}\s/ and not ebcontent =~ /^[^#]*inherit.*\s#{@eclass}\s/
|
| 89 |
end
|
| 90 |
end
|
| 91 |
|
| 92 |
## Kate modeline: leave at the end
|
| 93 |
# kate: indent-width 2; replace-trailing-space-save 1; space-indent 1; backspace-indents 1;
|