# download these 2 scipts into the root.
# https://github.com/vincent-picaud/Bazel_and_CompileCommands
# then, run ./generate_compile_commands_json.py once

# the script should be executed from the driving root, example:
# desktop:~/driving$ experimental/viktor/static_analysis/pvs_studio/generate.pvs.sh

execute() {
  TARGET=$1
  rm compile_commands.json
  EXEC_LOCATION='test/pvs-'$(date --rfc-3339=seconds | sed 's/[-: +]/-/g')
  mkdir $EXEC_LOCATION
  bazel clean
  bazel build $TARGET &> $EXEC_LOCATION/1_bazel_build.log
  ./create_compile_commands.sh $TARGET &> $EXEC_LOCATION/2_create_compile_commands.log
  pvs-studio-analyzer analyze -o $EXEC_LOCATION/pvs.log -j2 &> $EXEC_LOCATION/3_pvs_studio_analyzer.log
  mv compile_commands.json EXEC_LOCATION/
}

# execute <target>
execute //log_tests/ci_test:generate_offline_logs_test
execute //vehicle:l3_deploy_package