RULE: added rules and a prototype rule checker. 30/119230/1
authorMyungJoo Ham <myungjoo.ham@samsung.com>
Thu, 16 Mar 2017 05:31:47 +0000 (14:31 +0900)
committerMyungJoo Ham <myungjoo.ham@samsung.com>
Thu, 16 Mar 2017 05:31:47 +0000 (14:31 +0900)
Change-Id: I401ff877697370699b2449a7b84d88cb87559df7
Signed-off-by: MyungJoo Ham <myungjoo.ham@samsung.com>
RULES
rule_checker.py [new file with mode: 0755]

diff --git a/RULES b/RULES
index 6f5424b..b042e22 100644 (file)
--- a/RULES
+++ b/RULES
 4-4. To comitters: add proper maintainers as the reviewers in gerrit.
 
 
+
+
+
+===========================================================================
+               5. Other Coding Rules
+===========================================================================
+
+5-1. A domain cannot add "BuildRequires"
+       Global relations cannot be added by an individual domain.
+
+5.2. A domain cannot add "Recommends", "Provides", "Enhances", "Supplements"
+       We do not have any semantics for building blocks with such relations.
+       When we have definitions for such semantics and have them implemented in
+       TIC, we can allow then.
diff --git a/rule_checker.py b/rule_checker.py
new file mode 100755 (executable)
index 0000000..75d909c
--- /dev/null
@@ -0,0 +1,89 @@
+#!/usr/bin/env python
+# License: Apache version 2
+# (c) 2017 MyungJoo Ham <myungjoo.ham@samsung.com>
+#
+#############################################################
+# Building Block Rule Checker                               #
+#############################################################
+# This does not check all rules of "RULES"
+# This is a prototype with a lot of work in progress
+
+
+
+from __future__ import print_function
+import re
+import os
+import os.path
+import sys
+
+
+def ruleCheckInc(file):
+    error = 0
+    warning = 0
+
+    try:
+        f = open("packaging/"+file, 'r')
+    except:
+        warning += 1
+       print("WARNING: cannot find packaging/"+file)
+        return (0, 1)
+    for line in f:
+        # RULE 5.1
+       if re.search('^\s*BuildRequires', line, re.IGNORECASE):
+           error += 1
+           print("ERROR: RULE 5.1 .inc file cannot have BuildRequires tags")
+           continue
+
+        # Prevent: https://github.com/rpm-software-management/rpm/issues/158
+       if re.search('^#.*[^%]%[^%]', line) and !re.search('^#!', line):
+           error += 1
+           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.")
+           continue
+
+        # RULE 5.2
+       if re.search('^\s*Recommends', line, re.IGNORECASE) or
+           re.search('^\s*Provides', line, re.IGNORECASE) or
+           re.search('^\s*Enhances', line, re.IGNORECASE) or
+           re.search('^\s*Supplements', line, re.IGNORECASE):
+           error += 1
+           print("ERROR: RULE 5.2 .inc file cannot have unsupported relations")
+
+       # RULE 1-1
+       if re.search('^\s*%package\s*-n', line, re.IGNORECASE):
+           error += 1
+           print("ERROR: RULE 1.1 to ensure 1.1, do not use -n option in package name")
+
+       # RULE 1-3
+       if !re.search('^\s*%package\s*(root)|(sub1)|(sub2)'):
+           error +=1
+           print("ERROR: RULE 1.3 the send prefix should be root, sub1, or sub2")
+
+           
+
+    f.close()
+    
+
+
+    return (error, warning)
+
+
+def main():
+    dirs = os.listdir("packaging/")
+    error = 0
+    warning = 0
+
+    # iterate in the list of ./packaging/
+    for file in dirs:
+        if re.search('\.inc', file):
+           result = ruleCheckInc(file)
+           error += result[0]
+           warning += result[1]
+
+    print('Error: '+error)
+    print('Warning: '+warning)
+
+    return error
+
+retval = main()
+sys.exit(retval)
+