From 2b8f74013cadedda804ec7f51793e3eca668a1aa Mon Sep 17 00:00:00 2001 From: aceforeverd Date: Mon, 16 Sep 2024 14:17:37 +0800 Subject: [PATCH] fix pack_zetasql.sh --- build_zetasql_parser.sh | 49 ++++++++++++++++++++++++++++++++++++++++- pack_zetasql.sh | 48 ++++++++++++++++++++++++---------------- 2 files changed, 77 insertions(+), 20 deletions(-) diff --git a/build_zetasql_parser.sh b/build_zetasql_parser.sh index 81194da8..8d398f1a 100755 --- a/build_zetasql_parser.sh +++ b/build_zetasql_parser.sh @@ -29,8 +29,55 @@ fi echo "build with python: $(python -V), python3: $(python3 -V)" +#=== FUNCTION ================================================================ +# NAME: usage +# DESCRIPTION: Display usage information. +#=============================================================================== +function usage () +{ + echo "Usage : $0 [options] [--] + + Options: + -h|help Display this message" + +} # ---------- end of function usage ---------- + +#----------------------------------------------------------------------- +# Handle command line arguments +#----------------------------------------------------------------------- + +# NOTE: default to static profile: compile all as archive but not define `NDEBUG` +# since pre-compiled lib may used in Release/Debug profile in OpenMLDB +# +# acceptable values: +# - release: `-O2 -DNDEBUG`, shared libs +# - static: static libs +# - release-static: `-O2 -DNDEBUG`, static libs +PROFILE=static +ACCEPT_PROFILES=(static release release-static) + +while getopts ":hc:" opt +do + case $opt in + + c ) PROFILE=$OPTARG ;; + + h|help ) usage; exit 0 ;; + + * ) echo -e "\n Option does not exist : $OPTARG\n" + usage; exit 1 ;; + + esac # --- end of case --- +done +shift $((OPTIND-1)) + +if [[ ! " ${ACCEPT_PROFILES[*]} " =~ " ${PROFILE} " ]] ; then + echo "profile named $PROFILE not found in accept profile list: ${ACCEPT_PROFILES[*]}" + exit 1 +fi + TARGET='//zetasql/parser/...' -BUILD_ARGV=(--config=release-static) +BUILD_ARGV=(--config="$PROFILE") bazel build "$TARGET" "${BUILD_ARGV[@]}" bazel test "$TARGET" "${BUILD_ARGV[@]}" diff --git a/pack_zetasql.sh b/pack_zetasql.sh index c0eac838..44f8530e 100755 --- a/pack_zetasql.sh +++ b/pack_zetasql.sh @@ -15,6 +15,7 @@ function usage () Options: -h Display this message -d Linux distribution name, e.g centos, ubuntu, default empty + -p Pick PIC libraries only, OFF by default -i Request install to given directory after pack" } # ---------- end of function usage ---------- @@ -26,8 +27,9 @@ function usage () INSTALL_DIR= # linux distribution name DISTRO= +PICK_PIC=OFF -while getopts ":hi:d:" opt +while getopts ":hi:d:p:" opt do case $opt in @@ -35,6 +37,8 @@ do d ) DISTRO=$OPTARG ;; + p ) PICK_PIC=$OPTARG ;; + i ) INSTALL_DIR=$OPTARG mkdir -p "$INSTALL_DIR" @@ -48,6 +52,12 @@ do done shift $((OPTIND-1)) +if [[ "$PICK_PIC" == 'ON' ]] ; then + LIB_PATTERN='*.pic.a' +else + LIB_PATTERN='*.a' +fi + pushd "$(dirname "$0")" pushd "$(git rev-parse --show-toplevel)" @@ -68,7 +78,10 @@ install_lib() { local file file=$1 local libname - libname=lib$(echo "$file" | tr '/' '_' | sed -e 's/lib//' | sed -e 's/\.pic\.a$/.a/') + libname=lib$(echo "$file" | tr '/' '_' | sed -e 's/lib//' ) + if [[ "$PICK_PIC" == 'ON' ]]; then + libname=$(echo "$libname" | sed -e 's/\.pic\.a$/.a/') + fi if [[ "$OSTYPE" == "linux-gnu"* ]] then @@ -85,12 +98,6 @@ install_gen_include_file() { local outfile outfile=$(echo "$file" | sed -e 's/^.*proto\///') - if [[ "$OSTYPE" == "linux-gnu"* ]] - then - INSTALL_BIN="install" - else - INSTALL_BIN="ginstall" - fi ${INSTALL_BIN} -Dv "$file" "$PREFIX/include/$outfile" } @@ -98,7 +105,10 @@ install_external_lib() { local file file=$1 local libname - libname=$(basename "$file" | sed -e 's/\.pic\.a$/.a/') + libname=$(basename "$file") + if [[ "$PICK_PIC" == 'ON' ]]; then + libname=$(echo "$libname" | sed -e 's/\.pic\.a$/.a/') + fi if [[ "$OSTYPE" == "linux-gnu"* ]] then INSTALL_BIN="install" @@ -121,38 +131,38 @@ else fi pushd bazel-bin/ -find zetasql -type f -iname '*.pic.a' -exec bash -c 'install_lib $0' {} \; +find zetasql -type f -iname "$LIB_PATTERN" -exec bash -c 'install_lib $0' {} \; # external lib headers pushd "$(realpath .)/../../../../../external/com_googlesource_code_re2" -find re2 -iname "*.h" -exec ${INSTALL_BIN} -D {} "$PREFIX"/include/{} \; +find re2 -iname "*.h" -exec ${INSTALL_BIN} -Dv {} "$PREFIX"/include/{} \; popd pushd "$(realpath .)/../../../../../external/com_googleapis_googleapis" -find google -iname "*.h" -exec ${INSTALL_BIN} -D {} "$PREFIX"/include/{} \; +find google -iname "*.h" -exec ${INSTALL_BIN} -Dv {} "$PREFIX"/include/{} \; popd pushd "$(realpath .)/../../../../../external/com_google_file_based_test_driver" -find file_based_test_driver -iname "*.h" -exec ${INSTALL_BIN} -D {} "$PREFIX"/include/{} \; +find file_based_test_driver -iname "*.h" -exec ${INSTALL_BIN} -Dv {} "$PREFIX"/include/{} \; popd # external lib pushd external -find icu -type f -iname '*.pic.a' -exec bash -c 'install_external_lib $0' {} \; -find com_googlesource_code_re2 -type f -iname '*.pic.a' -exec bash -c 'install_external_lib $0' {} \; -find com_googleapis_googleapis -type f -iname '*.pic.a' -exec bash -c 'install_external_lib $0' {} \; -find com_google_file_based_test_driver -type f -iname '*.pic.a' -exec bash -c 'install_external_lib $0' {} \; +find icu -type f -iname "$LIB_PATTERN" -exec bash -c 'install_external_lib $0' {} \; +find com_googlesource_code_re2 -type f -iname "$LIB_PATTERN" -exec bash -c 'install_external_lib $0' {} \; +find com_googleapis_googleapis -type f -iname "$LIB_PATTERN" -exec bash -c 'install_external_lib $0' {} \; +find com_google_file_based_test_driver -type f -iname "$LIB_PATTERN" -exec bash -c 'install_external_lib $0' {} \; popd # zetasql generated files: protobuf & template generated files -find zetasql -type f -iname "*.h" -exec ${INSTALL_BIN} -D {} "$PREFIX"/include/{} \; +find zetasql -type f -iname "*.h" -exec ${INSTALL_BIN} -Dv {} "$PREFIX"/include/{} \; find zetasql -iregex ".*/_virtual_includes/.*\.h\$" -exec bash -c 'install_gen_include_file $0' {} \; popd # bazel-bin # header files from source -find zetasql -type f -iname "*.h" -exec ${INSTALL_BIN} -D {} "$PREFIX"/include/{} \; +find zetasql -type f -iname "*.h" -exec ${INSTALL_BIN} -Dv {} "$PREFIX"/include/{} \; if [[ "$OSTYPE" == "linux-gnu"* ]]