github.com/alwaysproblem/mlserving-tutorial@v0.0.0-20221124033215-121cfddbfbf4/TFserving/CustomOp/custom-op/build_pip_pkg.sh (about)

     1  #!/usr/bin/env bash
     2  # Copyright 2018 The TensorFlow Authors. All Rights Reserved.
     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  set -e
    17  set -x
    18  
    19  PLATFORM="$(uname -s | tr 'A-Z' 'a-z')"
    20  function is_windows() {
    21    if [[ "${PLATFORM}" =~ (cygwin|mingw32|mingw64|msys)_nt* ]]; then
    22      true
    23    else
    24      false
    25    fi
    26  }
    27  
    28  if is_windows; then
    29    PIP_FILE_PREFIX="bazel-bin/build_pip_pkg.exe.runfiles/__main__/"
    30  else
    31    PIP_FILE_PREFIX="bazel-bin/build_pip_pkg.runfiles/__main__/"
    32  fi
    33  
    34  function main() {
    35    while [[ ! -z "${1}" ]]; do
    36      if [[ ${1} == "make" ]]; then
    37        echo "Using Makefile to build pip package."
    38        PIP_FILE_PREFIX=""
    39      else
    40        DEST=${1}
    41      fi
    42      shift
    43    done
    44  
    45    if [[ -z ${DEST} ]]; then
    46      echo "No destination dir provided"
    47      exit 1
    48    fi
    49  
    50    # Create the directory, then do dirname on a non-existent file inside it to
    51    # give us an absolute paths with tilde characters resolved to the destination
    52    # directory.
    53    mkdir -p ${DEST}
    54    if [[ ${PLATFORM} == "darwin" ]]; then
    55      DEST=$(pwd -P)/${DEST}
    56    else
    57      DEST=$(readlink -f "${DEST}")
    58    fi
    59    echo "=== destination directory: ${DEST}"
    60  
    61    TMPDIR=$(mktemp -d -t tmp.XXXXXXXXXX)
    62  
    63    echo $(date) : "=== Using tmpdir: ${TMPDIR}"
    64  
    65    echo "=== Copy TensorFlow Custom op files"
    66  
    67    cp ${PIP_FILE_PREFIX}setup.py "${TMPDIR}"
    68    cp ${PIP_FILE_PREFIX}MANIFEST.in "${TMPDIR}"
    69    cp ${PIP_FILE_PREFIX}LICENSE "${TMPDIR}"
    70    # rsync -avm -L --exclude='*_test.py' ${PIP_FILE_PREFIX}tensorflow_zero_out "${TMPDIR}"
    71    # rsync -avm -L --exclude='*_test.py' ${PIP_FILE_PREFIX}tensorflow_time_two "${TMPDIR}"
    72    rsync -avm -L --exclude='*_test.py' ${PIP_FILE_PREFIX}add_index "${TMPDIR}"
    73  
    74    pushd ${TMPDIR}
    75    echo $(date) : "=== Building wheel"
    76  
    77    python3 setup.py bdist_wheel > /dev/null
    78  
    79    cp dist/*.whl "${DEST}"
    80    popd
    81    rm -rf ${TMPDIR}
    82    echo $(date) : "=== Output wheel file is in: ${DEST}"
    83  }
    84  
    85  main "$@"