sstate-diff-machines.sh 6.6 KB

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