test-pkg 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168
  1. #!/bin/bash
  2. set -e
  3. TOOLCHAINS_URL='http://autobuild.buildroot.org/toolchains/configs/toolchain-configs.csv'
  4. main() {
  5. local o O opts
  6. local cfg dir pkg toolchain
  7. local -a toolchains
  8. o='hc:d:p:'
  9. O='help,config-snippet:build-dir:package:'
  10. opts="$( getopt -n "${my_name}" -o "${o}" -l "${O}" -- "${@}" )"
  11. eval set -- "${opts}"
  12. while [ ${#} -gt 0 ]; do
  13. case "${1}" in
  14. (-h|--help)
  15. help; exit 0
  16. ;;
  17. (-c|--config-snippet)
  18. cfg="${2}"; shift 2
  19. ;;
  20. (-d|--build-dir)
  21. dir="${2}"; shift 2
  22. ;;
  23. (-p|--package)
  24. pkg="${2}"; shift 2
  25. ;;
  26. (--)
  27. shift; break
  28. ;;
  29. esac
  30. done
  31. if [ -z "${cfg}" ]; then
  32. printf "error: no config snippet specified\n" >&2; exit 1
  33. fi
  34. if [ -z "${dir}" ]; then
  35. dir="${HOME}/br-test-pkg"
  36. fi
  37. # Extract the URLs of the toolchains; drop internal toolchains
  38. # E.g.: http://server/path/to/name.config,arch,libc
  39. # --> http://server/path/to/name.config
  40. toolchains=( $( curl -s "${TOOLCHAINS_URL}" \
  41. |sed -r -e 's/,.*//; /internal/d;'
  42. )
  43. )
  44. if [ ${#toolchains[@]} -eq 0 ]; then
  45. printf "error: no toolchain found (networking issue?)\n" >&2; exit 1
  46. fi
  47. for toolchain in "${toolchains[@]}"; do
  48. build_one "${dir}" "${toolchain}" "${cfg}" "${pkg}"
  49. done
  50. }
  51. build_one() {
  52. local dir="${1}"
  53. local url="${2}"
  54. local cfg="${3}"
  55. local pkg="${4}"
  56. local toolchain line
  57. # Using basename(1) on a URL works nicely
  58. toolchain="$( basename "${url}" .config )"
  59. printf "%40s: " "${toolchain}"
  60. dir="${dir}/${toolchain}"
  61. mkdir -p "${dir}"
  62. printf "download config"
  63. if ! curl -s "${url}" >"${dir}/.config"; then
  64. printf ": FAILED\n"
  65. return
  66. fi
  67. cat >>"${dir}/.config" <<-_EOF_
  68. BR2_INIT_NONE=y
  69. BR2_SYSTEM_BIN_SH_NONE=y
  70. # BR2_PACKAGE_BUSYBOX is not set
  71. # BR2_TARGET_ROOTFS_TAR is not set
  72. _EOF_
  73. cat "${cfg}" >>"${dir}/.config"
  74. printf ", olddefconfig"
  75. if ! make O="${dir}" olddefconfig >/dev/null 2>&1; then
  76. printf ": FAILED\n"
  77. return
  78. fi
  79. # We want all the options from the snippet to be present as-is (set
  80. # or not set) in the actual .config; if one of them is not, it means
  81. # some dependency from the toolchain or arch is not available, in
  82. # which case this config is untestable and we skip it.
  83. while read line; do
  84. if ! grep "^${line}\$" "${dir}/.config" >/dev/null 2>&1; then
  85. printf ", SKIPPED\n"
  86. return
  87. fi
  88. done <"${cfg}"
  89. if [ -n "${pkg}" ]; then
  90. printf ", dirclean"
  91. if ! make O="${dir}" "${pkg}-dirclean" >> "${dir}/logfile" 2>&1; then
  92. printf ": FAILED\n"
  93. return
  94. fi
  95. fi
  96. printf ", build"
  97. # shellcheck disable=SC2086
  98. if ! make O="${dir}" ${pkg} >> "${dir}/logfile" 2>&1; then
  99. printf ": FAILED\n"
  100. return
  101. fi
  102. printf ": OK\n"
  103. }
  104. help() {
  105. cat <<_EOF_
  106. test-pkg: test-build a package against various toolchains and architectures
  107. The supplied config snippet is appended to each toolchain config, the
  108. resulting configuration is checked to ensure it still contains all options
  109. specified in the snippet; if any is missing, the build is skipped, on the
  110. assumption that the package under test requires a toolchain or architecture
  111. feature that is missing.
  112. In case failures are noticed, you can fix the package and just re-run the
  113. same command again; it will re-run the test where it failed. If you did
  114. specify a package (with -p), the package build dir will be removed first.
  115. The list of toolchains is retrieved from the Buildroot autobuilders, available
  116. at ${TOOLCHAINS_URL}.
  117. Options:
  118. -h, --help
  119. Print this help.
  120. -c CFG, --config-snippet CFG
  121. Use the CFG file as the source for the config snippet. This file
  122. should contain all the config options required to build a package.
  123. -d DIR, --build-dir DIR
  124. Do the builds in directory DIR, one sub-dir per toolchain.
  125. -p PKG, --package PKG
  126. Test-build the package PKG, by running 'make PKG'; if not specified,
  127. just runs 'make'.
  128. Example:
  129. Testing libcec would require a config snippet that contains:
  130. BR2_PACKAGE_LIBCEC=y
  131. Testing libcurl with openSSL support would require a snippet such as:
  132. BR2_PACKAGE_OPENSSL=y
  133. BR2_PACKAGE_LIBCURL=y
  134. _EOF_
  135. }
  136. my_name="${0##*/}"
  137. main "${@}"