forked from primihub/primihub
-
Notifications
You must be signed in to change notification settings - Fork 0
/
pre_build.sh
executable file
·56 lines (47 loc) · 1.43 KB
/
pre_build.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
#!/bin/bash
set -x
set -e
PYTHON_BIN=python3
if ! command -v python3 >/dev/null 2>&1; then
if ! command -v python >/dev/null 2>&1; then
echo "please install python3"
exit
else
PYTHON_BIN=python
fi
fi
U_V1=`$PYTHON_BIN -V 2>&1|awk '{print $2}'|awk -F '.' '{print $1}'`
U_V2=`$PYTHON_BIN -V 2>&1|awk '{print $2}'|awk -F '.' '{print $2}'`
U_V3=`$PYTHON_BIN -V 2>&1|awk '{print $2}'|awk -F '.' '{print $3}'`
echo your python version is : "$U_V1.$U_V2.$U_V3"
if ! [ "${U_V1}" = 3 ] && [ "${U_V2}" > 6 ]; then
echo "python version must > 3.6"
exit
fi
PYTHON_CONFIG_CMD="python$U_V1.$U_V2-config"
if ! command -v ${PYTHON_CONFIG_CMD} >/dev/null 2>&1; then
echo "please install python$U_V1.$U_V2-dev"
exit
fi
#get python include path
PYTHON_INC_CONFIG=`${PYTHON_CONFIG_CMD} --includes | awk '{print $1}' |awk -F'-I' '{print $2}'`
if [ ! -d "${PYTHON_INC_CONFIG}" ]; then
echo "${PYTHON_CONFIG_CMD} get python include path failed"
exit -1
fi
# link python include path into workspace
pushd third_party
rm -f python_headers
ln -s ${PYTHON_INC_CONFIG} python_headers
popd
#get python link option
CONFIG=`${PYTHON_CONFIG_CMD} --ldflags` && NEWLINE="[\"${CONFIG}\"] + [\"-lpython$U_V1.$U_V2\"]"
# Compatible with MacOS
sed -e "s|PLACEHOLDER-PYTHON3.X-CONFIG|${NEWLINE}|g" BUILD.bazel > BUILD.bazel.tmp && mv BUILD.bazel.tmp BUILD.bazel
echo "done"
if [ ! -d "localdb" ]; then
mkdir localdb
fi
if [ ! -d "log" ]; then
mkdir log
fi