build_setup.sh 1.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041
  1. #!/bin/bash
  2. # Configure environment variables for Bazel build and test.
  3. set -e
  4. [ -z "${NUM_CPUS}" ] && NUM_CPUS=`grep -c ^processor /proc/cpuinfo`
  5. export ENVOY_SRCDIR=/source
  6. export BUILD_DIR=/build
  7. mkdir -p ${BUILD_DIR}
  8. # Create a fake home. Python site libs tries to do getpwuid(3) if we don't and
  9. # the CI Docker image gets confused as it has no passwd entry when running
  10. # non-root unless we do this.
  11. FAKE_HOME=/tmp/fake_home
  12. mkdir -p "${FAKE_HOME}"
  13. export HOME="${FAKE_HOME}"
  14. export PYTHONUSERBASE="${FAKE_HOME}"
  15. # Environment setup.
  16. export USER=bazel
  17. export TEST_TMPDIR=/build/tmp
  18. export BAZEL="bazel"
  19. # Not sandboxing, since non-privileged Docker can't do nested namespaces.
  20. BAZEL_OPTIONS="--package_path %workspace%:/source"
  21. export BAZEL_QUERY_OPTIONS="${BAZEL_OPTIONS}"
  22. export BAZEL_BUILD_OPTIONS="--strategy=Genrule=standalone --spawn_strategy=standalone \
  23. --verbose_failures ${BAZEL_OPTIONS} --jobs=${NUM_CPUS} \
  24. --action_env=HOME --action_env=PYTHONUSERBASE"
  25. export BAZEL_TEST_OPTIONS="${BAZEL_BUILD_OPTIONS} --cache_test_results=no --test_output=all --test_env=HOME --test_env=PYTHONUSERBASE"
  26. [[ "${BAZEL_EXPUNGE}" == "1" ]] && "${BAZEL}" clean --expunge
  27. function cleanup() {
  28. # Remove build artifacts. This doesn't mess with incremental builds as these
  29. # are just symlinks.
  30. rm -f "${ENVOY_SRCDIR}"/bazel-*
  31. }
  32. trap cleanup EXIT