106f6ba60Sopenharmony_ci#!/bin/bash
206f6ba60Sopenharmony_ci# Copyright (c) Huawei Technologies Co., Ltd. 2021-2023. All rights reserved.
306f6ba60Sopenharmony_ci# Licensed under the Apache License, Version 2.0 (the "License");
406f6ba60Sopenharmony_ci# you may not use this file except in compliance with the License.
506f6ba60Sopenharmony_ci# You may obtain a copy of the License at
606f6ba60Sopenharmony_ci#
706f6ba60Sopenharmony_ci#     http://www.apache.org/licenses/LICENSE-2.0
806f6ba60Sopenharmony_ci#
906f6ba60Sopenharmony_ci# Unless required by applicable law or agreed to in writing, software
1006f6ba60Sopenharmony_ci# distributed under the License is distributed on an "AS IS" BASIS,
1106f6ba60Sopenharmony_ci# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
1206f6ba60Sopenharmony_ci# See the License for the specific language governing permissions and
1306f6ba60Sopenharmony_ci# limitations under the License.
1406f6ba60Sopenharmony_ci
1506f6ba60Sopenharmony_ciset -e
1606f6ba60Sopenharmony_ci
1706f6ba60Sopenharmony_ciTHIS_DIR=$(dirname ${BASH_SOURCE[0]})
1806f6ba60Sopenharmony_ciPROJECT_TOP=$(realpath $THIS_DIR/../../..)
1906f6ba60Sopenharmony_ci
2006f6ba60Sopenharmony_ciOHOS_X64_OUT=$PROJECT_TOP/$2/
2106f6ba60Sopenharmony_ciLIBCXX_X64_OUT=$PROJECT_TOP/$1/ndk/libcxx/linux_x86_64
2206f6ba60Sopenharmony_ciSUBSYS_X64_OUT=$PROJECT_TOP/$2/developtools/hiprofiler
2306f6ba60Sopenharmony_ciPROTOC=$PROJECT_TOP/$2/thirdparty/protobuf/protoc
2406f6ba60Sopenharmony_ciOPT_PLUGIN_PATH=$PROJECT_TOP/$2/developtools/hiprofiler/protoencoder_plugin
2506f6ba60Sopenharmony_ciOPT_PLUGIN=--plugin=protoc-gen-opt=$PROJECT_TOP/$2/developtools/hiprofiler/protoencoder_plugin
2606f6ba60Sopenharmony_ciOPT_OUT=--opt_out
2706f6ba60Sopenharmony_ci
2806f6ba60Sopenharmony_ciPYTHON_SHELL=$THIS_DIR/make_proto.py # shell path
2906f6ba60Sopenharmony_ciTMP=$2
3006f6ba60Sopenharmony_ciPROTO_OUT_DIR="$PROJECT_TOP/${TMP%/*}/$3" # path of the new proto file
3106f6ba60Sopenharmony_ci
3206f6ba60Sopenharmony_ciecho "1 = $1"
3306f6ba60Sopenharmony_ciecho "2 = $2"
3406f6ba60Sopenharmony_ciPARAMS=$*
3506f6ba60Sopenharmony_ciPARAMS_FILTER="$1 $2 $3"
3606f6ba60Sopenharmony_ci# for python : copy and change source .proto file
3706f6ba60Sopenharmony_ciTARFLAG="--proto_path"
3806f6ba60Sopenharmony_ciPARAMS_SOURCE_TMP="${PARAMS#*${TARFLAG}}" # get source proto file path
3906f6ba60Sopenharmony_ciPARAMS_SOURCES=""
4006f6ba60Sopenharmony_ciNUM=0
4106f6ba60Sopenharmony_cifor ITM in ${PARAMS_SOURCE_TMP[@]} # filter the TARGLAG
4206f6ba60Sopenharmony_cido
4306f6ba60Sopenharmony_ci  if [ $NUM -gt 0 ]; then
4406f6ba60Sopenharmony_ci    PARAMS_SOURCES="$PARAMS_SOURCES$ITM "
4506f6ba60Sopenharmony_ci  fi
4606f6ba60Sopenharmony_ci  NUM=$[$NUM + 1]
4706f6ba60Sopenharmony_cidone
4806f6ba60Sopenharmony_ciPARAMS_PRINT="$PROTO_OUT_DIR $PARAMS_SOURCES" # splice the python args
4906f6ba60Sopenharmony_ciecho "EXEC: python $PYTHON_SHELL $PARAMS_PRINT"
5006f6ba60Sopenharmony_cipython $PYTHON_SHELL $PARAMS_PRINT
5106f6ba60Sopenharmony_ci# end python
5206f6ba60Sopenharmony_ci
5306f6ba60Sopenharmony_ci# creat pb file
5406f6ba60Sopenharmony_ciPARAMS_SRC=${PARAMS:${#PARAMS_FILTER}}
5506f6ba60Sopenharmony_ciPARAMS_REPLACE=${PARAMS_SOURCES//.proto/_standard.proto} # make the new proto file name. like "_standard.proto"
5606f6ba60Sopenharmony_ciPARAMS_STANDARD=" --proto_path $PROTO_OUT_DIR " # add proto_path,$PROTO_OUT_DIR is the pb file path
5706f6ba60Sopenharmony_cifor VAR in ${PARAMS_REPLACE[@]}
5806f6ba60Sopenharmony_cido
5906f6ba60Sopenharmony_ci  PARAMS_STANDARD="$PARAMS_STANDARD$PROTO_OUT_DIR/${VAR##*/} " # add .proto file name to args
6006f6ba60Sopenharmony_cidone
6106f6ba60Sopenharmony_ciPARAMS_ALL="$PARAMS_SRC $PARAMS_STANDARD" # add new argument list to old argument list
6206f6ba60Sopenharmony_ci
6306f6ba60Sopenharmony_ciPARAMS_LITE_REPLACE=${PARAMS_SOURCES//.proto/_lite.proto} # make the new proto file name. like "_lite.proto"
6406f6ba60Sopenharmony_ciPARAMS_LITE=" --proto_path $PROTO_OUT_DIR " # add proto_path,$PROTO_OUT_DIR is the pb file path
6506f6ba60Sopenharmony_cifor VAR in ${PARAMS_LITE_REPLACE[@]}
6606f6ba60Sopenharmony_cido
6706f6ba60Sopenharmony_ci  PARAMS_LITE="$PARAMS_LITE$PROTO_OUT_DIR/${VAR##*/} " # add .proto file name to args
6806f6ba60Sopenharmony_cidone
6906f6ba60Sopenharmony_ciPARAMS_ALL="$PARAMS_SRC $PARAMS_STANDARD $PARAMS_LITE" # add new argument list to old argument list
7006f6ba60Sopenharmony_ci
7106f6ba60Sopenharmony_ci# avoid conflict, param4=--plugin* means ipc plugin, generate encode file if opt plugin exist
7206f6ba60Sopenharmony_ciif [[ "$4" != --plugin* ]]; then
7306f6ba60Sopenharmony_ci  if [ -f "$OPT_PLUGIN_PATH" ]; then
7406f6ba60Sopenharmony_ci    echo "generate protobuf optimize code OPT_PLUGIN = $OPT_PLUGIN"
7506f6ba60Sopenharmony_ci    echo "optimize EXEC: LD_LIBRARY_PATH=$LIBCXX_X64_OUT:$SUBSYS_X64_OUT $PROTOC $OPT_PLUGIN $OPT_OUT $5 $PARAMS_ALL"
7606f6ba60Sopenharmony_ci    LD_LIBRARY_PATH=$LIBCXX_X64_OUT:$SUBSYS_X64_OUT exec $PROTOC $OPT_PLUGIN $OPT_OUT $5 $PARAMS_ALL
7706f6ba60Sopenharmony_ci  fi
7806f6ba60Sopenharmony_cifi
7906f6ba60Sopenharmony_ci
8006f6ba60Sopenharmony_ciecho "EXEC: LD_LIBRARY_PATH=$LIBCXX_X64_OUT:$SUBSYS_X64_OUT $PROTOC $PARAMS_ALL"
8106f6ba60Sopenharmony_ciLD_LIBRARY_PATH=$LIBCXX_X64_OUT:$SUBSYS_X64_OUT exec $PROTOC $PARAMS_ALL