• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1#!/bin/bash -ex
2#
3# Copyright (C) 2021 The Android Open Source Project
4#
5# Licensed under the Apache License, Version 2.0 (the "License");
6# you may not use this file except in compliance with the License.
7# You may obtain a copy of the License at
8#
9#      http://www.apache.org/licenses/LICENSE-2.0
10#
11# Unless required by applicable law or agreed to in writing, software
12# distributed under the License is distributed on an "AS IS" BASIS,
13# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14# See the License for the specific language governing permissions and
15# limitations under the License.
16#
17
18function usage() {
19  cat <<END_OF_USAGE
20This script builds mainline modules. It is used from other build scripts that
21are run on build servers, and is meant to build both AOSP and internal
22variants of the modules.
23
24Basic usage:
25  \$ packages/modules/common/build/build_unbundled_mainline_module.sh \
26      --dist_dir out/dist/mainline_modules_arm64 \
27      --product module_arm64 \
28      -j8
29
30Arguments:
31   --dist_dir <dir>    a dist directory to store the outputs in.
32   --product <product> a target product to use when building.
33   \$@ all other arguments are passed through to soong_ui.bash verbatim.
34END_OF_USAGE
35}
36
37# List of AOSP modules to build if TARGET_BUILD_APPS is not set.
38readonly -a DEFAULT_MODULES=(
39  com.android.adbd
40  com.android.art
41  com.android.art.debug
42  com.android.art.testing
43  com.android.cellbroadcast
44  com.android.conscrypt
45  com.android.extservices
46  com.android.i18n
47  # TODO(b/210694291): include ipsec module in the build
48  # com.android.ipsec
49  com.android.media
50  com.android.mediaprovider
51  com.android.media.swcodec
52  com.android.neuralnetworks
53  # com.android.os.statsd
54  com.android.permission
55  com.android.resolv
56  com.android.runtime
57  com.android.sdkext
58  com.android.sepolicy
59  # TODO(b/210694291): include tethering module in the build
60  # com.android.tethering
61  com.android.tzdata
62  com.android.wifi
63  test1_com.android.tzdata
64  test_com.android.conscrypt
65  test_com.android.media
66  test_com.android.media.swcodec
67  CaptivePortalLogin
68  DocumentsUI
69  ExtServices
70  NetworkStack
71  NetworkStackNext
72  PermissionController
73)
74
75# Initializes and parses the command line arguments and environment variables.
76#
77# Do not rely on environment global variables for DIST_DIT and PRODUCT, since
78# the script expects specific values for those, instead of anything that could
79# have been lunch'ed in the terminal.
80function init() {
81  declare -ga ARGV
82  while (($# > 0)); do
83    case $1 in
84    --dist_dir)
85      local -r dist_dir="$2"
86      shift 2
87      ;;
88    --product)
89      local -r product="$2"
90      shift 2
91      ;;
92    --help)
93      usage
94      exit
95      ;;
96    *)
97      ARGV+=("$1")
98      shift 1
99      ;;
100    esac
101  done
102  readonly ARGV
103
104  if [ -z "${dist_dir}" ]; then
105    echo "Expected --dist_dir arg is not provided."
106    exit 1
107  fi
108  if [ -z "${product}" ]; then
109    echo "Expected --product arg is not provided."
110    exit 1
111  fi
112
113  declare -grx DIST_DIR="${dist_dir}"
114  declare -grx TARGET_BUILD_APPS="${TARGET_BUILD_APPS:-${DEFAULT_MODULES[*]}}"
115  declare -grx TARGET_BUILD_DENSITY="${TARGET_BUILD_DENSITY:-alldpi}"
116  declare -grx TARGET_BUILD_TYPE="${TARGET_BUILD_TYPE:-release}"
117  declare -grx TARGET_BUILD_VARIANT="${TARGET_BUILD_VARIANT:-user}"
118  declare -grx TARGET_PRODUCT="${product}"
119
120  # This script cannot handle compressed apexes
121  declare -grx OVERRIDE_PRODUCT_COMPRESSED_APEX=false
122
123  # UNBUNDLED_BUILD_SDKS_FROM_SOURCE defaults to false, which is necessary to
124  # use prebuilt SDKs on thin branches that may not have the sources (e.g.
125  # frameworks/base).
126}
127
128function main() {
129  if [ ! -e "build/make/core/Makefile" ]; then
130    echo "$0 must be run from the top of the Android source tree."
131    exit 1
132  fi
133
134  # Run installclean to remove previous artifacts, so they don't accumulate on
135  # the buildbots.
136  build/soong/soong_ui.bash --make-mode installclean
137
138  build/soong/soong_ui.bash --make-mode "$@" \
139    ALWAYS_EMBED_NOTICES=true \
140    MODULE_BUILD_FROM_SOURCE=true \
141    "${RUN_ERROR_PRONE:+"RUN_ERROR_PRONE=true"}" \
142    apps_only \
143    dist \
144    lint-check
145}
146
147init "$@"
148# The wacky ${foo[@]+"${foo[@]}"}, makes bash correctly pass nothing when an
149# array is empty (necessary prior to bash 4.4).
150main ${ARGV[@]+"${ARGV[@]}"}
151