#!/bin/bash # Generates a compile_commands.json file at $(bazel info execution_root) for # your Clang tooling needs. set -e bazel build \ --experimental_action_listener=//kythe/cxx/tools/generate_compile_commands:extract_json \ --noshow_progress \ --noshow_loading_progress \ $[bazel query 'kind(cc_.*, //...)] > /dev/null pushd $[bazel info execution_root] > /dev/null echo "[" > compile_commands.json find . -name '*.compile_command.json' -exec bash -c 'cat {} && echo ,' ';' >> compile_commands.json sed -i '$s/,$//' compile_commands.json echo "]" >> compile_commands.json popd > /dev/null (CommandList children: [ (C {(set)} {(-e)}) (SimpleCommand words: [ {(bazel)} {(build)} {(--experimental_action_listener) (Lit_Other "=") (//kythe/cxx/tools/generate_compile_commands) (Lit_Other ":") (extract_json) } {(--noshow_progress)} {(--noshow_loading_progress)} { (CommandSubPart command_list: (CommandList children: [(C {(bazel)} {(query)} {(SQ <"kind(cc_.*, //...)">)})] ) left_token: spids: [38 46] ) } ] redirects: [(Redir op_id:Redir_Great fd:-1 arg_word:{(/dev/null)} spids:[48])] ) (SimpleCommand words: [ {(pushd)} { (CommandSubPart command_list: (CommandList children:[(C {(bazel)} {(info)} {(execution_root)})]) left_token: spids: [55 61] ) } ] redirects: [(Redir op_id:Redir_Great fd:-1 arg_word:{(/dev/null)} spids:[63])] ) (SimpleCommand words: [{(echo)} {(DQ ("["))}] redirects: [(Redir op_id:Redir_Great fd:-1 arg_word:{(compile_commands.json)} spids:[73])] ) (SimpleCommand words: [ {(find)} {(.)} {(-name)} {(SQ <"*.compile_command.json">)} {(-exec)} {(bash)} {(-c)} {(SQ <"cat {} && echo ,">)} {(EscapedLiteralPart token:)} ] redirects: [(Redir op_id:Redir_DGreat fd:-1 arg_word:{(compile_commands.json)} spids:[99])] ) (C {(sed)} {(-i)} {(SQ <"$s/,$//">)} {(compile_commands.json)}) (SimpleCommand words: [{(echo)} {(DQ ("]"))}] redirects: [(Redir op_id:Redir_DGreat fd:-1 arg_word:{(compile_commands.json)} spids:[119])] ) (SimpleCommand words: [{(popd)}] redirects: [(Redir op_id:Redir_Great fd:-1 arg_word:{(/dev/null)} spids:[125])] ) ] )