source: issm/trunk-jpl/externalpackages/petsc-dev/src/bin/portabilitycheck.py@ 11896

Last change on this file since 11896 was 11896, checked in by habbalf, 13 years ago

petsc-dev : Petsc development code in external packages. Mercurial updates

  • Property svn:executable set to *
File size: 1.4 KB
Line 
1#!/usr/bin/env python
2
3import os
4import sys
5import popen2
6import re
7
8def portabilityCheck(filename,includes):
9
10 if filename.endswith('.o'):
11 # Check for bad symbols in file
12 bad = re.compile(r'creat|unlink|fprint|open|socket|pipe|fork|exec|kill|signal|longjmp|system|fscanf|_f_open|_system_|_do_l_out')
13 pipe = os.popen("nm " + filename)
14 for line in pipe.readlines():
15 if bad.search(line):
16 print 'For portability avoid direct read, write, or system commands in file ' + filename
17 print 'Function: '+ line
18 os.unlink(filename)
19 return 1
20 return 0
21
22 else:
23 # Check for use of system includes
24 include = re.compile(r"""#\s*include\s*('|"|<)""")
25 ok = re.compile(r"""#\s*include\s*('|"|<)petsc""")
26 okf = re.compile(r"""#\s*include\s*('|"|<)include/finclude/petsc""")
27 file = open(filename)
28 for line in file.readlines():
29 if include.search(line) and not ok.search(line) and not okf.search(line):
30 found = 0
31 for l in includes:
32 oki = re.compile(r"""#\s*include\s*('|"|<)"""+l)
33 if oki.search(line):
34 if portabilityCheck(l,sys.argv[2:]): return 1
35 found = 1
36 if not found:
37 print 'For portability avoid direct use of generic system #include files in ' + filename
38 print 'Line: '+ line
39 return 1
40 file.close()
41 return 0
42
43if __name__=="__main__":
44 sys.exit(portabilityCheck(sys.argv[1],sys.argv[2:]))
45
46
Note: See TracBrowser for help on using the repository browser.