From 60f22dbd7f1ddf028ef5058751bb91b6b2c5d968 Mon Sep 17 00:00:00 2001 From: benn Date: Fri, 30 May 2025 10:30:10 +0200 Subject: [PATCH] Add compilation database file fooor clang-tidy --- nb_create.sh | 79 ++++++++++++++++++++++++++++++++++++++++------------ 1 file changed, 61 insertions(+), 18 deletions(-) diff --git a/nb_create.sh b/nb_create.sh index 4b7258c..74b29da 100755 --- a/nb_create.sh +++ b/nb_create.sh @@ -59,9 +59,38 @@ EOF } +if_no_dir_then_exit() +{ + exist_dir=$1 + message=$2 + + if [ ! -d $exist_dir ]; then + echo "ERROR: Can't find: "$exist_dir + echo " $message" + exit 1 + fi +} + + +if_no_file_then_exit() +{ + exist_file=$1 + message=$2 + + if [ ! -f $exist_file ]; then + echo "ERROR: Can't find: "$exist_file + echo " $message" + exit 1 + fi +} + + + + + main() { - #OPT_DEBUG=False # By default, debugging is off + OPT_DEBUG=False # By default, debugging is off OPT_ALL="$(getopt -o dhm:p:r: -l debug,help,main:,project:,repo: --name "$0" -- "$@")" eval set -- "$OPT_ALL" @@ -146,26 +175,40 @@ main() echo "Checking out repo..." cd $pwd - $(git clone $REPO .) + # $(git clone $REPO .) - if [ ! -d $pwd/nbproject ]; then - echo "ERROR: Not a NetBeans project" - echo " Can't find: "$pwd"/nbproject" - exit 1 - fi - if [ ! -f $pwd/nbproject/project.xml ]; then - echo "ERROR: Missing ./nbproject/project.xml" - echo " Netbeans project without a configuration file!" - exit 1 + if_no_dir_then_exit $pwd/nbproject "Not a NetBeans project" + if_no_file_then_exit $pwd/nbproject/project.xml "Netbeans project without a configuration file!" + + + if [ ! -f "compile_commands.json" ]; then + echo "WARNING: ./compile_commands.json not found" + echo " Netbeans project without a compilation database" + echo " Target check2 will not work" + echo " Generate compilation database: bear -- make" + else + replace="directory" + replacement="$pwd" + sed -i "s%^\s*\"$replace\"\:.*%\"directory\"\:\ \"$replacement\"\,%g" compile_commands.json + + replace="file" + replacement="$pwd""/src/${MAIN}.cpp" + sed -i "s%^\s*\"$replace\"\:.*%\"file\"\:\ \"$replacement\"\,%g" compile_commands.json + + replace="output" + replacement="$pwd""/obj/${MAIN}.obj" + sed -i "s%^\s*\"$replace\"\:.*%\"output\"\:\ \"$replacement\"\,%g" compile_commands.json fi - cd $pwd/nbproject - sed -i -e "s/\(\).*\(<\/name>\)/$PROJECT<\/name>/g" project.xml - - cd "$pwd"/src - if [ -f ./myapp.cpp ]; then - mv myapp.cpp "$MAIN".cpp - fi + + exit 0 +# cd $pwd/nbproject +# sed -i -e "s/\(\).*\(<\/name>\(/$PROJECT<\/name>/g" project.xml +# +# cd "$pwd"/src +# if [ -f ./myapp.cpp ]; then +# mv myapp.cpp "$MAIN".cpp +# fi }