diff options
author | MyungJoo Ham <myungjoo.ham@samsung.com> | 2017-03-16 14:31:47 +0900 |
---|---|---|
committer | MyungJoo Ham <myungjoo.ham@samsung.com> | 2017-03-16 14:31:47 +0900 |
commit | 13c82765cf45d985a3caf89177d03a8c49cef1bc (patch) | |
tree | 6a41307b3ea6ec22228db141ed4e5868b5e052ab | |
parent | a02ac42261875a82c201a413e059527c85def4f7 (diff) | |
download | building-blocks-13c82765cf45d985a3caf89177d03a8c49cef1bc.tar.gz building-blocks-13c82765cf45d985a3caf89177d03a8c49cef1bc.tar.bz2 building-blocks-13c82765cf45d985a3caf89177d03a8c49cef1bc.zip |
RULE: added rules and a prototype rule checker.
Change-Id: I401ff877697370699b2449a7b84d88cb87559df7
Signed-off-by: MyungJoo Ham <myungjoo.ham@samsung.com>
-rw-r--r-- | RULES | 14 | ||||
-rwxr-xr-x | rule_checker.py | 89 |
2 files changed, 103 insertions, 0 deletions
@@ -77,3 +77,17 @@ 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 index 0000000..75d909c --- /dev/null +++ b/rule_checker.py @@ -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) + |