mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2024-11-21 23:20:20 +00:00
Meta: Script to configure clangd according to build type
Add a simple shell script to update the local clangd configuration according to the type of build selected by the user. Include documentation on where the script might be useful when building under different configurations.
This commit is contained in:
parent
d6af5bf5eb
commit
4f4fdce62a
Notes:
github-actions[bot]
2024-08-06 05:44:57 +00:00
Author: https://github.com/hawkinsw 🔰 Commit: https://github.com/LadybirdBrowser/ladybird/commit/4f4fdce62ad Pull-request: https://github.com/LadybirdBrowser/ladybird/pull/855 Reviewed-by: https://github.com/ADKaster
2 changed files with 63 additions and 0 deletions
|
@ -67,3 +67,16 @@ Some OS distributions don't ship bleeding-edge clang-format binaries. Below are
|
||||||
|
|
||||||
1) If you have a Debian-based (apt-based) distribution, use the [LLVM apt repositories](https://apt.llvm.org) to install the latest release of clang-format.
|
1) If you have a Debian-based (apt-based) distribution, use the [LLVM apt repositories](https://apt.llvm.org) to install the latest release of clang-format.
|
||||||
2) Compile LLVM from source as described in the LLVM documentation [here](https://llvm.org/docs/GettingStarted.html#compiling-the-llvm-suite-source-code).
|
2) Compile LLVM from source as described in the LLVM documentation [here](https://llvm.org/docs/GettingStarted.html#compiling-the-llvm-suite-source-code).
|
||||||
|
|
||||||
|
## Clangd Configuration
|
||||||
|
|
||||||
|
Clangd will automatically look for configuration information in files
|
||||||
|
named `.clangd` in each of the parent directories of the file being
|
||||||
|
edited. The Ladybird source code repository has a top-level `.clangd`
|
||||||
|
configuration file in the root directory. One of the configuration
|
||||||
|
stanzas in that file specifies the location for a compilation database.
|
||||||
|
Depending on your build configuration (e.g., Debug, default, Sanitizer,
|
||||||
|
etc), the path to the compilation database in that file may not be
|
||||||
|
correct. The result is that clangd will have a difficult time
|
||||||
|
understanding all your include directories. To resolve the problem, you
|
||||||
|
can use the `Meta/configure-clangd.sh` script.
|
||||||
|
|
50
Meta/configure-clangd.sh
Executable file
50
Meta/configure-clangd.sh
Executable file
|
@ -0,0 +1,50 @@
|
||||||
|
#!/usr/bin/env bash
|
||||||
|
|
||||||
|
function usage {
|
||||||
|
echo "$0 <.clangd file path> [release|debug]"
|
||||||
|
echo "Update local clangd configuration with the proper"
|
||||||
|
echo "compilation database according to the selected build type."
|
||||||
|
}
|
||||||
|
|
||||||
|
script_path=$(cd -P -- "$(dirname -- "$0")" && pwd -P)
|
||||||
|
cd "${script_path}/.." || exit 1
|
||||||
|
|
||||||
|
# Check if the user has sed.
|
||||||
|
|
||||||
|
if ! which sed >/dev/null 2>&1; then
|
||||||
|
echo "Error: No sed found. Cannot configure .clangd automatically."
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
|
|
||||||
|
# Check if the user specified the right number of parameters.
|
||||||
|
if [ $# -ne 2 ]; then
|
||||||
|
usage
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
|
|
||||||
|
clangd_file_path=$1
|
||||||
|
if [ ! -f "$clangd_file_path" ]; then
|
||||||
|
echo "Error: ${clangd_file_path} is not a regular file."
|
||||||
|
echo
|
||||||
|
usage
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
|
|
||||||
|
build_type=""
|
||||||
|
case $2 in
|
||||||
|
Debug)
|
||||||
|
build_type="-debug"
|
||||||
|
;;
|
||||||
|
default)
|
||||||
|
build_type=""
|
||||||
|
;;
|
||||||
|
Sanitizer)
|
||||||
|
build_type="-sanitizers"
|
||||||
|
;;
|
||||||
|
*)
|
||||||
|
echo "Invalid build configuration specified: $2"
|
||||||
|
usage
|
||||||
|
exit 1
|
||||||
|
esac
|
||||||
|
|
||||||
|
sed -i '' "s/\(^[ ]*CompilationDatabase:\).*$/\1 Build\/ladybird${build_type}/" "$clangd_file_path"
|
Loading…
Reference in a new issue