blob: ce4a0e48ab31b445bbe91f302e05ce86f7e24db2 [file] [log] [blame]
Dan Willemsen0df15172017-05-07 11:23:59 -07001# 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
Dan Willemsen1b822862017-07-12 15:00:05 -070042 out_dir="out"
Dan Willemsen0df15172017-05-07 11:23:59 -070043 fi
44 fi
Dan Willemsen1b822862017-07-12 15:00:05 -070045 if [[ "${out_dir}" != /* ]]; then
46 out_dir="${TOP}/${out_dir}"
47 fi
Dan Willemsen0df15172017-05-07 11:23:59 -070048 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 Willemsen91f9b542017-07-18 19:39:34 -070057function soong_build_go
Dan Willemsen0df15172017-05-07 11:23:59 -070058{
Dan Willemsen91f9b542017-07-18 19:39:34 -070059 BUILDDIR=$(getoutdir) \
60 SRCDIR=${TOP} \
61 BLUEPRINTDIR=${TOP}/build/blueprint \
Chris Parsons4d0b4df2022-10-18 20:53:11 -040062 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 Willemsen91f9b542017-07-18 19:39:34 -070063 build_go $@
Dan Willemsen0df15172017-05-07 11:23:59 -070064}
Dan Willemsen91f9b542017-07-18 19:39:34 -070065
66source ${TOP}/build/blueprint/microfactory/microfactory.bash