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. 24case $(uname) in 25 Linux) 26 case $(uname -m) in 27 x86_64) 28 export GOROOT="${TOP}/prebuilts/go/linux-x86/" 29 ;; 30 aarch64) 31 export GOROOT="${TOP}/prebuilts/go/linux-arm64/" 32 ;; 33 esac 34 ;; 35 Darwin) 36 export GOROOT="${TOP}/prebuilts/go/darwin-x86/" 37 ;; 38 *) echo "unknown OS:" $(uname) >&2 && exit 1;; 39esac 40 41# Find the output directory 42function getoutdir 43{ 44 local out_dir="${OUT_DIR-}" 45 if [ -z "${out_dir}" ]; then 46 if [ "${OUT_DIR_COMMON_BASE-}" ]; then 47 out_dir="${OUT_DIR_COMMON_BASE}/$(basename ${TOP})" 48 else 49 out_dir="out" 50 fi 51 fi 52 if [[ "${out_dir}" != /* ]]; then 53 out_dir="${TOP}/${out_dir}" 54 fi 55 echo "${out_dir}" 56} 57 58# Bootstrap microfactory from source if necessary and use it to build the 59# requested binary. 60# 61# Arguments: 62# $1: name of the requested binary 63# $2: package name 64function soong_build_go 65{ 66 BUILDDIR=$(getoutdir) \ 67 SRCDIR=${TOP} \ 68 BLUEPRINTDIR=${TOP}/build/blueprint \ 69 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" \ 70 build_go $@ 71} 72 73source ${TOP}/build/blueprint/microfactory/microfactory.bash 74