提交 8ed02f83 编写于 作者: C Chinmay Garde 提交者: GitHub

Create compile_commands.json on each GN invocation and add a YCM conf. (#3175)

上级 7e5d6351
# Copyright 2016 The Chromium Authors. All rights reserved.
# Use of this source code is governed by a BSD-style license that can be
# found in the LICENSE file.
import os
import ycm_core
compile_commands_dir = os.path.normpath(os.path.dirname(os.path.abspath(__file__)) + '/../out')
if os.path.exists(compile_commands_dir):
compilation_db = ycm_core.CompilationDatabase(compile_commands_dir)
else:
compilation_db = None
path_flags = [
'--sysroot=',
'-I',
'-iquote',
'-isystem',
]
def MakeFlagAbsolute(working_dir, flag):
# Check if its a flag that contains a path. (an ite, in the path_flags)
for path_flag in path_flags:
if flag.startswith(path_flag):
path_component = flag[len(path_flag):]
return path_flag + os.path.join(working_dir, path_component)
# Check if its a regular flag that does not contain a path. (defines, warnings, etc..)
if flag.startswith('-'):
return flag
# The file path is directly specified. (compiler, input, output, etc..)
return os.path.join(working_dir, flag)
def MakeFlagsAbsolute(working_dir, flags):
if not working_dir:
return list(flags)
updated_flags = []
for flag in flags:
updated_flags.append(MakeFlagAbsolute(working_dir, flag))
return updated_flags
empty_flags = { 'flags' : '' }
def FlagsForFile(filename, **kwargs):
if not compilation_db:
return empty_flags
info = compilation_db.GetCompilationInfoForFile(filename)
if not info:
return empty_flags
return { 'flags' : MakeFlagsAbsolute(info.compiler_working_dir_,
info.compiler_flags_) }
......@@ -163,8 +163,27 @@ def main(argv):
print "gn gen --check in %s" % out_dir
command.append(out_dir)
command.append('--args=%s' % ' '.join(gn_args))
return subprocess.call(command, cwd=SRC_ROOT)
gn_call_result = subprocess.call(command, cwd=SRC_ROOT)
if gn_call_result == 0:
# Generate/Replace the compile commands database in out.
compile_cmd_gen_cmd = [
'%s/buildtools/%s/ninja' % (SRC_ROOT, subdir),
'-C',
out_dir,
'-t',
'compdb',
'cxx',
'cc',
'mm',
]
contents = subprocess.check_output(compile_cmd_gen_cmd, cwd=SRC_ROOT)
compile_commands = open('%s/out/compile_commands.json' % SRC_ROOT, 'w+')
compile_commands.write(contents)
compile_commands.close()
return gn_call_result
if __name__ == '__main__':
sys.exit(main(sys.argv))
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册