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 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;; 32esac 33 34# Find the output directory 35function 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 42 out_dir="out" 43 fi 44 fi 45 if [[ "${out_dir}" != /* ]]; then 46 out_dir="${TOP}/${out_dir}" 47 fi 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 57function soong_build_go 58{ 59 BUILDDIR=$(getoutdir) \ 60 SRCDIR=${TOP} \ 61 BLUEPRINTDIR=${TOP}/build/blueprint \ 62 EXTRA_ARGS="-pkg-path android/soong=${TOP}/build/soong -pkg-path github.com/golang/protobuf=${TOP}/external/golang-protobuf" \ 63 build_go $@ 64} 65 66source ${TOP}/build/blueprint/microfactory/microfactory.bash 67