2 # License: Apache version 2
3 # (c) 2017 MyungJoo Ham <myungjoo.ham@samsung.com>
5 #############################################################
6 # Building Block Rule Checker #
7 #############################################################
8 # This does not check all rules of "RULES"
9 # This is a prototype with a lot of work in progress
13 from __future__ import print_function
20 def ruleCheckInc(file):
25 f = open("packaging/"+file, 'r')
28 print("WARNING: cannot find packaging/"+file)
32 if re.search('^\s*BuildRequires', line, re.IGNORECASE):
34 print("ERROR: RULE 5.1 .inc file cannot have BuildRequires tags")
37 # Prevent: https://github.com/rpm-software-management/rpm/issues/158
38 if re.search('^#.*[^%]%[^%]', line) and not re.search('^#!', line):
40 print("ERROR: unless it is shebang, you must not have rpm macro in a # comment. They are expanded and multiline macro will do unexpected effects.")
44 if re.search('^\s*Recommends', line, re.IGNORECASE) or \
45 re.search('^\s*Provides', line, re.IGNORECASE) or \
46 re.search('^\s*Enhances', line, re.IGNORECASE) or \
47 re.search('^\s*Supplements', line, re.IGNORECASE):
49 print("ERROR: RULE 5.2 .inc file cannot have unsupported relations")
52 if re.search('^\s*%package\s*-n', line, re.IGNORECASE):
54 print("ERROR: RULE 1.1 to ensure 1.1, do not use -n option in package name")
56 # Implicit / General Rule
57 if re.search('^\s*%package\s', line, re.IGNORECASE) and not re.search('^\s*%package\s', line):
59 print('ERROR: (General) Please use %package, not '+re.search('^%package'))
62 if re.search('^\s*%package', line) and not re.search('^\s*%package\s*(root)|(sub1)|(sub2)', line):
64 print("ERROR: RULE 1.3 the send prefix should be root, sub1, or sub2.")
72 return (error, warning)
76 dirs = os.listdir("packaging/")
80 # iterate in the list of ./packaging/
82 if re.search('\.inc', file):
83 result = ruleCheckInc(file)
87 print('Error: '+str(error))
88 print('Warning: '+str(warning))