microfactory.bash 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566
  1. # Copyright 2017 Google Inc. All rights reserved.
  2. #
  3. # Licensed under the Apache License, Version 2.0 (the "License");
  4. # you may not use this file except in compliance with the License.
  5. # You may obtain a copy of the License at
  6. #
  7. # http://www.apache.org/licenses/LICENSE-2.0
  8. #
  9. # Unless required by applicable law or agreed to in writing, software
  10. # distributed under the License is distributed on an "AS IS" BASIS,
  11. # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  12. # See the License for the specific language governing permissions and
  13. # limitations under the License.
  14. # Set of utility functions to build and run go code with microfactory
  15. #
  16. # Inputs:
  17. # ${TOP}: The top of the android source tree
  18. # ${OUT_DIR}: The output directory location (defaults to ${TOP}/out)
  19. # ${OUT_DIR_COMMON_BASE}: Change the default out directory to
  20. # ${OUT_DIR_COMMON_BASE}/$(basename ${TOP})
  21. # Ensure GOROOT is set to the in-tree version.
  22. case $(uname) in
  23. Linux)
  24. export GOROOT="${TOP}/prebuilts/go/linux-x86/"
  25. ;;
  26. Darwin)
  27. export GOROOT="${TOP}/prebuilts/go/darwin-x86/"
  28. ;;
  29. *) echo "unknown OS:" $(uname) >&2 && exit 1;;
  30. esac
  31. # Find the output directory
  32. function getoutdir
  33. {
  34. local out_dir="${OUT_DIR-}"
  35. if [ -z "${out_dir}" ]; then
  36. if [ "${OUT_DIR_COMMON_BASE-}" ]; then
  37. out_dir="${OUT_DIR_COMMON_BASE}/$(basename ${TOP})"
  38. else
  39. out_dir="out"
  40. fi
  41. fi
  42. if [[ "${out_dir}" != /* ]]; then
  43. out_dir="${TOP}/${out_dir}"
  44. fi
  45. echo "${out_dir}"
  46. }
  47. # Bootstrap microfactory from source if necessary and use it to build the
  48. # requested binary.
  49. #
  50. # Arguments:
  51. # $1: name of the requested binary
  52. # $2: package name
  53. function soong_build_go
  54. {
  55. BUILDDIR=$(getoutdir) \
  56. SRCDIR=${TOP} \
  57. BLUEPRINTDIR=${TOP}/build/blueprint \
  58. EXTRA_ARGS="-pkg-path android/soong=${TOP}/build/soong -pkg-path prebuilts/bazel/common/proto=${TOP}/prebuilts/bazel/common/proto -pkg-path rbcrun=${TOP}/build/make/tools/rbcrun -pkg-path google.golang.org/protobuf=${TOP}/external/golang-protobuf -pkg-path go.starlark.net=${TOP}/external/starlark-go" \
  59. build_go $@
  60. }
  61. source ${TOP}/build/blueprint/microfactory/microfactory.bash