Andrew Geissler | 82c905d | 2020-04-13 13:39:40 -0500 | [diff] [blame] | 1 | #!/bin/sh |
| 2 | # Copyright (c) 2020 Wind River Systems, Inc. |
| 3 | # |
| 4 | # SPDX-License-Identifier: GPL-2.0-only |
| 5 | # |
| 6 | # buildall-qemu: a tool for automating build testing of recipes |
| 7 | # TODO: Add support for selecting which qemu architectures to build |
| 8 | # TODO: Add support for queueing up multiple recipe builds |
| 9 | # TODO: Add more logging options (e.g. local.conf info, bitbake env info) |
| 10 | |
| 11 | usage () |
| 12 | { |
| 13 | base=$(basename "$0") |
| 14 | echo "Usage: $base [options] [recipename/target]" |
| 15 | echo "Executes a build of a given target for selected LIBCs. With no options, default to both libc and musl." |
| 16 | echo "Options:" |
| 17 | echo "-l, --libc Specify one of \"glibc\" or \"musl\"" |
| 18 | } |
| 19 | |
| 20 | |
| 21 | buildall () |
| 22 | { |
| 23 | # Get path to oe-core directory. Since oe-init-build-env prepends $PATH with |
| 24 | # the path to the scripts directory, get it from there |
| 25 | SCRIPTS_PATH="$(echo "$PATH" | cut -d ":" -f 1)" |
| 26 | OE_CORE_PATH=$(echo "$SCRIPTS_PATH" | sed 's|\(.*\)/.*|\1|') |
| 27 | |
| 28 | # Get target list and host machine information |
| 29 | TARGET_LIST=$(find "$OE_CORE_PATH"/meta/conf/machine -maxdepth 1 -type f | grep qemu | sed 's|.*/||' | sed -e 's/\.conf//') |
| 30 | |
| 31 | # Set LIBC value to use for the builds based on options provided by the user |
| 32 | if [ -n "$2" ] |
| 33 | then |
| 34 | LIBC_LIST="$2" |
| 35 | echo "$LIBC_LIST" |
| 36 | else |
| 37 | LIBC_LIST="glibc musl" |
| 38 | echo "$LIBC_LIST" |
| 39 | fi |
| 40 | |
| 41 | START_TIME=$(date "+%Y-%m-%d_%H:%M:%S") |
| 42 | LOG_FILE="$1-buildall.log" |
| 43 | OS_INFO=$(grep "PRETTY_NAME=" /etc/os-release | awk -F "=" '{print $2}' | sed -e 's/^"//' -e 's/"$//') |
| 44 | |
| 45 | # Append an existing log file for this build with .old if one exists |
| 46 | if [ -f "${LOG_FILE}" ] |
| 47 | then |
| 48 | mv "${LOG_FILE}" "${LOG_FILE}.old" |
| 49 | else |
| 50 | touch "${LOG_FILE}" |
| 51 | fi |
| 52 | |
| 53 | # Fill the log file with build and host info |
| 54 | echo "BUILDALL-QEMU LOG FOR $1" >> "${LOG_FILE}" |
| 55 | echo "START TIME: ${START_TIME}" >> "${LOG_FILE}" |
| 56 | echo "HOSTNAME: $(uname -n)" >> "${LOG_FILE}" |
| 57 | echo "HOST OS: ${OS_INFO}" >> "${LOG_FILE}" |
| 58 | echo "HOST KERNEL: $(uname -r)" >> "${LOG_FILE}" |
| 59 | echo "===============" >> "${LOG_FILE}" |
| 60 | echo "BUILD RESULTS:" >> "${LOG_FILE}" |
| 61 | |
| 62 | # start the builds for each MACHINE and TCLIBC |
| 63 | for j in ${LIBC_LIST} |
| 64 | do |
| 65 | echo "[$j]" >> "${LOG_FILE}" |
| 66 | for i in ${TARGET_LIST} |
| 67 | do |
| 68 | echo "$i" "$j"; \ |
| 69 | TCLIBC=$j MACHINE=$i bitbake "$1" && echo "PASS: $i" >> "${LOG_FILE}" || echo "FAIL: $i" >> "${LOG_FILE}" |
| 70 | done |
| 71 | done |
| 72 | |
| 73 | # Get pass/fail totals and add them to the end of the log |
| 74 | PASSED=$(grep "PASS:" "${LOG_FILE}" | wc -l) |
| 75 | FAILED=$(grep "FAIL:" "${LOG_FILE}" | wc -l) |
| 76 | |
| 77 | echo "===============" >> "${LOG_FILE}" |
| 78 | echo "PASSED: ${PASSED}" >> "${LOG_FILE}" |
| 79 | echo "FAILED: ${FAILED}" >> "${LOG_FILE}" |
| 80 | } |
| 81 | |
| 82 | |
| 83 | # fail entire script if any command fails |
| 84 | set -e |
| 85 | |
| 86 | # print usage and exit if not enough args given |
| 87 | [ $# -eq 0 ] && usage && exit 1 |
| 88 | |
| 89 | # handle arguments |
| 90 | RECIPE= |
| 91 | while [ $# -gt 0 ] |
| 92 | do |
| 93 | arg=$1 |
| 94 | case $arg in |
| 95 | -l|--libc) |
| 96 | if [ "$2" = "glibc" ] || [ "$2" = "musl" ] |
| 97 | then |
| 98 | LIBC_LIST="$2" |
| 99 | else |
| 100 | echo "Unrecognized libc option." |
| 101 | usage && exit 1 |
| 102 | fi |
| 103 | shift |
| 104 | shift |
| 105 | ;; |
| 106 | *) |
| 107 | RECIPE="$1" |
| 108 | shift |
| 109 | ;; |
| 110 | esac |
| 111 | done |
| 112 | |
| 113 | set -- "$RECIPE" |
| 114 | |
| 115 | # run buildall for the given recipe and LIBC |
| 116 | if [ -n "$1" ] |
| 117 | then |
| 118 | buildall "$1" "$LIBC_LIST" |
| 119 | fi |
| 120 | |