Skip to content

Commit

Permalink
fix pack_zetasql.sh
Browse files Browse the repository at this point in the history
  • Loading branch information
aceforeverd committed Sep 16, 2024
1 parent 30a04b6 commit 2b8f740
Show file tree
Hide file tree
Showing 2 changed files with 77 additions and 20 deletions.
49 changes: 48 additions & 1 deletion build_zetasql_parser.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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[@]}"
Expand Down
48 changes: 29 additions & 19 deletions pack_zetasql.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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 ----------
Expand All @@ -26,15 +27,18 @@ 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

h ) usage; exit 0 ;;

d ) DISTRO=$OPTARG ;;

p ) PICK_PIC=$OPTARG ;;

i )
INSTALL_DIR=$OPTARG
mkdir -p "$INSTALL_DIR"
Expand All @@ -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)"

Expand All @@ -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
Expand All @@ -85,20 +98,17 @@ 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"
}

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"
Expand All @@ -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"* ]]
Expand Down

0 comments on commit 2b8f740

Please sign in to comment.