buildall-qemu 3.2 KB

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