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