fate.sh 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135
  1. #!/bin/sh
  2. config=$1
  3. die(){
  4. echo "$@"
  5. exit 1
  6. }
  7. test -r "$config" || die "usage: fate.sh <config>"
  8. workdir=$(cd $(dirname $config) && pwd)
  9. make=make
  10. tar='tar c'
  11. . "$config"
  12. test -n "$slot" || die "slot not specified"
  13. test -n "$repo" || die "repo not specified"
  14. test -d "$samples" || die "samples location not specified"
  15. : ${branch:=master}
  16. lock(){
  17. lock=$1/fate.lock
  18. (set -C; exec >$lock) 2>/dev/null || return
  19. trap 'rm $lock' EXIT
  20. }
  21. checkout(){
  22. case "$repo" in
  23. file:*|/*) src="${repo#file:}" ;;
  24. git:*|https:*) git clone --quiet --branch "$branch" "$repo" "$src" ;;
  25. esac
  26. }
  27. update()(
  28. cd ${src} || return
  29. case "$repo" in
  30. git:*|https:*) git fetch --quiet --force && git reset --quiet --hard "origin/$branch" ;;
  31. esac
  32. )
  33. configure()(
  34. cd ${build} || return
  35. ${shell} ${src}/configure \
  36. --prefix="${inst}" \
  37. --samples="${samples}" \
  38. --enable-gpl \
  39. --enable-memory-poisoning \
  40. ${ignore_tests:+--ignore-tests="$ignore_tests"} \
  41. ${arch:+--arch=$arch} \
  42. ${cpu:+--cpu="$cpu"} \
  43. ${toolchain:+--toolchain="$toolchain"} \
  44. ${cross_prefix:+--cross-prefix="$cross_prefix"} \
  45. ${as:+--as="$as"} \
  46. ${cc:+--cc="$cc"} \
  47. ${ld:+--ld="$ld"} \
  48. ${target_os:+--target-os="$target_os"} \
  49. ${sysroot:+--sysroot="$sysroot"} \
  50. ${target_exec:+--target-exec="$target_exec"} \
  51. ${target_path:+--target-path="$target_path"} \
  52. ${target_samples:+--target-samples="$target_samples"} \
  53. ${extra_cflags:+--extra-cflags="$extra_cflags"} \
  54. ${extra_ldflags:+--extra-ldflags="$extra_ldflags"} \
  55. ${extra_libs:+--extra-libs="$extra_libs"} \
  56. ${extra_conf}
  57. )
  58. compile()(
  59. cd ${build} || return
  60. ${make} ${makeopts} && ${make} install
  61. )
  62. fate()(
  63. test "$build_only" = "yes" && return
  64. cd ${build} || return
  65. if [ -n "${fate_environments}" ]; then
  66. ret=0
  67. for e in ${fate_environments}; do
  68. eval "curenv=\${${e}_env}"
  69. echo Testing environment ${e}: ${curenv}
  70. ${make} ${makeopts_fate-${makeopts}} -k ${fate_targets} FATE_SUFFIX=_${e} ${curenv}
  71. cur_ret=$?
  72. test $cur_ret != 0 && ret=$cur_ret
  73. done
  74. return $ret
  75. else
  76. ${make} ${makeopts_fate-${makeopts}} -k ${fate_targets}
  77. fi
  78. )
  79. clean(){
  80. rm -rf ${build} ${inst}
  81. }
  82. report(){
  83. date=$(date -u +%Y%m%d%H%M%S)
  84. echo "fate:1:${date}:${slot}:${version}:$1:$2:${branch}:${comment}" >report
  85. cat ${build}/ffbuild/config.fate >>report
  86. cat ${build}/tests/data/fate/*.rep >>report 2>/dev/null || for i in ${build}/tests/data/fate/*.rep ; do cat "$i" >>report 2>/dev/null; done
  87. test -n "$fate_recv" && $tar report *.log | gzip | $fate_recv
  88. }
  89. fail(){
  90. report "$@"
  91. clean
  92. exit
  93. }
  94. mkdir -p ${workdir} || die "Error creating ${workdir}"
  95. lock ${workdir} || die "${workdir} locked"
  96. cd ${workdir} || die "cd ${workdir} failed"
  97. src=${workdir}/src
  98. : ${build:=${workdir}/build}
  99. : ${inst:=${workdir}/install}
  100. : ${fate_targets:=fate}
  101. test -d "$src" && update || checkout || die "Error fetching source"
  102. cd ${workdir}
  103. version=$(${src}/ffbuild/version.sh ${src})
  104. test "$version" = "$(cat version-$slot 2>/dev/null)" && exit 0
  105. echo ${version} >version-$slot
  106. rm -rf "${build}" *.log
  107. mkdir -p ${build}
  108. configure >configure.log 2>&1 || fail 3 "error configuring"
  109. compile >compile.log 2>&1 || fail 2 "error compiling"
  110. fate >test.log 2>&1 || fail 1 "error testing"
  111. report 0 success
  112. clean