blob: b41f2fcf1c01bbcb907394cd2c21a1bb48c65ca6 [file] [log] [blame]
Brian Silvermand4aea1d2015-12-09 00:24:18 -05001# This is the implementation of a Bazel extra_action which genenerates
2# _compile_command files for generate_compile_commands.py to consume.
3
4import sys
5
6import third_party.bazel.protos.extra_actions_base_pb2 as extra_actions_base_pb2
7
8def _get_cpp_command(cpp_compile_info):
9 compiler = cpp_compile_info.tool
10 options = ' '.join(cpp_compile_info.compiler_option)
11 source = cpp_compile_info.source_file
12 output = cpp_compile_info.output_file
13 return '%s %s -c %s -o %s' % (compiler, options, source, output), source
14
15def main(argv):
16 action = extra_actions_base_pb2.ExtraActionInfo()
17 with open(argv[1], 'rb') as f:
18 action.MergeFromString(f.read())
19 command, source_file = _get_cpp_command(
20 action.Extensions[extra_actions_base_pb2.CppCompileInfo.cpp_compile_info])
21 with open(argv[2], 'w') as f:
22 f.write(command)
23 f.write('\0')
24 f.write(source_file)
25
26if __name__ == '__main__':
27 sys.exit(main(sys.argv))