blob: 6f10e09991c4abab89a16b9ffd79cc0c57cc9449 [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
Ravago Jones5127ccc2022-07-31 16:32:45 -07008
Brian Silvermand4aea1d2015-12-09 00:24:18 -05009def _get_cpp_command(cpp_compile_info):
Ravago Jones5127ccc2022-07-31 16:32:45 -070010 compiler = cpp_compile_info.tool
11 options = ' '.join(cpp_compile_info.compiler_option)
12 source = cpp_compile_info.source_file
13 output = cpp_compile_info.output_file
14 return '%s %s -c %s -o %s' % (compiler, options, source, output), source
15
Brian Silvermand4aea1d2015-12-09 00:24:18 -050016
17def main(argv):
Ravago Jones5127ccc2022-07-31 16:32:45 -070018 action = extra_actions_base_pb2.ExtraActionInfo()
19 with open(argv[1], 'rb') as f:
20 action.MergeFromString(f.read())
21 command, source_file = _get_cpp_command(action.Extensions[
22 extra_actions_base_pb2.CppCompileInfo.cpp_compile_info])
23 with open(argv[2], 'w') as f:
24 f.write(command)
25 f.write('\0')
26 f.write(source_file)
27
Brian Silvermand4aea1d2015-12-09 00:24:18 -050028
29if __name__ == '__main__':
Ravago Jones5127ccc2022-07-31 16:32:45 -070030 sys.exit(main(sys.argv))