3 # This script is for checking that patches don't introduce non-portable symbols
4 # into the Lustre/LNET/libcfs code.
7 # 1. (Required) Filename (including path) of the diff file to be checked
8 # 2. (Optional) path to the nn-final-symbol-list.txt file (By default, this
9 # script looks for nn-final-symbol-list.txt in the current working
13 # The output of this script is either PASS or FAIL (with WARNINGS).
14 # FAIL means that there may have been symbols found that are not supposed
15 # to be used. This requires the person running the script to look into the
16 # WARNINGS that are in the output to determine if there is a problem.
18 # Author: lisa.week@sun.com
27 # Setup command line options for nn-check.py
28 from optparse import OptionParser
29 usage = "%prog DIFF-FILE [options]"
30 parser = OptionParser(usage)
31 parser.add_option("-s", "--symb", action="store", dest="symb_pathname",
32 help="(Optional) PATH to nn-final-symbol-list.txt file",
35 (options, args) = parser.parse_args()
37 # Check if we have the minimum number of arguments supplied.
39 parser.error("Incorrect number of arguments, see nn-check -h for help.")
41 # Check if we were passed a path to the nn-final-symbol-list.txt file
42 if options.symb_pathname:
43 symb_file = os.path.join(options.symb_pathname,
44 'nn-final-symbol-list.txt')
46 symb_file = 'nn-final-symbol-list.txt'
52 # Function Definitions
53 def search_symbol(line, linenum):
56 for key, val in symbol_dict.items():
57 regex_match = val.search(line)
60 print_symbol = regex_match.group(0)
61 print 'warning: Found %s at line %d:' \
62 % (print_symbol, linenum)
63 print '%s' % line.rstrip()
66 # Open the nn-final-symbol-list.txt file and pull in the symbols to check into
67 # a dictionary object.
69 f = fileinput.input(symb_file)
71 print 'nn-check.py: error: %s not found.' % symb_file
72 print 'Is nn-final-symbol-list.txt is in your current working directory'
73 print 'or have you have passed nn-check.py a valid path to the file?'
78 stripped_symbol = line.rstrip()
79 symbol_dict[stripped_symbol] = re.compile(stripped_symbol)
81 # Close nn-final-symbol-list.txt
84 # Open the diff file passed to the script and parse it for the symbols from
85 # nn-final-symbol-list.txt
87 f = fileinput.input(sys.argv[1])
89 print 'nn-check.py: error: %s not found.' % sys.argv[1]
90 print 'Check the path provided for the diff file.'
93 # The main portion of the script
94 print '==================================================='
95 print '%s: starting nn-check' % sys.argv[1]
96 print '==================================================='
98 index = re.compile(r'^\+\+\+ [b/]*([^ \t]*)')
99 plus = re.compile(r'^\+')
101 # Check for the "diff --cc " delimiter in order to grab the file name.
102 index_match = index.match(line)
105 # Store the file name
106 filename=index_match.group(1)
107 print '%s: ' % filename
109 # Check if the line starts with a "+" character.
110 plus_match = plus.match(line)
112 # The line starts with a "+" character. Look for
113 # non-portable symbols
114 search_symbol(line, f.lineno())
118 # Close the diff file
121 # Finish up and print the results of the script (i.e. total number of
123 if bad_symbol_cnt != 0:
124 print '=============================='
125 print 'Finished nn-check status: FAIL'
126 print '=============================='
127 print 'Found %d potential problem(s). See "WARNINGS" from script output and refer to https://wikis.lustre.org/intra/index.php/Lustre_Name_Normalization for the complete set of rules to make sure you have not used a non-portable symbol.' % bad_symbol_cnt
129 print '=============================='
130 print 'Finished nn-check status: PASS'
131 print '=============================='