Merge pull request #63948 from azat/build/c++expr

Some usability improvements for c++expr script
This commit is contained in:
Alexey Milovidov 2024-05-17 01:32:47 +00:00 committed by GitHub
commit 2bee6d295e
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -7,11 +7,13 @@ USAGE: c++expr [-c CXX | -C | -I] [-i INCLUDE] [-l LIB] [-b STEPS] [-t TESTS] [-
OPTIONS:
-c CXX use specified c++ compiler
-C use cmake
-k keep generated worktree
-I integrate into ClickHouse build tree in current directory
-i INC add #include <INC>
-l LIB link against LIB (only for -I or -C)
-b STEPS_NUM make program to benchmark specified code snippet and run tests with STEPS_NUM each
-b perf-top run infinite benchmark and show perf top
-B build-dir build directory for -I (default: "build")
-t TESTS_NUM make program to benchmark specified code snippet and run TESTS_NUM tests
-o FILE do not run, just save binary executable file
-O CXX_OPTS forward option compiler (e.g. -O "-O3 -std=c++20")
@ -37,6 +39,7 @@ GLOBAL=
OUTPUT_EXECUTABLE=
INCS="vector iostream typeinfo cstdlib cmath sys/time.h"
LIBS=""
BUILD_DIR=build
BENCHMARK_STEPS=0
RUN_PERFTOP=
BENCHMARK_TESTS=5
@ -45,13 +48,14 @@ USE_CLICKHOUSE=
CXX=g++
CXX_OPTS=
CMD_PARAMS=
KEEP_WORKTREE=0
#
# Parse command line
#
if [ "$1" == "--help" ] || [ -z "$1" ]; then usage; fi
while getopts "vc:CIi:l:b:t:o:O:g:" OPT; do
while getopts "vc:CIi:l:bkB:t:o:O:g:" OPT; do
case "$OPT" in
v) set -x; ;;
c) CXX="$OPTARG"; ;;
@ -60,6 +64,8 @@ while getopts "vc:CIi:l:b:t:o:O:g:" OPT; do
i) INCS="$INCS $OPTARG"; ;;
l) LIBS="$LIBS $OPTARG"; ;;
b) if [ "$OPTARG" = perf-top ]; then BENCHMARK_STEPS=-1; RUN_PERFTOP=y; else BENCHMARK_STEPS="$OPTARG"; fi; ;;
B) BUILD_DIR="$OPTARG"; ;;
k) KEEP_WORKTREE=1; ;;
t) BENCHMARK_TESTS="$OPTARG"; ;;
o) OUTPUT_EXECUTABLE="$OPTARG"; ;;
O) CXX_OPTS="$CXX_OPTS $OPTARG"; ;;
@ -110,11 +116,11 @@ find_clickhouse_root () {
find_clickhouse_build () {
local CLICKHOUSE_ROOT="`find_clickhouse_root`"
if [ -e "$CLICKHOUSE_ROOT/build/CMakeCache.txt" ]; then
echo "$CLICKHOUSE_ROOT/build"
if [ -e "$CLICKHOUSE_ROOT/$BUILD_DIR/CMakeCache.txt" ]; then
echo "$CLICKHOUSE_ROOT/$BUILD_DIR"
return 0
fi
echo "error: $CLICKHOUSE_ROOT/build/CMakeCache.txt doesn't exist"
echo "error: $CLICKHOUSE_ROOT/$BUILD_DIR/CMakeCache.txt doesn't exist"
return 1
}
@ -144,13 +150,17 @@ if [ -n "$USE_CLICKHOUSE" ]; then
echo "add_subdirectory ($SUBDIR)" >>$CALL_DIR/CMakeLists.txt
cleanup() {
mv $CALL_DIR/CMakeLists.txt.backup.$$ $CALL_DIR/CMakeLists.txt
rm -rf $WORKDIR
rm -rf ${BUILD_ROOT}${CLICKHOUSE_PATH}
if [ $KEEP_WORKTREE -eq 0 ]; then
rm -rf $WORKDIR
rm -rf ${BUILD_ROOT}${CLICKHOUSE_PATH}
fi
}
else
WORKDIR=/var/tmp/cppexpr_$$
cleanup() {
rm -rf $WORKDIR
if [ $KEEP_WORKTREE -eq 0 ]; then
rm -rf $WORKDIR
fi
}
fi