这是我最终使用的构建器代码。请注意,ctags 命令有一个--tag-relative=yes
选项。
# -*- coding: utf-8 -*-
import SCons.Builder
import SCons.Action
def complain_ctags(target, source, env):
print 'INFORMATION: ctags binary was not found (see above). Tags have not been built.'
def generate(env):
env['CTAGS'] = find_ctags(env)
if env['CTAGS'] != None:
#env['CTAGSCOM'] = 'cd $TARGET.dir; ctags -R .'
env['CTAGSCOM'] = '$CTAGS --tag-relative=yes -f $TARGET $SOURCES'
env['BUILDERS']['ctags'] = SCons.Builder.Builder(action=env['CTAGSCOM'])
else:
env['BUILDERS']['ctags'] = SCons.Builder.Builder(action=env.Action(complain_ctags))
def find_ctags(env):
b=env.WhereIs('ctags')
if b == None:
print 'Searching for ctags: not found. Tags will not be built'
else:
print 'Searching for ctags: ', b
return b
def exists(env):
if find_ctags(env) == None:
return 0
return 1
在我的Sconscript
文件中,我现在可以执行以下操作:
Alias('tags', env.ctags(source=all_python_files, target='tags'))
该tags
文件现在包含标签,其路径相对于标签文件的位置,而不是来自 scons 根目录。