Brian Silverman | d4aea1d | 2015-12-09 00:24:18 -0500 | [diff] [blame] | 1 | # This is the implementation of a Bazel extra_action which genenerates |
| 2 | # _compile_command files for generate_compile_commands.py to consume. |
| 3 | |
| 4 | import sys |
| 5 | |
| 6 | import third_party.bazel.protos.extra_actions_base_pb2 as extra_actions_base_pb2 |
| 7 | |
Ravago Jones | 5127ccc | 2022-07-31 16:32:45 -0700 | [diff] [blame^] | 8 | |
Brian Silverman | d4aea1d | 2015-12-09 00:24:18 -0500 | [diff] [blame] | 9 | def _get_cpp_command(cpp_compile_info): |
Ravago Jones | 5127ccc | 2022-07-31 16:32:45 -0700 | [diff] [blame^] | 10 | 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 Silverman | d4aea1d | 2015-12-09 00:24:18 -0500 | [diff] [blame] | 16 | |
| 17 | def main(argv): |
Ravago Jones | 5127ccc | 2022-07-31 16:32:45 -0700 | [diff] [blame^] | 18 | 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 Silverman | d4aea1d | 2015-12-09 00:24:18 -0500 | [diff] [blame] | 28 | |
| 29 | if __name__ == '__main__': |
Ravago Jones | 5127ccc | 2022-07-31 16:32:45 -0700 | [diff] [blame^] | 30 | sys.exit(main(sys.argv)) |