sstate-diff-machines.sh 6.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172
  1. #!/bin/bash
  2. # Used to compare sstate checksums between MACHINES.
  3. # Execute script and compare generated list.M files.
  4. # Using bash to have PIPESTATUS variable.
  5. # It's also usefull to keep older sstate checksums
  6. # to be able to find out why something is rebuilding
  7. # after updating metadata
  8. # $ diff \
  9. # sstate-diff/1349348392/fake-cortexa8/list.M \
  10. # sstate-diff/1349348392/fake-cortexa9/list.M \
  11. # | wc -l
  12. # 538
  13. # Then to compare sigdata use something like:
  14. # $ ls sstate-diff/1349348392/*/armv7a-vfp-neon*/linux-libc-headers/*do_configure*sigdata*
  15. # sstate-diff/1349348392/fake-cortexa8/armv7a-vfp-neon-oe-linux-gnueabi/linux-libc-headers/3.4.3-r0.do_configure.sigdata.cb73b3630a7b8191e72fc469c5137025
  16. # sstate-diff/1349348392/fake-cortexa9/armv7a-vfp-neon-oe-linux-gnueabi/linux-libc-headers/3.4.3-r0.do_configure.sigdata.f37ada177bf99ce8af85914df22b5a0b
  17. # $ bitbake-diffsigs stamps.1349348392/*/armv7a-vfp-neon*/linux-libc-headers/*do_configure*sigdata*
  18. # basehash changed from 8d0bd67bb1da6f68717760fc3ef43171 to e869fa61426e88e9c30726ba88a1216a
  19. # Variable TUNE_CCARGS value changed from -march=armv7-a -mthumb-interwork -mfloat-abi=softfp -mfpu=neon -mtune=cortex-a8 to -march=armv7-a -mthumb-interwork -mfloat-abi=softfp -mfpu=neon -mtune=cortex-a9
  20. # Global vars
  21. tmpdir=
  22. machines=
  23. targets=
  24. default_machines="qemuarm qemux86 qemux86-64"
  25. default_targets="core-image-base"
  26. analyze="N"
  27. usage () {
  28. cat << EOF
  29. Welcome to utility to compare sstate checksums between different MACHINEs.
  30. $0 <OPTION>
  31. Options:
  32. -h, --help
  33. Display this help and exit.
  34. --tmpdir=<tmpdir>
  35. Specify tmpdir, will use the environment variable TMPDIR if it is not specified.
  36. Something like /OE/oe-core/tmp-eglibc (no / at the end).
  37. --machines=<machines>
  38. List of MACHINEs separated by space, will use the environment variable MACHINES if it is not specified.
  39. Default value is "qemuarm qemux86 qemux86-64".
  40. --targets=<targets>
  41. List of targets separated by space, will use the environment variable TARGETS if it is not specified.
  42. Default value is "core-image-base".
  43. --analyze
  44. Show the differences between MACHINEs. It assumes:
  45. * First 2 MACHINEs in --machines parameter have the same TUNE_PKGARCH
  46. * Third optional MACHINE has different TUNE_PKGARCH - only native and allarch recipes are compared).
  47. * Next MACHINEs are ignored
  48. EOF
  49. }
  50. # Print error information and exit.
  51. echo_error () {
  52. echo "ERROR: $1" >&2
  53. exit 1
  54. }
  55. while [ -n "$1" ]; do
  56. case $1 in
  57. --tmpdir=*)
  58. tmpdir=`echo $1 | sed -e 's#^--tmpdir=##' | xargs readlink -e`
  59. [ -d "$tmpdir" ] || echo_error "Invalid argument to --tmpdir"
  60. shift
  61. ;;
  62. --machines=*)
  63. machines=`echo $1 | sed -e 's#^--machines="*\([^"]*\)"*#\1#'`
  64. shift
  65. ;;
  66. --targets=*)
  67. targets=`echo $1 | sed -e 's#^--targets="*\([^"]*\)"*#\1#'`
  68. shift
  69. ;;
  70. --analyze)
  71. analyze="Y"
  72. shift
  73. ;;
  74. --help|-h)
  75. usage
  76. exit 0
  77. ;;
  78. *)
  79. echo "Invalid arguments $*"
  80. echo_error "Try '$0 -h' for more information."
  81. ;;
  82. esac
  83. done
  84. # tmpdir directory, use environment variable TMPDIR
  85. # if it was not specified, otherwise, error.
  86. [ -n "$tmpdir" ] || tmpdir=$TMPDIR
  87. [ -n "$tmpdir" ] || echo_error "No tmpdir found!"
  88. [ -d "$tmpdir" ] || echo_error "Invalid tmpdir \"$tmpdir\""
  89. [ -n "$machines" ] || machines=$MACHINES
  90. [ -n "$machines" ] || machines=$default_machines
  91. [ -n "$targets" ] || targets=$TARGETS
  92. [ -n "$targets" ] || targets=$default_targets
  93. OUTPUT=${tmpdir}/sstate-diff/`date "+%s"`
  94. declare -i RESULT=0
  95. for M in ${machines}; do
  96. [ -d ${tmpdir}/stamps/ ] && find ${tmpdir}/stamps/ -name \*sigdata\* | xargs rm -f
  97. mkdir -p ${OUTPUT}/${M}
  98. export MACHINE=${M}
  99. bitbake -S none ${targets} 2>&1 | tee -a ${OUTPUT}/${M}/log;
  100. RESULT+=${PIPESTATUS[0]}
  101. if ls ${tmpdir}/stamps/* >/dev/null 2>/dev/null ; then
  102. cp -ra ${tmpdir}/stamps/* ${OUTPUT}/${M}
  103. find ${OUTPUT}/${M} -name \*sigdata\* | sed "s#${OUTPUT}/${M}/##g" | sort > ${OUTPUT}/${M}/list
  104. M_UNDERSCORE=`echo ${M} | sed 's/-/_/g'`
  105. sed "s/^${M_UNDERSCORE}-/MACHINE/g" ${OUTPUT}/${M}/list | sort > ${OUTPUT}/${M}/list.M
  106. find ${tmpdir}/stamps/ -name \*sigdata\* | xargs rm -f
  107. else
  108. printf "ERROR: no sigdata files were generated for MACHINE $M in ${tmpdir}/stamps\n";
  109. fi
  110. done
  111. function compareSignatures() {
  112. MACHINE1=$1
  113. MACHINE2=$2
  114. PATTERN="$3"
  115. PRE_PATTERN=""
  116. [ -n "${PATTERN}" ] || PRE_PATTERN="-v"
  117. [ -n "${PATTERN}" ] || PATTERN="MACHINE"
  118. for TASK in do_configure.sigdata do_populate_sysroot.sigdata do_package_write_ipk.sigdata; do
  119. printf "\n\n === Comparing signatures for task ${TASK} between ${MACHINE1} and ${MACHINE2} ===\n" | tee -a ${OUTPUT}/signatures.${MACHINE2}.${TASK}.log
  120. diff ${OUTPUT}/${MACHINE1}/list.M ${OUTPUT}/${MACHINE2}/list.M | grep ${PRE_PATTERN} "${PATTERN}" | grep ${TASK} > ${OUTPUT}/signatures.${MACHINE2}.${TASK}
  121. for i in `cat ${OUTPUT}/signatures.${MACHINE2}.${TASK} | sed 's#[^/]*/\([^/]*\)/.*#\1#g' | sort -u | xargs`; do
  122. [ -e ${OUTPUT}/${MACHINE1}/*/$i/*${TASK}* ] || echo "INFO: ${i} task ${TASK} doesn't exist in ${MACHINE1}" >&2
  123. [ -e ${OUTPUT}/${MACHINE1}/*/$i/*${TASK}* ] || continue
  124. [ -e ${OUTPUT}/${MACHINE2}/*/$i/*${TASK}* ] || echo "INFO: ${i} task ${TASK} doesn't exist in ${MACHINE2}" >&2
  125. [ -e ${OUTPUT}/${MACHINE2}/*/$i/*${TASK}* ] || continue
  126. printf "ERROR: $i different signature for task ${TASK} between ${MACHINE1} and ${MACHINE2}\n";
  127. bitbake-diffsigs ${OUTPUT}/${MACHINE1}/*/$i/*${TASK}* ${OUTPUT}/${MACHINE2}/*/$i/*${TASK}*;
  128. echo "$i" >> ${OUTPUT}/failed-recipes.log
  129. echo
  130. done | tee -a ${OUTPUT}/signatures.${MACHINE2}.${TASK}.log
  131. # don't create empty files
  132. ERRORS=`grep "^ERROR.*" ${OUTPUT}/signatures.${MACHINE2}.${TASK}.log | wc -l`
  133. if [ "${ERRORS}" != "0" ] ; then
  134. echo "ERROR: ${ERRORS} errors found in ${OUTPUT}/signatures.${MACHINE2}.${TASK}.log"
  135. RESULT+=${ERRORS}
  136. fi
  137. done
  138. }
  139. function compareMachines() {
  140. [ "$#" -ge 2 ] && compareSignatures $1 $2
  141. [ "$#" -ge 3 ] && compareSignatures $1 $3 "\(^< all\)\|\(^< x86_64-linux\)\|\(^< i586-linux\)"
  142. }
  143. if [ "${analyze}" = "Y" ] ; then
  144. compareMachines ${machines}
  145. fi
  146. if [ "${RESULT}" != "0" -a -f ${OUTPUT}/failed-recipes.log ] ; then
  147. cat ${OUTPUT}/failed-recipes.log | sort -u >${OUTPUT}/failed-recipes.log.u && mv ${OUTPUT}/failed-recipes.log.u ${OUTPUT}/failed-recipes.log
  148. echo "ERROR: ${RESULT} issues were found in these recipes: `cat ${OUTPUT}/failed-recipes.log | xargs`"
  149. fi
  150. echo "INFO: Output written in: ${OUTPUT}"
  151. exit ${RESULT}