blob: 1a16f7c7dbbcc0ce4be03128c5228a17708fac38 [file] [log] [blame]
Pete Bentley237de412021-01-29 15:14:42 +00001#!/bin/bash -e
2
Martin Stjernholm040e0442021-06-07 23:18:56 +01003# This script is similar to "m" but builds in --soong-only mode, and handles
4# special cases to make that mode work. All arguments are passed on to
5# build/soong/soong_ui.bash.
Pete Bentley237de412021-01-29 15:14:42 +00006#
Martin Stjernholm040e0442021-06-07 23:18:56 +01007# --soong-only bypasses the kati step and hence the make logic that e.g. doesn't
8# handle more than two device architectures. It is particularly intended for use
9# with TARGET_PRODUCT=mainline_sdk to build 'sdk' and 'module_export' Soong
10# modules in TARGET_ARCH_SUITE=mainline_sdk mode so that they get all four
11# device architectures (artifacts get installed in $OUT_DIR/soong/mainline-sdks
12# - cf PathForMainlineSdksInstall in android/paths.go).
13#
14# TODO(b/174315599): Replace this script completely with a 'soong_ui.bash
15# --soong-only' invocation. For now it is still necessary to set up
16# build_number.txt.
17
18if [ ! -e build/soong/soong_ui.bash ]; then
19 echo "$0 must be run from the top of the tree"
20 exit 1
21fi
Pete Bentley237de412021-01-29 15:14:42 +000022
23export OUT_DIR=${OUT_DIR:-out}
24
25if [ -e ${OUT_DIR}/soong/.soong.kati_enabled ]; then
Colin Cross34d60c92021-10-28 16:19:40 -070026 # If ${OUT_DIR} has been created without --soong-only, Soong will create an
Pete Bentley237de412021-01-29 15:14:42 +000027 # ${OUT_DIR}/soong/build.ninja that leaves out many targets which are
28 # expected to be supplied by the .mk files, and that might cause errors in
Colin Cross34d60c92021-10-28 16:19:40 -070029 # "m --soong-only" below. We therefore default to a different out dir
Pete Bentley237de412021-01-29 15:14:42 +000030 # location in that case.
31 AML_OUT_DIR=out/aml
32 echo "Avoiding in-make OUT_DIR '${OUT_DIR}' - building in '${AML_OUT_DIR}' instead"
33 OUT_DIR=${AML_OUT_DIR}
34fi
35
Martin Stjernholm040e0442021-06-07 23:18:56 +010036mkdir -p ${OUT_DIR}/soong
Pete Bentley237de412021-01-29 15:14:42 +000037
Martin Stjernholm040e0442021-06-07 23:18:56 +010038# The --dumpvars-mode invocation will run Soong in normal make mode where it
39# creates .soong.kati_enabled. That would clobber our real out directory, so we
40# need to use a different OUT_DIR.
41vars="$(OUT_DIR=${OUT_DIR}/dumpvars_mode build/soong/soong_ui.bash \
42 --dumpvars-mode --vars=BUILD_NUMBER)"
43# Assign to a variable and eval that, since bash ignores any error status
44# from the command substitution if it's directly on the eval line.
45eval $vars
Pete Bentley237de412021-01-29 15:14:42 +000046
47# Some Soong build rules may require this, and the failure mode if it's missing
48# is confusing (b/172548608).
Martin Stjernholm040e0442021-06-07 23:18:56 +010049echo -n ${BUILD_NUMBER} > ${OUT_DIR}/soong/build_number.txt
Pete Bentley237de412021-01-29 15:14:42 +000050
Martin Stjernholm040e0442021-06-07 23:18:56 +010051build/soong/soong_ui.bash --make-mode --soong-only "$@"