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