pyavroc编译

编译pyavroc

  1 #!/bin/bash
  2 avro_dir=$1
  3 
  4 # Copyright 2015 Byhiras (Europe) Limited
  5 #
  6 # Licensed under the Apache License, Version 2.0 (the "License");
  7 # you may not use this file except in compliance with the License.
  8 # You may obtain a copy of the License at
  9 #
 10 #     http://www.apache.org/licenses/LICENSE-2.0
 11 #
 12 # Unless required by applicable law or agreed to in writing, software
 13 # distributed under the License is distributed on an "AS IS" BASIS,
 14 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 15 # See the License for the specific language governing permissions and
 16 # limitations under the License.
 17 
 18 set -eux
 19 
 20 STATIC=0
 21 [ "${2:-}" = '--static' ] && STATIC=1
 22 
 23 MYDIR=$(dirname $(readlink -f "$0"))
 24 
 25 cd $MYDIR
 26 
 27 
 28 if [ -z "$avro_dir" ]; then
 29     echo "avro is null " 
 30     exit 1
 31 fi
 32 
 33 AVRO=$MYDIR/$avro_dir
 34 
 35 [ -d $AVRO ] || git clone -b patches http://github.com/Byhiras/avro $(basename $AVRO)
 36 
 37 # build avro
 38 
 39 if ! [ -f $AVRO/dist/lib/libavro.a ] && ! [ -f $AVRO/dist/lib/libavro.so ]
 40 then
 41     # libavro.a must contain PIC
 42     mv -n $AVRO/lang/c/src/CMakeLists.txt $AVRO/lang/c/src/orig_CMakeLists
 43     cp -v $AVRO/lang/c/src/orig_CMakeLists $AVRO/lang/c/src/CMakeLists.txt
 44     echo 'set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${CMAKE_SHARED_LIBRARY_C_FLAGS}")' >>$AVRO/lang/c/src/CMakeLists.txt
 45 
 46     mkdir -p $AVRO/build $AVRO/dist
 47     cd $AVRO/build
 48     cmake $AVRO/lang/c -DCMAKE_VERBOSE_MAKEFILE=ON -DCMAKE_INSTALL_PREFIX=$AVRO/dist -DCMAKE_BUILD_TYPE=Release -DTHREADSAFE=true
 49     make
 50     make test
 51     # workaround older cmake
 52     mv $AVRO/build/avro-c.pc $AVRO/build/src/ || true
 53     make install
 54 
 55     # use static lib
 56     [ $STATIC -eq 0 ] || rm -f $AVRO/dist/lib/libavro.so*
 57 fi
 58 
 59 PYTHON=${PYTHON:-python}
 60 
 61 # build avro python
 62 
 63 case $($PYTHON -c 'import sys; print(sys.version_info.major)') in
 64     3) AVROPY=$AVRO/lang/py3
 65         ;;
 66     *) AVROPY=$AVRO/lang/py
 67        ;;
 68 esac
 69 
 70 cd $AVROPY
 71 
 72 rm -rf build
 73 $PYTHON setup.py build
 74 
 75 # build pyavroc
 76 
 77 cd $MYDIR
 78 
 79 rm -rf build dist
 80 
 81 export PYAVROC_CFLAGS="-I$AVRO/dist/include"
 82 if [ $STATIC -ne 0 ]
 83 then
 84     mkdir -p pyavroc/avro
 85     cp -v local_avro/NOTICE.txt pyavroc/avro/
 86     # a bit cheesy: get libraries from the cmake link.txt file
 87     export PYAVROC_LIBS=$(tr ' ' '
' <$AVRO/build/src/CMakeFiles/avro-shared.dir/link.txt | grep '^-l' | cut -c3-)
 88     export LDFLAGS="-L$AVRO/dist/lib"
 89 else
 90     export LDFLAGS="-L$AVRO/dist/lib -Wl,-rpath,$AVRO/dist/lib"
 91 fi
 92 
 93 $PYTHON setup.py build
 94 
 95 cd build/lib*/pyavroc
 96 
 97 cd $MYDIR
 98 
 99 export PYTHONPATH=$(readlink -e build/lib*):$(readlink -e $AVROPY/build/lib*)
100 
101 cd tests
102 
103 $PYTHON -m pytest -sv .

https://github.com/apache/avro/tags

https://github.com/Byhiras/pyavroc/releases

 LD_LIBRARY_PATH=/data/xxx/ python reader.py 

原文地址:https://www.cnblogs.com/shiqi17/p/13268889.html