cscope-index.py revision 3110
110923SN/A#! /usr/bin/python
210923SN/A
310923SN/A# Generate list of files to index with cscope.
410923SN/A
510923SN/A# From the m5 directory, run:
610923SN/A#    util/cscope-find.py > cscope.files
710923SN/A#    cscope -b
810923SN/A
910923SN/Aimport os
1010923SN/A
1110923SN/A# absolute paths to skip
1210923SN/Askipdirs = [ 'src/unittest', 'src/doxygen' ]
1310923SN/A
1410923SN/A# suffixes of files to index
1510923SN/Asuffixes = [ '.cc', '.hh', '.c', '.h' ]
1610923SN/A
1710923SN/Adef oksuffix(f):
1810923SN/A    for s in suffixes:
1910923SN/A        if f.endswith(s):
2010923SN/A            return True
2110923SN/A    return False
2210923SN/A
2310923SN/Afor dirpath,subdirs,files in os.walk('src'):
2410923SN/A    # filter out undesirable subdirectories
2510923SN/A    for i,dir in enumerate(subdirs):
2610923SN/A        if dir == 'SCCS':
2710923SN/A            del subdirs[i]
2810923SN/A            break
2910923SN/A
3010923SN/A    # filter out undesriable absolute paths
3110923SN/A    if dirpath in skipdirs:
3210923SN/A        del subdirs[:]
3310923SN/A        continue
3410923SN/A
3510923SN/A    # find C/C++ sources
3610923SN/A    okfiles = [f for f in files if oksuffix(f)]
3710923SN/A    if okfiles:
3810923SN/A        print '\n'.join([os.path.join(dirpath, f) for f in okfiles])
3910923SN/A