| Dan Willemsen | 0df1517 | 2017-05-07 11:23:59 -0700 | [diff] [blame] | 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 |  | 
 | 15 | # Set of utility functions to build and run go code with microfactory | 
 | 16 | # | 
 | 17 | # Inputs: | 
 | 18 | #  ${TOP}: The top of the android source tree | 
 | 19 | #  ${OUT_DIR}: The output directory location (defaults to ${TOP}/out) | 
 | 20 | #  ${OUT_DIR_COMMON_BASE}: Change the default out directory to | 
 | 21 | #    ${OUT_DIR_COMMON_BASE}/$(basename ${TOP}) | 
 | 22 |  | 
 | 23 | # Ensure GOROOT is set to the in-tree version. | 
 | 24 | case $(uname) in | 
 | 25 |     Linux) | 
 | 26 |         export GOROOT="${TOP}/prebuilts/go/linux-x86/" | 
 | 27 |         ;; | 
 | 28 |     Darwin) | 
 | 29 |         export GOROOT="${TOP}/prebuilts/go/darwin-x86/" | 
 | 30 |         ;; | 
 | 31 |     *) echo "unknown OS:" $(uname) >&2 && exit 1;; | 
 | 32 | esac | 
 | 33 |  | 
 | 34 | # Find the output directory | 
 | 35 | function getoutdir | 
 | 36 | { | 
 | 37 |     local out_dir="${OUT_DIR-}" | 
 | 38 |     if [ -z "${out_dir}" ]; then | 
 | 39 |         if [ "${OUT_DIR_COMMON_BASE-}" ]; then | 
 | 40 |             out_dir="${OUT_DIR_COMMON_BASE}/$(basename ${TOP})" | 
 | 41 |         else | 
| Dan Willemsen | 1b82286 | 2017-07-12 15:00:05 -0700 | [diff] [blame] | 42 |             out_dir="out" | 
| Dan Willemsen | 0df1517 | 2017-05-07 11:23:59 -0700 | [diff] [blame] | 43 |         fi | 
 | 44 |     fi | 
| Dan Willemsen | 1b82286 | 2017-07-12 15:00:05 -0700 | [diff] [blame] | 45 |     if [[ "${out_dir}" != /* ]]; then | 
 | 46 |         out_dir="${TOP}/${out_dir}" | 
 | 47 |     fi | 
| Dan Willemsen | 0df1517 | 2017-05-07 11:23:59 -0700 | [diff] [blame] | 48 |     echo "${out_dir}" | 
 | 49 | } | 
 | 50 |  | 
 | 51 | # Bootstrap microfactory from source if necessary and use it to build the | 
 | 52 | # requested binary. | 
 | 53 | # | 
 | 54 | # Arguments: | 
 | 55 | #  $1: name of the requested binary | 
 | 56 | #  $2: package name | 
| Dan Willemsen | 91f9b54 | 2017-07-18 19:39:34 -0700 | [diff] [blame] | 57 | function soong_build_go | 
| Dan Willemsen | 0df1517 | 2017-05-07 11:23:59 -0700 | [diff] [blame] | 58 | { | 
| Dan Willemsen | 91f9b54 | 2017-07-18 19:39:34 -0700 | [diff] [blame] | 59 |     BUILDDIR=$(getoutdir) \ | 
 | 60 |       SRCDIR=${TOP} \ | 
 | 61 |       BLUEPRINTDIR=${TOP}/build/blueprint \ | 
| Chris Parsons | 4d0b4df | 2022-10-18 20:53:11 -0400 | [diff] [blame] | 62 |       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" \ | 
| Dan Willemsen | 91f9b54 | 2017-07-18 19:39:34 -0700 | [diff] [blame] | 63 |       build_go $@ | 
| Dan Willemsen | 0df1517 | 2017-05-07 11:23:59 -0700 | [diff] [blame] | 64 | } | 
| Dan Willemsen | 91f9b54 | 2017-07-18 19:39:34 -0700 | [diff] [blame] | 65 |  | 
 | 66 | source ${TOP}/build/blueprint/microfactory/microfactory.bash |