Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/bin/bash
- THIS_PATH=$(dirname $0)
- if [ "$1" = "--update-root" ]; then
- update_root=true
- shift
- fi
- if [ -z "$*" ]; then
- targets=$THIS_PATH/_BUILD/*/compile_commands.json $THIS_PATH/*/compile_commands.json
- else
- for i in $*; do
- targets+="$THIS_PATH/_BUILD/$i $THIS_PATH/$i "
- done
- fi
- function count_files()
- {
- grep "\"file\"" -c $1 2> /dev/null || echo 0
- }
- function print_stats()
- {
- echo "$1 has $(count_files $1) files"
- }
- function update_commands()
- {
- path=$1
- shift
- extra_paths=$*
- print_stats $path/compile_commands.json
- for p in $path $extra_paths; do
- update_paths+="-p $p "
- done
- compdb $update_paths list -1 > $path/compile_commands_full.json
- compdb_ret=$?
- if [ $compdb_ret == 0 ] && [ -f $path/compile_commands_full.json ]; then
- if [ $(count_files $path/compile_commands_full.json) -gt 0 ]; then
- mv -v $path/compile_commands_full.json $path/compile_commands.json
- for p in $path $extra_paths; do
- touch $p/compile_commands_headers.stamp
- done
- else
- rm -f $path/compile_commands_full.json
- rm -f $path/compile_commands_headers.stamp
- fi
- fi
- print_stats $path/compile_commands.json
- exit $compdb_ret
- }
- subpaths=""
- for i in $targets; do
- if [ -d $i ]; then
- path=$i
- else
- path=$(dirname $i)
- fi
- if [ ! -f $path/compile_commands.json ]; then
- continue
- fi
- if [ -z "$update_root" ]; then
- update_commands $path
- echo ""
- fi
- subpaths+="$path "
- done
- if [ -z "$subpaths" ]; then
- echo "No path containing a 'compile_commands.json' found"
- exit 1;
- fi
- if [ -n "$update_root" ]; then
- echo "===== UPDATING MAIN FILE ====="
- if [ ! -f "compile_commands.json" ]; then
- echo "Missing compile_commands.json, creating a new one..."
- echo "[]" > $THIS_PATH/compile_commands.json
- fi
- exec update_commands $THIS_PATH $subpaths
- fi
Advertisement
Add Comment
Please, Sign In to add comment