configure-clangd.sh 1.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950
  1. #!/usr/bin/env bash
  2. function usage {
  3. echo "$0 <.clangd file path> [release|debug]"
  4. echo "Update local clangd configuration with the proper"
  5. echo "compilation database according to the selected build type."
  6. }
  7. script_path=$(cd -P -- "$(dirname -- "$0")" && pwd -P)
  8. cd "${script_path}/.." || exit 1
  9. # Check if the user has sed.
  10. if ! which sed >/dev/null 2>&1; then
  11. echo "Error: No sed found. Cannot configure .clangd automatically."
  12. exit 1
  13. fi
  14. # Check if the user specified the right number of parameters.
  15. if [ $# -ne 2 ]; then
  16. usage
  17. exit 1
  18. fi
  19. clangd_file_path=$1
  20. if [ ! -f "$clangd_file_path" ]; then
  21. echo "Error: ${clangd_file_path} is not a regular file."
  22. echo
  23. usage
  24. exit 1
  25. fi
  26. build_type=""
  27. case $2 in
  28. Debug)
  29. build_type="-debug"
  30. ;;
  31. default)
  32. build_type=""
  33. ;;
  34. Sanitizer)
  35. build_type="-sanitizers"
  36. ;;
  37. *)
  38. echo "Invalid build configuration specified: $2"
  39. usage
  40. exit 1
  41. esac
  42. sed -i '' "s/\(^[ ]*CompilationDatabase:\).*$/\1 Build\/ladybird${build_type}/" "$clangd_file_path"