|
| 1 | +# |
| 2 | +# File : cscope.py |
| 3 | +# This file is part of RT-Thread RTOS |
| 4 | +# COPYRIGHT (C) 2006 - 2015, RT-Thread Development Team |
| 5 | +# |
| 6 | +# This program is free software; you can redistribute it and/or modify |
| 7 | +# it under the terms of the GNU General Public License as published by |
| 8 | +# the Free Software Foundation; either version 2 of the License, or |
| 9 | +# (at your option) any later version. |
| 10 | +# |
| 11 | +# This program is distributed in the hope that it will be useful, |
| 12 | +# but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 13 | +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 14 | +# GNU General Public License for more details. |
| 15 | +# |
| 16 | +# You should have received a copy of the GNU General Public License along |
| 17 | +# with this program; if not, write to the Free Software Foundation, Inc., |
| 18 | +# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. |
| 19 | +# |
| 20 | +# Change Logs: |
| 21 | +# Date Author Notes |
| 22 | +# 2015-01-20 Bernard Add copyright information |
| 23 | +# |
| 24 | + |
| 25 | +import os |
| 26 | + |
| 27 | +def _get_src(project): |
| 28 | + li = [] |
| 29 | + for group in project: |
| 30 | + for f in group['src']: |
| 31 | + li.append(os.path.normpath(f.rfile().abspath)) |
| 32 | + return li |
| 33 | + |
| 34 | +def _get_header_dir(dirp): |
| 35 | + li = [] |
| 36 | + for root, dirs, files in os.walk(dirp): |
| 37 | + for d in dirs: |
| 38 | + fpath = os.path.join(root, d) |
| 39 | + li.extend(_get_header_dir(fpath)) |
| 40 | + |
| 41 | + for f in files: |
| 42 | + if f[-2:] == '.h': |
| 43 | + fpath = os.path.join(root, f) |
| 44 | + li.append(os.path.normpath(fpath)) |
| 45 | + return li |
| 46 | + |
| 47 | +def _get_header(project): |
| 48 | + li = [] |
| 49 | + for g in project: |
| 50 | + for d in g.get('CPPPATH', []): |
| 51 | + li.extend(_get_header_dir(d)) |
| 52 | + return li |
| 53 | + |
| 54 | +def CscopeDatabase(project): |
| 55 | + files = set(_get_src(project) + _get_header(project)) |
| 56 | + with open('cscope.files', 'w') as db: |
| 57 | + db.write('-k\n-q\n') |
| 58 | + db.write('\n'.join(files)) |
| 59 | + db.flush() # let cscope see the full content |
| 60 | + os.system('cscope -b') |
| 61 | + |
0 commit comments