github.com/muhammedhassanm/blockchain@v0.0.0-20200120143007-697261defd4d/sawtooth-core-master/bin/build_debs (about)

     1  #!/bin/bash
     2  #
     3  # Copyright 2016, 2017 Intel Corporation
     4  #
     5  # Licensed under the Apache License, Version 2.0 (the "License");
     6  # you may not use this file except in compliance with the License.
     7  # You may obtain a copy of the License at
     8  #
     9  #     http://www.apache.org/licenses/LICENSE-2.0
    10  #
    11  # Unless required by applicable law or agreed to in writing, software
    12  # distributed under the License is distributed on an "AS IS" BASIS,
    13  # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
    14  # See the License for the specific language governing permissions and
    15  # limitations under the License.
    16  # ------------------------------------------------------------------------------
    17  
    18  set -e
    19  
    20  main() {
    21      top_dir=$(cd $(dirname $(dirname $0)) && pwd)
    22  
    23      # 1. Create tmp directory
    24  
    25      build_dir=/tmp/build-debs
    26      rm -rf $build_dir
    27      mkdir -p $build_dir
    28  
    29      # 2. Copy to tmp
    30      info "Copying source to temp build dir"
    31  
    32      rsync -aH \
    33          --exclude="build" \
    34          --exclude="target" \
    35          --exclude="node-modules" \
    36          --exclude="*.pyc" \
    37          --exclude="*.swp" \
    38          --exclude="*_pb2.py" \
    39          --exclude="__pycache__" \
    40          $top_dir/ \
    41          $build_dir/
    42  
    43      # 3. Run protogen
    44      info "Building protobuf classes"
    45      $build_dir/bin/protogen
    46  
    47      case "$1" in
    48          python)
    49              build_python
    50              ;;
    51          go)
    52              build_go
    53              ;;
    54          rust)
    55              build_rust
    56              ;;
    57          cxx)
    58              build_cxx
    59              ;;
    60          *)
    61              echo "Building all packages"
    62              build_python
    63              build_go
    64              build_rust
    65              build_cxx
    66              ;;
    67      esac
    68  }
    69  
    70  build_python() {
    71      echo "Building python packages"
    72  
    73      pkg_dir=$top_dir/build/debs/python
    74      mkdir -p $pkg_dir
    75      rm -f $pkg_dir/*.deb
    76  
    77      # Group 1: No internal dependencies
    78      build_python_pkg "signing"
    79  
    80      pypath=$build_dir/consensus/poet/common
    81      pypath=$pypath:$build_dir/consensus/poet/common/tests
    82      build_python_pkg "consensus/poet/common"  $pypath
    83  
    84      build_python_pkg "utility/ias_client"
    85  
    86      # Group 2: Depends only on 1
    87      build_python_pkg "sdk/python" "$build_dir/sdk/python"
    88  
    89      build_python_pkg "cli"
    90  
    91      # Group 3: Depends on 1 & 2
    92      build_python_pkg "families/settings"
    93  
    94      build_python_pkg "families/identity"
    95  
    96      build_python_pkg "families/block_info"
    97  
    98      build_python_pkg "rest_api"
    99  
   100      build_python_pkg "sdk/examples/intkey_python"
   101  
   102      build_python_pkg "sdk/examples/xo_python"
   103  
   104      build_python_pkg "validator" "$build_dir/signing"
   105  
   106      pypath=$build_dir/integration
   107      pypath=$pypath:$build_dir/sdk/python
   108      pypath=$pypath:$build_dir/signing
   109      pypath=$pypath:$build_dir/consensus/poet/common
   110      pypath=$pypath:$build_dir/consensus/poet/families
   111      pypath=$pypath:$build_dir/consensus/poet/families/tests
   112      build_python_pkg "consensus/poet/families" $pypath
   113  
   114      # Group 4: Depends on 1, 2, & 3
   115      pypath=$build_dir/signing
   116      pypath=$pypath:$build_dir/validator
   117      pypath=$pypath:$build_dir/consensus/poet/common
   118      pypath=$pypath:$build_dir/consensus/poet/core
   119      pypath=$pypath:$build_dir/consensus/poet/families
   120      pypath=$pypath:$build_dir/consensus/poet/families/tests
   121      build_python_pkg "consensus/poet/simulator" $pypath
   122  
   123      pypath=$build_dir/signing
   124      pypath=$pypath:$build_dir/validator
   125      pypath=$pypath:$build_dir/consensus/poet/common
   126      pypath=$pypath:$build_dir/consensus/poet/common/tests
   127      pypath=$pypath:$build_dir/consensus/poet/core
   128      pypath=$pypath:$build_dir/consensus/poet/core/tests
   129      pypath=$pypath:$build_dir/consensus/poet/simulator
   130      build_python_pkg "consensus/poet/core" $pypath
   131  
   132      pypath=$build_dir/sdk/python
   133      pypath=$pypath:$build_dir/utility/ias_client
   134      build_python_pkg "utility/ias_proxy" $pypath
   135  
   136      # Group 5: Depends on 1-4
   137      build_python_pkg "consensus/poet/cli" $pypath
   138  
   139      # Group 6: PoET
   140      # No dependencies on anything above, builds last for simplicity
   141      if [ -z ${POET_ENCLAVE_PEM+x} ];
   142      then
   143          export POET_ENCLAVE_PEM=/tmp/sgxsdk/SampleCode/SampleEnclave/Enclave/Enclave_private.pem
   144      fi
   145  
   146      export SGXSDKInstallPath=/tmp/sgxsdk/
   147  
   148      SAWTOOTH_CORE=/project/sawtooth-core
   149      SAWTOOTH_POET=/project/sawtooth-core/consensus/poet/sgx
   150  
   151      PATH=$PATH:$SAWTOOTH_CORE/bin
   152      export PATH
   153      export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:$SAWTOOTH_POET
   154  
   155      build_python_pkg "consensus/poet/sgx"
   156  
   157      # Build the meta-package
   158      VERSION=$($top_dir/bin/get_version)
   159      cd $top_dir/ci
   160      sed -i -e"s/@VERSION@/$VERSION/" ns-control
   161      equivs-build ns-control
   162      sed -i -e"s/$VERSION/@VERSION@/" ns-control
   163      mv sawtooth*.deb $pkg_dir/
   164  
   165      # Copy the packages to the output directory
   166      find $build_dir -name python3-sawtooth*.deb -exec cp {} $pkg_dir/ \;
   167  
   168      for pkg in $pkg_dir/*.deb
   169      do
   170          echo
   171          info "Package $pkg"
   172          dpkg -I $pkg
   173      done
   174  }
   175  
   176  info() {
   177      echo -e "\033[0;35m\n[--- $1 ---]\n\033[0m"
   178  }
   179  
   180  build_go() {
   181      echo "Building go packages"
   182  
   183      pkg_dir=$top_dir/build/debs/go
   184      mkdir -p $pkg_dir
   185      rm -f $pkg_dir/*.deb
   186  
   187      info "smallbank_go"
   188      build_go_pkg smallbank
   189      info "intkey_go"
   190      build_go_pkg intkey_go
   191      info "noop_go"
   192      build_go_pkg noop_go
   193      info "xo_go"
   194      build_go_pkg xo_go
   195  
   196      for pkg in $pkg_dir/*.deb
   197      do
   198          echo
   199          info "Package $pkg"
   200          dpkg -I $pkg
   201      done
   202  
   203  }
   204  
   205  build_rust() {
   206      echo "Building rust packages"
   207  
   208      output_dir=$top_dir/build/debs/rust
   209      mkdir -p $output_dir
   210      rm -f $output_dir/*.deb
   211  
   212      info "sawadm"
   213      build_rust_pkg sawadm $top_dir/adm $output_dir
   214  
   215      info "smallbank-workload"
   216      build_rust_pkg smallbank-workload $top_dir/perf/smallbank_workload $output_dir
   217  
   218      info "intkey-workload"
   219      build_rust_pkg intkey-workload $top_dir/perf/intkey_workload $output_dir
   220  
   221      for pkg in $output_dir/*.deb
   222      do
   223          echo
   224          info "Package $pkg"
   225          dpkg -I $pkg
   226      done
   227  }
   228  
   229  build_go_pkg(){
   230  
   231      pkg_dir=$top_dir/build/debs/go
   232      pkg=$1
   233      GO_TP_DASH=$(echo $pkg | sed s/_/-/)
   234      CHANGELOG_DIR="debian/usr/share/doc/sawtooth-tp-$GO_TP_DASH"
   235      ST_VERSION=$($top_dir/bin/get_version)
   236  
   237      if [ $pkg == "smallbank" ];
   238      then
   239          cd $build_dir/families/smallbank/smallbank_go
   240      else
   241          cd $build_dir/sdk/examples/$pkg
   242      fi
   243  
   244      if [ -d "debian" ]
   245      then
   246          rm -rf debian
   247      fi
   248  
   249      mkdir -p debian/DEBIAN
   250  
   251      mkdir -p $CHANGELOG_DIR
   252      cp packaging/ubuntu/* debian
   253      sed -i -e"s/@VERSION@/$ST_VERSION/" debian/control
   254      sed -i -e"s/@VERSION@/$ST_VERSION/" debian/changelog
   255      cp debian/changelog $CHANGELOG_DIR
   256      mv debian/changelog $CHANGELOG_DIR/changelog.Debian
   257      gzip --best $CHANGELOG_DIR/changelog
   258      gzip --best $CHANGELOG_DIR/changelog.Debian
   259      mv debian/control debian/DEBIAN
   260      mv debian/postinst debian/DEBIAN
   261  
   262      PACKAGENAME=$(awk '/^Package:/ { print $2 }' debian/DEBIAN/control)
   263      PACKAGEVERSION=$(dpkg-parsechangelog -S version -l $CHANGELOG_DIR/changelog.gz)
   264      PACKAGEARCH=$(dpkg-architecture -qDEB_BUILD_ARCH)
   265  
   266      mkdir debian/usr/bin
   267      cp -R bin/ debian/usr/
   268      cp -R packaging/systemd/* debian/
   269  
   270  
   271      fakeroot dpkg-deb --build debian
   272      echo --
   273      echo "${PACKAGENAME}_${PACKAGEVERSION}_${PACKAGEARCH}.deb"
   274      echo --
   275      mv debian.deb $pkg_dir/"${PACKAGENAME}_${PACKAGEVERSION}_${PACKAGEARCH}.deb"
   276  }
   277  
   278  build_rust_pkg(){
   279      pkg=$1
   280      pkg_dir=$2
   281      output_dir=$3
   282  
   283      # GO_TP_DASH=$(echo $pkg | sed s/_/-/)
   284      CHANGELOG_DIR="debian/usr/share/doc/$pkg"
   285      ST_VERSION=$($top_dir/bin/get_version)
   286  
   287      cd $pkg_dir
   288  
   289      if [ -d "debian" ]
   290      then
   291          rm -rf debian
   292      fi
   293  
   294      mkdir -p debian/DEBIAN
   295  
   296      mkdir -p $CHANGELOG_DIR
   297      cp packaging/ubuntu/* debian
   298      sed -i -e"s/@VERSION@/$ST_VERSION/" debian/control
   299      sed -i -e"s/@VERSION@/$ST_VERSION/" debian/changelog
   300      cp debian/changelog $CHANGELOG_DIR
   301      mv debian/changelog $CHANGELOG_DIR/changelog.Debian
   302      gzip --best $CHANGELOG_DIR/changelog
   303      gzip --best $CHANGELOG_DIR/changelog.Debian
   304      mv debian/control debian/DEBIAN
   305      if [ -e debian/postinst ]; then
   306          mv debian/postinst debian/DEBIAN
   307      fi
   308  
   309      PACKAGENAME=$(awk '/^Package:/ { print $2 }' debian/DEBIAN/control)
   310      PACKAGEVERSION=$(dpkg-parsechangelog -S version -l $CHANGELOG_DIR/changelog.gz)
   311      PACKAGEARCH=$(dpkg-architecture -qDEB_BUILD_ARCH)
   312  
   313      mkdir debian/usr/bin
   314      cp -R bin/ debian/usr/
   315  
   316      fakeroot dpkg-deb --build debian
   317      echo --
   318      echo "${PACKAGENAME}_${PACKAGEVERSION}_${PACKAGEARCH}.deb"
   319      echo --
   320      mv debian.deb $output_dir/"${PACKAGENAME}_${PACKAGEVERSION}_${PACKAGEARCH}.deb"
   321  }
   322  
   323  build_python_pkg() {
   324      pkg=$1
   325      pypath=$2
   326  
   327      info "Building $pkg"
   328  
   329      # 1. Set PYTHONPATH required for unit tests
   330      export PYTHONPATH=$pypath
   331  
   332      cd $build_dir/$pkg
   333  
   334      # 2. Cleanup previous builds
   335      if [ -d "debian" ]
   336      then
   337          rm -rf debian
   338      fi
   339      python3 setup.py clean --all
   340  
   341  
   342      # 2. Build the package
   343      python3 setup.py --command-packages=stdeb.command debianize
   344  
   345      if [ -d "packaging/ubuntu" ]
   346      then
   347          cp -R packaging/ubuntu/* debian/
   348      fi
   349  
   350      dpkg-buildpackage -b -rfakeroot -us -uc
   351  
   352      # 3. Install the package
   353      mv ../*.deb ./
   354      dpkg -i *.deb
   355  
   356      unset PYTHONPATH
   357  }
   358  
   359  
   360  build_cxx() {
   361      echo "Building cxx packages"
   362  
   363      pkg_dir=$top_dir/build/debs/cxx
   364      mkdir -p $pkg_dir
   365      rm -f $pkg_dir/*.deb
   366  
   367      cp $top_dir/sdk/cxx/build/*.deb $pkg_dir
   368  
   369      for pkg in $pkg_dir/*.deb
   370      do
   371          echo
   372          info "Package $pkg"
   373          dpkg -I $pkg
   374      done
   375  
   376  }
   377  
   378  main "$@"