build_artifact_python.sh 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596
  1. #!/bin/bash
  2. # Copyright 2016, Google Inc.
  3. # All rights reserved.
  4. #
  5. # Redistribution and use in source and binary forms, with or without
  6. # modification, are permitted provided that the following conditions are
  7. # met:
  8. #
  9. # * Redistributions of source code must retain the above copyright
  10. # notice, this list of conditions and the following disclaimer.
  11. # * Redistributions in binary form must reproduce the above
  12. # copyright notice, this list of conditions and the following disclaimer
  13. # in the documentation and/or other materials provided with the
  14. # distribution.
  15. # * Neither the name of Google Inc. nor the names of its
  16. # contributors may be used to endorse or promote products derived from
  17. # this software without specific prior written permission.
  18. #
  19. # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
  20. # "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
  21. # LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
  22. # A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
  23. # OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
  24. # SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
  25. # LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
  26. # DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
  27. # THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
  28. # (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
  29. # OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  30. set -ex
  31. cd $(dirname $0)/../../..
  32. export GRPC_PYTHON_USE_CUSTOM_BDIST=0
  33. export GRPC_PYTHON_BUILD_WITH_CYTHON=1
  34. export PYTHON=${PYTHON:-python}
  35. export PIP=${PIP:-pip}
  36. export AUDITWHEEL=${AUDITWHEEL:-auditwheel}
  37. mkdir -p "${ARTIFACTS_OUT}"
  38. ARTIFACT_DIR="$PWD/${ARTIFACTS_OUT}"
  39. # Build the source distribution first because MANIFEST.in cannot override
  40. # exclusion of built shared objects among package resources (for some
  41. # inexplicable reason).
  42. ${SETARCH_CMD} ${PYTHON} setup.py sdist
  43. # Wheel has a bug where directories don't get excluded.
  44. # https://bitbucket.org/pypa/wheel/issues/99/cannot-exclude-directory
  45. ${SETARCH_CMD} ${PYTHON} setup.py bdist_wheel
  46. # Build gRPC tools package distribution
  47. ${PYTHON} tools/distrib/python/make_grpcio_tools.py
  48. # Build gRPC tools package source distribution
  49. ${SETARCH_CMD} ${PYTHON} tools/distrib/python/grpcio_tools/setup.py sdist
  50. # Build gRPC tools package binary distribution
  51. ${SETARCH_CMD} ${PYTHON} tools/distrib/python/grpcio_tools/setup.py bdist_wheel
  52. if [ "$GRPC_BUILD_MANYLINUX_WHEEL" != "" ]
  53. then
  54. for wheel in dist/*.whl; do
  55. ${AUDITWHEEL} repair $wheel -w "$ARTIFACT_DIR"
  56. rm $wheel
  57. done
  58. for wheel in tools/distrib/python/grpcio_tools/dist/*.whl; do
  59. ${AUDITWHEEL} repair $wheel -w "$ARTIFACT_DIR"
  60. rm $wheel
  61. done
  62. fi
  63. # We need to use the built grpcio-tools/grpcio to compile the health proto
  64. # Wheels are not supported by setup_requires/dependency_links, so we
  65. # manually install the dependency. Note we should only do this if we
  66. # are in a docker image or in a virtualenv.
  67. if [ "$GRPC_BUILD_GRPCIO_TOOLS_DEPENDENTS" != "" ]
  68. then
  69. ${PIP} install -rrequirements.txt
  70. ${PIP} install grpcio --no-index --find-links "file://$ARTIFACT_DIR/"
  71. ${PIP} install grpcio-tools --no-index --find-links "file://$ARTIFACT_DIR/"
  72. # Build gRPC health-checking source distribution
  73. ${SETARCH_CMD} ${PYTHON} src/python/grpcio_health_checking/setup.py \
  74. preprocess build_package_protos sdist
  75. cp -r src/python/grpcio_health_checking/dist/* "$ARTIFACT_DIR"
  76. # Build gRPC reflection source distribution
  77. ${SETARCH_CMD} ${PYTHON} src/python/grpcio_reflection/setup.py \
  78. preprocess build_package_protos sdist
  79. cp -r src/python/grpcio_reflection/dist/* "$ARTIFACT_DIR"
  80. fi
  81. cp -r dist/* "$ARTIFACT_DIR"
  82. cp -r tools/distrib/python/grpcio_tools/dist/* "$ARTIFACT_DIR"