blob: 8ede784f1a294b6153d9fcdcbd10abd52666ee47 [file] [log] [blame]
Elliot Bermanb0d6c582020-05-29 14:29:10 -07001#!/bin/bash
2
3# Copyright (c) 2020, The Linux Foundation. All rights reserved.
4#
5# Redistribution and use in source and binary forms, with or without
6# modification, are permitted provided that the following conditions are
7# met:
8# * Redistributions of source code must retain the above copyright
9# notice, this list of conditions and the following disclaimer.
10# * Redistributions in binary form must reproduce the above
11# copyright notice, this list of conditions and the following
12# disclaimer in the documentation and/or other materials provided
13# with the distribution.
14# * Neither the name of The Linux Foundation nor the names of its
15# contributors may be used to endorse or promote products derived
16# from this software without specific prior written permission.
17#
18# THIS SOFTWARE IS PROVIDED "AS IS" AND ANY EXPRESS OR IMPLIED
19# WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
20# MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT
21# ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS
22# BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
23# CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
24# SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
25# BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
26# WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE
27# OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN
28# IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
29
30set -e
31
32if [ "$1" = "-h" ] || [ "$1" = "--help" ]; then
33 echo """
34$0 <command>
35
36Loop through all build variants
37
38If no <command> is given, then the variant environment variables are printed
39If <command> is given, then the variant environment variables are set when calling <command>
40
41If BUILD_CONFIG is set, then all-variants.sh loops over all variants of that BUILD_CONFIG
42If BUILD_CONFIG is not set, then all-variants.sh loops over all found target configs (those listed in build.targets)
43
44The following environment variables are provided:
45 BUILD_CONFIG - the path to the build.config file for the target
46 VARIANT - a build.config variant
47 BRANCH - when not specifying an output directory, output is put in out/${BRANCH}.
48
49Example 1:
50./build/all-variants.sh \"./build/build.sh\"
51 Invokes ./build/build.sh for each BUILD_CONFIG/VARIANT combo
52
53Example 2:
54function do_build() {
55 OUT_DIR=./output BUILD_CONFIG=\${BUILD_CONFIG} VARIANT=\${VARIANT} ./build/build.sh 2>&1 | tee ${BRANCH}.log
56 if [ \$? -ne \"0\" ]; then
57 echo ${BRANCH} build failed!
58 fi
59 rm -rf ./output
60}
61./build/all-variants.sh do_build
62 Invokes do_build function for each BUILD_CONFIG/VARIANT combo, which compiles each kernel
63 in a temporary folder. Build logs go in \${BRANCH}.log
64"""
65 exit
66fi
67
68function do_list_variants() (
69 local ROOT_DIR=$(readlink -f $(dirname $0)/..)
70
71 source "${ROOT_DIR}/build/_wrapper_common.sh"
72
Elliot Bermanb0d6c582020-05-29 14:29:10 -070073 if [ -n "${BUILD_CONFIG}" ]; then
74 BUILD_CONFIGS=("${BUILD_CONFIG}")
75 else
76 create_targets_array BUILD_CONFIGS
77 fi
78
79 for target in "${BUILD_CONFIGS[@]}"
80 do
81 variants=()
82 create_variants_array variants "${target}"
83
Elliot Bermanbffe81b2020-07-29 19:11:43 -070084 if [ "${#variants[@]}" -eq 0 ]; then
85 echo "BUILD_CONFIG=${target} BRANCH=`get_branch`"
86 fi
87
Elliot Bermanb0d6c582020-05-29 14:29:10 -070088 for variant in "${variants[@]}"
89 do
90 echo "BUILD_CONFIG=${target} VARIANT=${variant} BRANCH=`get_branch`"
91 done
92 done
93)
94
Elliot Berman9f25de82021-03-02 16:08:00 -080095if [ -n "$*" ]; then
Elliot Bermanb0d6c582020-05-29 14:29:10 -070096 while read variant; do
97 unset do_list_variants
98 echo "${variant}"
Elliot Bermana159e242020-08-17 16:26:59 -070099 # Now, export those variables to the requested command
Elliot Berman9f25de82021-03-02 16:08:00 -0800100 ${SHELL} -c "set -a; ${variant// /;}; set +a; $*"
Elliot Bermanb0d6c582020-05-29 14:29:10 -0700101 done < <(do_list_variants)
102else
103 do_list_variants
104fi