cscope-index.py revision 12043
15647Sgblack@eecs.umich.edu#! /usr/bin/python
25647Sgblack@eecs.umich.edu# Copyright (c) 2006 The Regents of The University of Michigan
35647Sgblack@eecs.umich.edu# All rights reserved.
45647Sgblack@eecs.umich.edu#
55647Sgblack@eecs.umich.edu# Redistribution and use in source and binary forms, with or without
65647Sgblack@eecs.umich.edu# modification, are permitted provided that the following conditions are
75647Sgblack@eecs.umich.edu# met: redistributions of source code must retain the above copyright
85647Sgblack@eecs.umich.edu# notice, this list of conditions and the following disclaimer;
95647Sgblack@eecs.umich.edu# redistributions in binary form must reproduce the above copyright
105647Sgblack@eecs.umich.edu# notice, this list of conditions and the following disclaimer in the
115647Sgblack@eecs.umich.edu# documentation and/or other materials provided with the distribution;
125647Sgblack@eecs.umich.edu# neither the name of the copyright holders nor the names of its
135647Sgblack@eecs.umich.edu# contributors may be used to endorse or promote products derived from
145647Sgblack@eecs.umich.edu# this software without specific prior written permission.
155647Sgblack@eecs.umich.edu#
165647Sgblack@eecs.umich.edu# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
175647Sgblack@eecs.umich.edu# "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
185647Sgblack@eecs.umich.edu# LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
195647Sgblack@eecs.umich.edu# A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
205647Sgblack@eecs.umich.edu# OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
215647Sgblack@eecs.umich.edu# SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
225647Sgblack@eecs.umich.edu# LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
235647Sgblack@eecs.umich.edu# DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
245647Sgblack@eecs.umich.edu# THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
255647Sgblack@eecs.umich.edu# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
265647Sgblack@eecs.umich.edu# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
275647Sgblack@eecs.umich.edu#
285647Sgblack@eecs.umich.edu# Authors: Steve Reinhardt
295647Sgblack@eecs.umich.edu
305647Sgblack@eecs.umich.edu# Generate list of files to index with cscope and then generate cscope index.
315647Sgblack@eecs.umich.edu
325647Sgblack@eecs.umich.edu# Should be run from root of m5 tree (i.e. as 'util/cscope-index.py').
335647Sgblack@eecs.umich.edu
345647Sgblack@eecs.umich.eduimport os
355647Sgblack@eecs.umich.edu
365647Sgblack@eecs.umich.edu# absolute paths to skip
375647Sgblack@eecs.umich.eduskipdirs = [ 'src/unittest', 'src/doxygen' ]
385647Sgblack@eecs.umich.edu
395647Sgblack@eecs.umich.edu# suffixes of files to index
405647Sgblack@eecs.umich.edusuffixes = [ '.cc', '.hh', '.c', '.h' ]
415647Sgblack@eecs.umich.edu
425647Sgblack@eecs.umich.edudef oksuffix(f):
435647Sgblack@eecs.umich.edu    for s in suffixes:
445647Sgblack@eecs.umich.edu        if f.endswith(s):
455647Sgblack@eecs.umich.edu            return True
465647Sgblack@eecs.umich.edu    return False
475647Sgblack@eecs.umich.edu
485647Sgblack@eecs.umich.edufile_list = file('cscope.files', 'w')
495647Sgblack@eecs.umich.educwd = os.getcwd()
505647Sgblack@eecs.umich.edu
515647Sgblack@eecs.umich.edufor dirpath,subdirs,files in os.walk(os.path.join(cwd, 'src')):
525647Sgblack@eecs.umich.edu    # filter out undesirable subdirectories
535647Sgblack@eecs.umich.edu    for i,dir in enumerate(subdirs):
545647Sgblack@eecs.umich.edu        if dir == 'SCCS':
555647Sgblack@eecs.umich.edu            del subdirs[i]
565647Sgblack@eecs.umich.edu            break
575647Sgblack@eecs.umich.edu
585648Sgblack@eecs.umich.edu    # filter out undesirable absolute paths
595647Sgblack@eecs.umich.edu    if dirpath in skipdirs:
605654Sgblack@eecs.umich.edu        del subdirs[:]
615647Sgblack@eecs.umich.edu        continue
625654Sgblack@eecs.umich.edu
635647Sgblack@eecs.umich.edu    # find C/C++ sources
645648Sgblack@eecs.umich.edu    okfiles = [f for f in files if oksuffix(f)]
655648Sgblack@eecs.umich.edu    if okfiles:
665647Sgblack@eecs.umich.edu        print >> file_list, \
675647Sgblack@eecs.umich.edu              '\n'.join([os.path.join(dirpath, f) for f in okfiles])
685647Sgblack@eecs.umich.edu
695647Sgblack@eecs.umich.edufile_list.close()
705647Sgblack@eecs.umich.edu
715647Sgblack@eecs.umich.edu# run cscope to generate index
725647Sgblack@eecs.umich.eduos.system("cscope -b")
735647Sgblack@eecs.umich.edu