blob: 49988fa298f0db02aea25958232d5988c4615ec7 [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)
Colin Cross92ac46d2025-02-26 19:25:23 -080026 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
Dan Willemsen0df15172017-05-07 11:23:59 -070034 ;;
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
Dan Willemsen1b822862017-07-12 15:00:05 -070049 out_dir="out"
Dan Willemsen0df15172017-05-07 11:23:59 -070050 fi
51 fi
Dan Willemsen1b822862017-07-12 15:00:05 -070052 if [[ "${out_dir}" != /* ]]; then
53 out_dir="${TOP}/${out_dir}"
54 fi
Dan Willemsen0df15172017-05-07 11:23:59 -070055 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
Dan Willemsen91f9b542017-07-18 19:39:34 -070064function soong_build_go
Dan Willemsen0df15172017-05-07 11:23:59 -070065{
Dan Willemsen91f9b542017-07-18 19:39:34 -070066 BUILDDIR=$(getoutdir) \
67 SRCDIR=${TOP} \
68 BLUEPRINTDIR=${TOP}/build/blueprint \
Chris Parsons4d0b4df2022-10-18 20:53:11 -040069 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 -070070 build_go $@
Dan Willemsen0df15172017-05-07 11:23:59 -070071}
Dan Willemsen91f9b542017-07-18 19:39:34 -070072
73source ${TOP}/build/blueprint/microfactory/microfactory.bash