github.com/muhammedhassanm/blockchain@v0.0.0-20200120143007-697261defd4d/sawtooth-core-master/bin/build_ext_debs (about) 1 #!/usr/bin/env bash 2 # Copyright 2017 Intel Corporation 3 # 4 # Licensed under the Apache License, Version 2.0 (the "License"); 5 # you may not use this file except in compliance with the License. 6 # You may obtain a copy of the License at 7 # 8 # http://www.apache.org/licenses/LICENSE-2.0 9 # 10 # Unless required by applicable law or agreed to in writing, software 11 # distributed under the License is distributed on an "AS IS" BASIS, 12 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 # See the License for the specific language governing permissions and 14 # limitations under the License. 15 # ------------------------------------------------------------------------------ 16 17 # This script was developed for usage inside a docker container and makes 18 # assumptions that the 'bin/install_packaging_deps' has already been run 19 # to install the dependencies. This script can be run in a clean docker 20 # environment with the following commands: 21 # 22 # cd sawtooth-core 23 # docker run \ 24 # -v $(pwd):/project/sawtooth-core \ 25 # --workdir /project/sawtooth-core \ 26 # --env https_proxy=$https_proxy \ 27 # --env http_proxy=$http_proxy \ 28 # --env HTTPS_PROXY=$HTTPS_PROXY \ 29 # --env HTTP_PROXY=$HTTP_PROXY \ 30 # -t ubuntu:xenial \ 31 # bash -c " \ 32 # apt-get update \ 33 # && ./bin/install_packaging_deps \ 34 # && ./bin/build_ext_debs \ 35 # " 36 # Between builds you may want to clean the intermediate and output directories" 37 # cd sawtooth-core 38 # rm -rf projects packages 39 # 40 41 set -e 42 43 build_dir=$(pwd)/projects 44 pkg_dir=$(pwd)/packages 45 46 while getopts :p:b:h opt 47 do 48 case $opt in 49 h) 50 echo "Usage:" 51 echo " $0 [-b build_dir] [-p package_dir]" 52 echo 53 echo "Options:" 54 echo " -h print usage and exit" 55 echo " -b build_dir directory to build in" 56 echo " -p package_dir directory to place debs in" 57 exit 0 58 ;; 59 b) 60 build_dir=$OPTARG 61 ;; 62 p) 63 pkg_dir=$OPTARG 64 ;; 65 \?) 66 echo "Invalid option: -$OPTARG" >&2 67 exit 2 68 ;; 69 esac 70 done 71 72 73 main() { 74 info "Building debs in $build_dir and storing in $pkg_dir" 75 76 mkdir -p ${build_dir} && mkdir -p ${pkg_dir} 77 78 build_python_debs 79 build_cxx_debs 80 } 81 82 build_cxx_debs() { 83 info "Building debs needed by the C++ SDK" 84 build_dir_cxx=${build_dir}/cxx 85 mkdir -p ${build_dir_cxx} 86 87 build_cxx_protobuf_deb 88 } 89 90 build_cxx_protobuf_deb() { 91 version=3.3.0 92 deb_file=protobuf_$version-1_amd64.deb 93 94 if [[ -e $pkg_dir/$deb_file ]] 95 then 96 warn "Skipping $deb, already exists at $pkg_dir/$deb" 97 else 98 99 cd ${build_dir_cxx} 100 101 export DEBEMAIL="distributedledger@intel.com" 102 export DEBFULLNAME="Hyperledger Sawtooth" 103 104 # skip the fetch if we have the file 105 if [[ ! -e v$version.tar.gz ]]; then 106 wget https://github.com/google/protobuf/archive/v$version.tar.gz 107 fi 108 tar zxvf v$version.tar.gz 109 110 cd protobuf-$version 111 112 ./autogen.sh 113 ./configure --enable-deb 114 make dist 115 116 # skip the debian dir creation (dh_make gets cranky if it already exists) 117 if [[ ! -e debian ]]; then 118 dh_make -s -y -f protobuf-$version.tar.gz 119 fi 120 dpkg-buildpackage -B 121 122 cp ../$deb_file $pkg_dir 123 fi 124 } 125 126 build_python_debs() { 127 128 info "Building debs needed by the Sawtooth Validator and Python SDK" 129 130 build_dir_python=${build_dir}/python 131 mkdir -p $build_dir_python 132 cd ${build_dir_python} 133 134 # WARNING: Order is important 135 pip_pkgs=' 136 pycares==2.1.1 137 aiodns==1.1.1 138 cchardet==2.0a3 139 multidict==2.1.4 140 async_timeout==1.2.0 141 yarl==0.10.0 142 aiohttp 143 grpcio==1.1.3 144 protobuf==3.2.0 145 six==1.10.0 146 grpcio-tools==1.1.3 147 bitcoin==1.1.42 148 setuptools_scm==1.15.0 149 pytest-runner==2.6.2 150 secp256k1==0.13.2 151 cryptography-vectors==1.7.2 152 pytz==2016.10 153 pytest==2.9.0 154 cryptography==1.7.2 155 lmdb==0.92 156 pyformance==0.4 157 ' 158 159 # secp256k1 needs a couple of libraries not readily available 160 libsecp256k1_debs=' 161 libsecp256k1-0_0.1~20161228-1_amd64.deb 162 libsecp256k1-dev_0.1~20161228-1_amd64.deb 163 ' 164 165 # Download and install additional secp256k dependencies 166 info "Downloading and installing libsecp256k1 debs" 167 for deb in $libsecp256k1_debs; do 168 if [[ -e $pkg_dir/$deb ]] 169 then 170 warn "Skipping $deb, already exists at $pkg_dir/$deb" 171 else 172 wget http://ftp.br.debian.org/debian/pool/main/libs/libsecp256k1/$deb 173 dpkg -i $deb 174 mv $deb $pkg_dir 175 fi 176 done 177 178 info "Installing all pip packages for building" 179 pip3 install $pip_pkgs 180 181 for pkg in $pip_pkgs; do 182 package_python_deb $pkg 183 done 184 185 info "Uninstalling packages installed by pip" 186 pip3 uninstall -y $pip_pkgs 187 188 info "Done building packages" 189 echo $(ls -1 $pkg_dir/*.deb) 190 } 191 192 info() { 193 echo -e "\033[0;36m\n[--- $1 ---]\n\033[0m" 194 } 195 196 warn() { 197 echo -e "\033[0;31m\n[--- $1 ---]\n\033[0m" 198 } 199 200 package_python_deb() { 201 cd ${build_dir_python} 202 203 pip_pkg_name=$1 204 tar_pkg_name=$(echo "$pip_pkg_name" | \ 205 sed -e 's/==.*//' \ 206 -e 's/async_/async-/' \ 207 -e 's/cryptography-/cryptography_/') 208 209 deb_pkg_name=$(echo "$tar_pkg_name" | \ 210 sed -e 's/setuptools_/setuptools-/' \ 211 -e 's/cryptography_/cryptography-/') 212 213 if [ -z $(find $pkg_dir -name "python3-$deb_pkg_name\_*.deb") ] 214 then 215 info "Downloading source code for $pip_pkg_name" 216 pip3 download --no-binary :all: \ 217 --disable-pip-version-check \ 218 --no-deps $pip_pkg_name 219 220 tarball=$tar_pkg_name*.tar.gz 221 info "Extracting $tarball" 222 tar xfz $tarball; 223 224 rm -f $tarball 225 226 info "Building $deb_pkg_name deb" 227 # Remove version fixing and fix async-timeout inconsistency 228 229 cd ${build_dir_python}/$tar_pkg_name* 230 231 # Arcane wizadry to get protobuf to build right 232 if [ $tar_pkg_name = 'protobuf' ]; then 233 # Grab protoc and .proto files expected by protobuf 234 wget https://github.com/google/protobuf/releases/download/v3.2.0/protoc-3.2.0-linux-x86_64.zip 235 236 # Unpack and relocate 237 mkdir src 238 unzip protoc-3.2.0-linux-x86_64.zip -d src 239 mv src/include/* src/ && mv src/bin/* src/ 240 241 # Patch bad relative paths 242 sed 's/\.\.\/src/\.\.\/\.\.\/src/' < setup.py > patch.py && mv patch.py setup.py 243 fi 244 245 # This test is failing, so we need to skip it. 246 if [ $tar_pkg_name == 'pyformance' ]; then 247 rm ./tests/test__syslog_reporter.py 248 fi 249 250 # Build the package 251 python3 setup.py --command-packages=stdeb.command bdist_deb 252 info "Finished building $deb_pkg_name deb" 253 254 info "Installing $deb_pkg_name deb" 255 # Install the package 256 dpkg -i deb_dist/*.deb 257 258 info "Saving $deb_pkg_name deb to $pkg_dir" 259 # Save the package 260 cp deb_dist/*.deb $pkg_dir 261 else 262 warn "Skipping $deb_pkg_name, already exists in $pkg_dir" 263 fi 264 265 } 266 267 main