• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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# ==============================================================================
16set -ex
17
18SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
19PYTHON="${PYTHON:-python3}"
20VERSION_SUFFIX=${VERSION_SUFFIX:-}
21export TENSORFLOW_DIR="${SCRIPT_DIR}/../../../.."
22TENSORFLOW_LITE_DIR="${TENSORFLOW_DIR}/tensorflow/lite"
23TENSORFLOW_VERSION=$(grep "_VERSION = " "${TENSORFLOW_DIR}/tensorflow/tools/pip_package/setup.py" | cut -d= -f2 | sed "s/[ '-]//g")
24export PACKAGE_VERSION="${TENSORFLOW_VERSION}${VERSION_SUFFIX}"
25BUILD_DIR="${SCRIPT_DIR}/gen/tflite_pip/${PYTHON}"
26
27# Build source tree.
28rm -rf "${BUILD_DIR}" && mkdir -p "${BUILD_DIR}/tflite_runtime"
29cp -r "${TENSORFLOW_LITE_DIR}/tools/pip_package/debian" \
30      "${TENSORFLOW_LITE_DIR}/tools/pip_package/setup.py" \
31      "${TENSORFLOW_LITE_DIR}/tools/pip_package/MANIFEST.in" \
32      "${TENSORFLOW_LITE_DIR}/python/interpreter_wrapper" \
33      "${BUILD_DIR}"
34cp "${TENSORFLOW_LITE_DIR}/python/interpreter.py" \
35   "${BUILD_DIR}/tflite_runtime"
36echo "__version__ = '${PACKAGE_VERSION}'" >> "${BUILD_DIR}/tflite_runtime/__init__.py"
37echo "__git_version__ = '$(git -C "${TENSORFLOW_DIR}" describe)'" >> "${BUILD_DIR}/tflite_runtime/__init__.py"
38
39# Build python wheel.
40cd "${BUILD_DIR}"
41case "${TENSORFLOW_TARGET}" in
42  rpi)
43    ${PYTHON} setup.py bdist --plat-name=linux-armv7l \
44                       bdist_wheel --plat-name=linux-armv7l
45    ;;
46  aarch64)
47    ${PYTHON} setup.py bdist --plat-name=linux-aarch64 \
48                       bdist_wheel --plat-name=linux-aarch64
49    ;;
50  *)
51    if [[ -n "${TENSORFLOW_TARGET}" ]] && [[ -n "${TENSORFLOW_TARGET_ARCH}" ]]; then
52      ${PYTHON} setup.py bdist --plat-name=${TENSORFLOW_TARGET}-${TENSORFLOW_TARGET_ARCH} \
53                         bdist_wheel --plat-name=${TENSORFLOW_TARGET}-${TENSORFLOW_TARGET_ARCH}
54    else
55      ${PYTHON} setup.py bdist bdist_wheel
56    fi
57    ;;
58esac
59
60# Build debian package.
61if [[ "${BUILD_DEB}" != "y" ]]; then
62  exit 0
63fi
64
65PYTHON_VERSION=$(${PYTHON} -c "import sys;print(sys.version_info.major)")
66if [[ ${PYTHON_VERSION} != 3 ]]; then
67  echo "Debian package can only be generated for python3." >&2
68  exit 1
69fi
70
71DEB_VERSION=$(dpkg-parsechangelog --show-field Version | cut -d- -f1)
72if [[ "${DEB_VERSION}" != "${PACKAGE_VERSION}" ]]; then
73  cat << EOF > "${BUILD_DIR}/debian/changelog"
74tflite-runtime (${PACKAGE_VERSION}-1) unstable; urgency=low
75
76  * Bump version to ${PACKAGE_VERSION}.
77
78 -- TensorFlow team <packages@tensorflow.org>  $(date -R)
79
80$(<"${BUILD_DIR}/debian/changelog")
81EOF
82fi
83
84case "${TENSORFLOW_TARGET}" in
85  rpi)
86    dpkg-buildpackage -b -rfakeroot -us -uc -tc -d -a armhf
87    ;;
88  aarch64)
89    dpkg-buildpackage -b -rfakeroot -us -uc -tc -d -a arm64
90    ;;
91  *)
92    dpkg-buildpackage -b -rfakeroot -us -uc -tc -d
93    ;;
94esac
95
96cat "${BUILD_DIR}/debian/changelog"
97