|
| 1 | +#!/bin/bash |
| 2 | + |
| 3 | +set -e |
| 4 | +#set -x |
| 5 | + |
| 6 | +if [ -z "$BUILD_VERBOSE" ]; then |
| 7 | + BUILD_VERBOSE=OFF |
| 8 | +fi |
| 9 | + |
| 10 | +source $(dirname $(readlink -f $0))/common.sh |
| 11 | + |
| 12 | + |
| 13 | +parse_with_getopt() { |
| 14 | + # [如何使用 getopt 和 getopts 命令解析命令行选项和参数](https://zhuanlan.zhihu.com/p/673908518) |
| 15 | + # [【Linux】Shell 命令 getopts/getopt 用法详解](https://blog.csdn.net/arpospf/article/details/103381621) |
| 16 | + if command -V getopt >/dev/null; then |
| 17 | + echo "getopt is exits" |
| 18 | + #echo "original parameters=[$@]" |
| 19 | + # -o 或 --options 选项后面是可接受的短选项,如 ab:c:: ,表示可接受的短选项为 -a -b -c , |
| 20 | + # 其中 -a 选项不接参数,-b 选项后必须接参数,-c 选项的参数为可选的 |
| 21 | + # 后面没有冒号表示没有参数。后跟有一个冒号表示有参数。跟两个冒号表示有可选参数。 |
| 22 | + # -l 或 --long 选项后面是可接受的长选项,用逗号分开,冒号的意义同短选项。 |
| 23 | + # -n 选项后接选项解析错误时提示的脚本名字 |
| 24 | + OPTS=help,verbose::,install:,source:,tools:,build:,lint:: |
| 25 | + ARGS=`getopt -o h,v:: -l $OPTS -n $(basename $0) -- "$@"` |
| 26 | + if [ $? != 0 ]; then |
| 27 | + echo_error "exec getopt fail: $?" |
| 28 | + exit 1 |
| 29 | + fi |
| 30 | + #echo "ARGS=[$ARGS]" |
| 31 | + #将规范化后的命令行参数分配至位置参数($1,$2,......) |
| 32 | + eval set -- "${ARGS}" |
| 33 | + #echo "formatted parameters=[$@]" |
| 34 | + |
| 35 | + while [ $1 ] |
| 36 | + do |
| 37 | + #echo "\$1: $1" |
| 38 | + #echo "\$2: $2" |
| 39 | + case $1 in |
| 40 | + --install) |
| 41 | + INSTALL_DIR=$2 |
| 42 | + shift 2 |
| 43 | + ;; |
| 44 | + --source) |
| 45 | + SOURCE_DIR=$2 |
| 46 | + shift 2 |
| 47 | + ;; |
| 48 | + --tools) |
| 49 | + TOOLS_DIR=$2 |
| 50 | + shift 2 |
| 51 | + ;; |
| 52 | + --build) |
| 53 | + BUILD_DIR="$2" |
| 54 | + shift 2 |
| 55 | + ;; |
| 56 | + -v|--verbose) |
| 57 | + case $2 in |
| 58 | + "") |
| 59 | + BUILD_VERBOSE=ON;; |
| 60 | + *) |
| 61 | + BUILD_VERBOSE=$2;; |
| 62 | + esac |
| 63 | + shift 2 |
| 64 | + ;; |
| 65 | + --lint) |
| 66 | + case $2 in |
| 67 | + "") |
| 68 | + LINT=1;; |
| 69 | + *) |
| 70 | + LINT=$2;; |
| 71 | + esac |
| 72 | + shift 2 |
| 73 | + ;; |
| 74 | + --) # 当解析到“选项和参数“与“non-option parameters“的分隔符时终止 |
| 75 | + shift |
| 76 | + break |
| 77 | + ;; |
| 78 | + -h | -help) |
| 79 | + usage_long |
| 80 | + shift |
| 81 | + ;; |
| 82 | + *) |
| 83 | + usage_long |
| 84 | + break |
| 85 | + ;; |
| 86 | + esac |
| 87 | + done |
| 88 | + fi |
| 89 | +} |
| 90 | + |
| 91 | +# Parse command line arguments |
| 92 | +parse_command_line() { |
| 93 | + # Use getopt if available, otherwise fall back to getopts |
| 94 | + if command -v getopt >/dev/null 2>&1; then |
| 95 | + parse_with_getopt "$@" |
| 96 | + else |
| 97 | + echo "Install GNU getopt" |
| 98 | + fi |
| 99 | +} |
| 100 | + |
| 101 | + |
| 102 | +# Display current configuration |
| 103 | +show_configuration() { |
| 104 | + if [ "$BUILD_VERBOSE" = "ON" ]; then |
| 105 | + echo "=== Current Configuration ===" |
| 106 | + echo "Directory Configuration:" |
| 107 | + echo " Install Directory: ${INSTALL_DIR:-Not set (using default)}" |
| 108 | + echo " Source Directory: ${SOURCE_DIR:-Not set (using default)}" |
| 109 | + echo " Tools Directory: ${TOOLS_DIR:-Not set (using default)}" |
| 110 | + echo " Build Directory: ${BUILD_DIR:-Not set (using default)}" |
| 111 | + echo " Build Depend Directory: ${BUILD_DEPEND_DIR:-Not set (using default)}" |
| 112 | + echo "Build target:" |
| 113 | + echo " Lint check: $LINT" |
| 114 | + echo "Other Settings:" |
| 115 | + echo " Verbose Mode: $BUILD_VERBOSE" |
| 116 | + echo "=========================" |
| 117 | + echo "" |
| 118 | + fi |
| 119 | + |
| 120 | + echo "Repo folder: $REPO_ROOT" |
| 121 | + echo "Old folder: $OLD_CWD" |
| 122 | + echo "Current folder: `pwd`" |
| 123 | + echo "SOURCE_DIR: $SOURCE_DIR" |
| 124 | + echo "TOOLS_DIR: $TOOLS_DIR" |
| 125 | + echo "INSTALL_DIR: $INSTALL_DIR" |
| 126 | + echo "BUILD_DIR: $BUILD_DIR" |
| 127 | + echo "BUILD_LINUX_DIR: $BUILD_LINUX_DIR" |
| 128 | +} |
| 129 | + |
| 130 | +# Parse command line arguments (will override environment variables) |
| 131 | +parse_command_line "$@" |
| 132 | + |
| 133 | +## Directory variables |
| 134 | +CURDIR=$(dirname $(safe_readlink $0)) |
| 135 | +REPO_ROOT=$(safe_readlink $(dirname $(dirname $(safe_readlink $0)))) |
| 136 | + |
| 137 | +if [ -z "$BUILD_LINUX_DIR" ]; then |
| 138 | + if [ -z "$BUILD_DIR" ]; then |
| 139 | + BUILD_LINUX_DIR=${REPO_ROOT}/build_linux |
| 140 | + else |
| 141 | + BUILD_LINUX_DIR=${BUILD_DIR}/build_linux |
| 142 | + fi |
| 143 | +fi |
| 144 | +if [ -z "$SOURCE_DIR" ]; then |
| 145 | + SOURCE_DIR=${BUILD_LINUX_DIR}/source |
| 146 | +fi |
| 147 | +if [ -z "$TOOLS_DIR" ]; then |
| 148 | + TOOLS_DIR=${BUILD_LINUX_DIR}/tools |
| 149 | +fi |
| 150 | +if [ -z "$INSTALL_DIR" ]; then |
| 151 | + INSTALL_DIR=${BUILD_LINUX_DIR}/install |
| 152 | +fi |
| 153 | +#rm -fr $SOURCE_DIR |
| 154 | +mkdir -p $SOURCE_DIR |
| 155 | +#rm -fr $TOOLS_DIR |
| 156 | +mkdir -p $TOOLS_DIR |
| 157 | +#rm -fr $INSTALL_DIR |
| 158 | +mkdir -p $INSTALL_DIR |
| 159 | + |
| 160 | +# Display configuration |
| 161 | +show_configuration |
| 162 | + |
| 163 | +echo_status "Build with lint check ......" |
| 164 | +pushd $BUILD_LINUX_DIR |
| 165 | + |
| 166 | +cmake "$REPO_ROOT" \ |
| 167 | + -DCMAKE_CXX_COMPILER=clazy -DCMAKE_EXPORT_COMPILE_COMMANDS=ON \ |
| 168 | + -DCMAKE_INSTALL_PREFIX=/usr \ |
| 169 | + -DCMAKE_VERBOSE_MAKEFILE=${BUILD_VERBOSE} \ |
| 170 | + -DCMARK_SHARED=OFF \ |
| 171 | + -DCMARK_TESTS=OFF \ |
| 172 | + -DCMARK_STATIC=ON \ |
| 173 | + -DWITH_CMARK=OFF \ |
| 174 | + -DWITH_CMARK_GFM=OFF \ |
| 175 | + -DENABLE_UPDATE_TRANSLATIONS=OFF \ |
| 176 | + -DWITH_WebEngineWidgets=ON \ |
| 177 | + -DCMAKE_BUILD_TYPE=Release \ |
| 178 | + -DBUILD_QUIWidget=OFF \ |
| 179 | + -DBUILD_APP=ON \ |
| 180 | + -DBUILD_FREERDP=ON |
| 181 | +if [ "$BUILD_VERBOSE"="ON" ]; then |
| 182 | + cmake --build . --config Release --parallel $(nproc) | tee clazy_output.log |
| 183 | +else |
| 184 | + cmake --build . --config Release --parallel $(nproc) > clazy_output.log |
| 185 | +fi |
| 186 | + |
| 187 | +# 统计错误和警告 |
| 188 | +errors_found=$(grep -c "error:" clazy_output.log 2>/dev/null || echo "0") |
| 189 | +warnings_found=$(grep -c "warning:" clazy_output.log 2>/dev/null || echo "0") |
| 190 | + |
| 191 | +# 处理错误 |
| 192 | +if [ "$errors_found" -gt 0 ] 2>/dev/null; then |
| 193 | + echo_error "Clazy check found $errors_found error(s):" |
| 194 | + grep "error:" clazy_output.log |
| 195 | + exit 1 # 有错误时退出 |
| 196 | +fi |
| 197 | + |
| 198 | +# 处理警告 |
| 199 | +if [ "$warnings_found" -gt 0 ] 2>/dev/null; then |
| 200 | + echo_warn "Clazy check found $warnings_found warning(s):" |
| 201 | + grep "warning:" clazy_output.log |
| 202 | + # 警告不退出,只提示 |
| 203 | +fi |
| 204 | + |
| 205 | +popd |
| 206 | + |
| 207 | +echo_status "lint check completed" |
0 commit comments