Gyorgy Szing | ba1095c | 2020-11-24 00:33:11 +0100 | [diff] [blame] | 1 | #!/bin/bash |
| 2 | # |
Imre Kis | 23583e3 | 2021-10-22 14:54:51 +0200 | [diff] [blame] | 3 | # Copyright (c) 2020-2021, Arm Limited and contributors. All rights reserved. |
Gyorgy Szing | ba1095c | 2020-11-24 00:33:11 +0100 | [diff] [blame] | 4 | # |
| 5 | # SPDX-License-Identifier: BSD-3-Clause |
| 6 | # |
| 7 | |
| 8 | # Exit with error if any command fails |
| 9 | set -e |
| 10 | |
| 11 | # Read in user specific environment settings |
| 12 | if [ -e user.env ] |
| 13 | then |
| 14 | echo "Reding user specific settings from user.env" |
| 15 | source user.env |
| 16 | fi |
| 17 | |
| 18 | # Default to non-verbose mode. |
| 19 | VERBOSE=${VERBOSE:-0} |
| 20 | |
| 21 | # Get root of TS repo. |
| 22 | TS_ROOT=${TS_ROOT:-$(git rev-parse --show-toplevel)} |
| 23 | |
| 24 | # Number of threads to use in parallel |
| 25 | NUMBER_OF_PROCESSORS=${NUMBER_OF_PROCESSORS:-$(( $(nproc) * 2 )) } |
| 26 | |
| 27 | # Convert test name to build directory |
| 28 | function name-to-bdir() { |
| 29 | printf "./build-%s" "$1" |
| 30 | } |
| 31 | |
| 32 | # Wrap cmake to allow verbose vs non-verbose mode |
| 33 | function _cmake() { |
| 34 | log_file=$1 |
| 35 | shift |
| 36 | if [ "$VERBOSE" != "0" ] |
| 37 | then |
| 38 | cmake "$@" 2>&1 | tee -a "$log_file" |
| 39 | return ${PIPESTATUS[0]} |
| 40 | else |
| 41 | cmake "$@" >>"$log_file" 2>&1 |
| 42 | fi |
| 43 | } |
| 44 | |
| 45 | {% for config in data %} |
| 46 | # Run build test "{{config.name}}" |
| 47 | {{config.name}}() { |
| 48 | echo "##################################################################" |
| 49 | echo "########################## {{config.name}} started." |
| 50 | |
| 51 | {% if config.os_id is defined %} |
| 52 | if [ "$OS_ID" != "{{config.os_id}}" ] |
| 53 | then |
| 54 | echo "Test case is not supported on this host." |
| 55 | echo "########################## $COLOR_YELOW {{config.name}} skipped $COLOR_RESET" |
| 56 | echo "##################################################################" |
| 57 | return |
| 58 | fi |
| 59 | {% endif %} |
| 60 | b_dir=$(name-to-bdir "{{config.name}}") |
| 61 | log_file=$b_dir/build.log |
| 62 | rm -rf "$b_dir" |
| 63 | mkdir -p "$b_dir" |
| 64 | |
Gyorgy Szing | b164e39 | 2021-09-04 01:51:57 +0200 | [diff] [blame] | 65 | if [ -n "$_ccache" ] |
| 66 | then |
| 67 | ccache_option=-DCMAKE_C_COMPILER_LAUNCHER=$_ccache |
| 68 | fi |
| 69 | |
| 70 | _cmake "$log_file" -S {{config.src}} -B "$b_dir" $ccache_option {% for param in config.params %} "{{param}}" {%endfor%} || { |
Gyorgy Szing | ba1095c | 2020-11-24 00:33:11 +0100 | [diff] [blame] | 71 | |
| 72 | echo "For details see: $log_file" |
| 73 | echo "########################## $COLOR_RED {{config.name}} failed $COLOR_RESET" |
| 74 | return |
| 75 | } |
| 76 | |
Gyorgy Szing | b164e39 | 2021-09-04 01:51:57 +0200 | [diff] [blame] | 77 | if _cmake "$log_file" --build "$b_dir" -j ${NUMBER_OF_PROCESSORS} --verbose |
Gyorgy Szing | ba1095c | 2020-11-24 00:33:11 +0100 | [diff] [blame] | 78 | then |
| 79 | if _cmake "$log_file" --install "$b_dir" --prefix ./install |
| 80 | then |
| 81 | echo "########################## $COLOR_GREEN {{config.name}} passed $COLOR_RESET" |
| 82 | else |
| 83 | echo "For details see: $log_file" |
| 84 | echo "########################## $COLOR_RED {{config.name}} failed $COLOR_RESET" |
| 85 | fi |
| 86 | else |
| 87 | echo "For details see: $log_file" |
| 88 | echo "########################## $COLOR_RED {{config.name}} failed $COLOR_RESET" |
| 89 | fi |
| 90 | echo "##################################################################" |
| 91 | } |
| 92 | |
| 93 | {% endfor %} |
| 94 | |
| 95 | # Clean intermediate files |
| 96 | do_clean() { |
| 97 | {% for config in data %} |
| 98 | b_dir=$(name-to-bdir "{{config.name}}") |
| 99 | if [ -d "$b_dir" ] |
| 100 | then |
| 101 | echo "Removing $b_dir" |
| 102 | rm -rf "$b_dir" || true |
| 103 | fi |
| 104 | {% endfor %} |
| 105 | } |
| 106 | |
| 107 | # Print usage info |
| 108 | do_help() { |
| 109 | cat <<END_HELP |
| 110 | Build test runner |
| 111 | ================= |
| 112 | |
| 113 | Invocation:: |
| 114 | ``$0 <command>`` |
| 115 | |
| 116 | The file "user.env" is sourced from the current directory. Use it to set |
| 117 | environment specific defaults. For config variables see the start of this script |
| 118 | and any "$<XXXX>" in the "params" array of any command in test_data.yaml |
| 119 | Some variables to note |
| 120 | - VERBOSE : make the script output more info. |
| 121 | VERBOSE=$VERBOSE |
| 122 | - TS_ROOT : Root directory of the TS repo. |
| 123 | TS_ROOT=$TS_ROOT |
| 124 | - NUMBER_OF_PROCESSORS: number of processors in the system. Used for setting the number of |
| 125 | parallel processes during build |
| 126 | NUMBER_OF_PROCESSORS=$NUMBER_OF_PROCESSORS |
Gyorgy Szing | ba1095c | 2020-11-24 00:33:11 +0100 | [diff] [blame] | 127 | |
| 128 | Available commands: |
| 129 | "" - no command/default -> run all test cases |
| 130 | clean - remove build directories |
| 131 | help - print this text |
| 132 | <test case> - run a single build |
| 133 | available test cases: |
| 134 | {% for config in data %} |
| 135 | {{config.name}} |
| 136 | {% endfor %} |
| 137 | END_HELP |
| 138 | } |
| 139 | |
| 140 | #################### Entry point ################################### |
| 141 | |
| 142 | OS_ID=$(uname -o ) |
| 143 | |
| 144 | if [ -n $(which tput) -a -t ] |
| 145 | then |
| 146 | COLOR_YELOW=$(tput setaf 3) |
| 147 | COLOR_RESET=$(tput sgr0) |
| 148 | COLOR_RED=$(tput setaf 1) |
| 149 | COLOR_GREEN=$(tput setaf 2) |
| 150 | else |
| 151 | COLOR_YELOW= |
| 152 | COLOR_RESET= |
| 153 | COLOR_RED= |
| 154 | COLOR_GREEN= |
| 155 | fi |
| 156 | |
Gyorgy Szing | b164e39 | 2021-09-04 01:51:57 +0200 | [diff] [blame] | 157 | _ccache=$(which ccache) |
| 158 | |
Gyorgy Szing | ba1095c | 2020-11-24 00:33:11 +0100 | [diff] [blame] | 159 | case $1 in |
| 160 | {% for config in data %} |
| 161 | {{config.name}}) |
| 162 | {{config.name}} |
| 163 | ;; |
| 164 | {% endfor %} |
| 165 | clean) |
| 166 | do_clean |
| 167 | ;; |
| 168 | help) |
| 169 | do_help |
| 170 | ;; |
| 171 | "") |
| 172 | {% for config in data %} |
| 173 | {{config.name}} |
| 174 | {% endfor %} |
| 175 | ;; |
| 176 | *) |
| 177 | do_help |
| 178 | ;; |
| 179 | esac |