cscope-index.py revision 3703
112882Sspwilson2@wisc.edu#! /usr/bin/python
212882Sspwilson2@wisc.edu# Copyright (c) 2006 The Regents of The University of Michigan
312882Sspwilson2@wisc.edu# All rights reserved.
412882Sspwilson2@wisc.edu#
512882Sspwilson2@wisc.edu# Redistribution and use in source and binary forms, with or without
612882Sspwilson2@wisc.edu# modification, are permitted provided that the following conditions are
712882Sspwilson2@wisc.edu# met: redistributions of source code must retain the above copyright
812882Sspwilson2@wisc.edu# notice, this list of conditions and the following disclaimer;
912882Sspwilson2@wisc.edu# redistributions in binary form must reproduce the above copyright
1012882Sspwilson2@wisc.edu# notice, this list of conditions and the following disclaimer in the
1112882Sspwilson2@wisc.edu# documentation and/or other materials provided with the distribution;
1212882Sspwilson2@wisc.edu# neither the name of the copyright holders nor the names of its
1312882Sspwilson2@wisc.edu# contributors may be used to endorse or promote products derived from
1412882Sspwilson2@wisc.edu# this software without specific prior written permission.
1512882Sspwilson2@wisc.edu#
1612882Sspwilson2@wisc.edu# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
1712882Sspwilson2@wisc.edu# "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
1812882Sspwilson2@wisc.edu# LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
1912882Sspwilson2@wisc.edu# A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
2012882Sspwilson2@wisc.edu# OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
2112882Sspwilson2@wisc.edu# SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
2212882Sspwilson2@wisc.edu# LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
2312882Sspwilson2@wisc.edu# DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
2412882Sspwilson2@wisc.edu# THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
2512882Sspwilson2@wisc.edu# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
2612882Sspwilson2@wisc.edu# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
2712882Sspwilson2@wisc.edu#
2812882Sspwilson2@wisc.edu# Authors: Steve Reinhardt
2912882Sspwilson2@wisc.edu
3012882Sspwilson2@wisc.edu# Generate list of files to index with cscope and then generate cscope index.
3112882Sspwilson2@wisc.edu
3212882Sspwilson2@wisc.edu# Should be run from root of m5 tree (i.e. as 'util/cscope-index.py').
3312882Sspwilson2@wisc.edu
3412882Sspwilson2@wisc.eduimport os
3512882Sspwilson2@wisc.edu
3612882Sspwilson2@wisc.edu# absolute paths to skip
3712882Sspwilson2@wisc.eduskipdirs = [ 'src/unittest', 'src/doxygen' ]
3812882Sspwilson2@wisc.edu
3912882Sspwilson2@wisc.edu# suffixes of files to index
4012882Sspwilson2@wisc.edusuffixes = [ '.cc', '.hh', '.c', '.h' ]
4112882Sspwilson2@wisc.edu
4212882Sspwilson2@wisc.edudef oksuffix(f):
4312882Sspwilson2@wisc.edu    for s in suffixes:
4412882Sspwilson2@wisc.edu        if f.endswith(s):
4512882Sspwilson2@wisc.edu            return True
4612882Sspwilson2@wisc.edu    return False
4712882Sspwilson2@wisc.edu
4812882Sspwilson2@wisc.edufile_list = file('cscope.files', 'w')
4912882Sspwilson2@wisc.edu
5012882Sspwilson2@wisc.edufor dirpath,subdirs,files in os.walk('src'):
5112882Sspwilson2@wisc.edu    # filter out undesirable subdirectories
5212882Sspwilson2@wisc.edu    for i,dir in enumerate(subdirs):
5312882Sspwilson2@wisc.edu        if dir == 'SCCS':
5412882Sspwilson2@wisc.edu            del subdirs[i]
5512882Sspwilson2@wisc.edu            break
5612882Sspwilson2@wisc.edu
5712882Sspwilson2@wisc.edu    # filter out undesirable absolute paths
5812882Sspwilson2@wisc.edu    if dirpath in skipdirs:
5912882Sspwilson2@wisc.edu        del subdirs[:]
6012882Sspwilson2@wisc.edu        continue
6112882Sspwilson2@wisc.edu
6212882Sspwilson2@wisc.edu    # find C/C++ sources
6312882Sspwilson2@wisc.edu    okfiles = [f for f in files if oksuffix(f)]
6412882Sspwilson2@wisc.edu    if okfiles:
6512882Sspwilson2@wisc.edu        print >> file_list, \
6612882Sspwilson2@wisc.edu              '\n'.join([os.path.join(dirpath, f) for f in okfiles])
6712882Sspwilson2@wisc.edu
6812882Sspwilson2@wisc.edufile_list.close()
6912882Sspwilson2@wisc.edu
7012882Sspwilson2@wisc.edu# run cscope to generate index
7112882Sspwilson2@wisc.eduos.system("cscope -b")
7212882Sspwilson2@wisc.edu