Elliot Berman | b0d6c58 | 2020-05-29 14:29:10 -0700 | [diff] [blame] | 1 | #!/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 | |
| 30 | set -e |
| 31 | |
| 32 | if [ "$1" = "-h" ] || [ "$1" = "--help" ]; then |
| 33 | echo """ |
| 34 | $0 <command> |
| 35 | |
| 36 | Loop through all build variants |
| 37 | |
| 38 | If no <command> is given, then the variant environment variables are printed |
| 39 | If <command> is given, then the variant environment variables are set when calling <command> |
| 40 | |
| 41 | If BUILD_CONFIG is set, then all-variants.sh loops over all variants of that BUILD_CONFIG |
| 42 | If BUILD_CONFIG is not set, then all-variants.sh loops over all found target configs (those listed in build.targets) |
| 43 | |
| 44 | The 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 | |
| 49 | Example 1: |
| 50 | ./build/all-variants.sh \"./build/build.sh\" |
| 51 | Invokes ./build/build.sh for each BUILD_CONFIG/VARIANT combo |
| 52 | |
| 53 | Example 2: |
| 54 | function 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 |
| 66 | fi |
| 67 | |
| 68 | function do_list_variants() ( |
| 69 | local ROOT_DIR=$(readlink -f $(dirname $0)/..) |
| 70 | |
| 71 | source "${ROOT_DIR}/build/_wrapper_common.sh" |
| 72 | |
Elliot Berman | b0d6c58 | 2020-05-29 14:29:10 -0700 | [diff] [blame] | 73 | 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 Berman | bffe81b | 2020-07-29 19:11:43 -0700 | [diff] [blame] | 84 | if [ "${#variants[@]}" -eq 0 ]; then |
| 85 | echo "BUILD_CONFIG=${target} BRANCH=`get_branch`" |
| 86 | fi |
| 87 | |
Elliot Berman | b0d6c58 | 2020-05-29 14:29:10 -0700 | [diff] [blame] | 88 | for variant in "${variants[@]}" |
| 89 | do |
| 90 | echo "BUILD_CONFIG=${target} VARIANT=${variant} BRANCH=`get_branch`" |
| 91 | done |
| 92 | done |
| 93 | ) |
| 94 | |
Elliot Berman | 9f25de8 | 2021-03-02 16:08:00 -0800 | [diff] [blame] | 95 | if [ -n "$*" ]; then |
Elliot Berman | b0d6c58 | 2020-05-29 14:29:10 -0700 | [diff] [blame] | 96 | while read variant; do |
| 97 | unset do_list_variants |
| 98 | echo "${variant}" |
Elliot Berman | a159e24 | 2020-08-17 16:26:59 -0700 | [diff] [blame] | 99 | # Now, export those variables to the requested command |
Elliot Berman | 9f25de8 | 2021-03-02 16:08:00 -0800 | [diff] [blame] | 100 | ${SHELL} -c "set -a; ${variant// /;}; set +a; $*" |
Elliot Berman | b0d6c58 | 2020-05-29 14:29:10 -0700 | [diff] [blame] | 101 | done < <(do_list_variants) |
| 102 | else |
| 103 | do_list_variants |
| 104 | fi |