sstate-sysroot-cruft.sh 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152
  1. #!/bin/sh
  2. # Used to find files installed in sysroot which are not tracked by sstate manifest
  3. # Global vars
  4. tmpdir=
  5. usage () {
  6. cat << EOF
  7. Welcome to sysroot cruft finding utility.
  8. $0 <OPTION>
  9. Options:
  10. -h, --help
  11. Display this help and exit.
  12. --tmpdir=<tmpdir>
  13. Specify tmpdir, will use the environment variable TMPDIR if it is not specified.
  14. Something like /OE/oe-core/tmp-eglibc (no / at the end).
  15. --whitelist=<whitelist-file>
  16. Text file, each line is regular expression for paths we want to ignore in resulting diff.
  17. You can use diff file from the script output, if it contains only expected exceptions.
  18. '#' is used as regexp delimiter, so you don't need to prefix forward slashes in paths.
  19. ^ and $ is automatically added, so provide only the middle part.
  20. Lines starting with '#' are ignored as comments.
  21. All paths are relative to "sysroots" directory.
  22. Directories don't end with forward slash.
  23. EOF
  24. }
  25. # Print error information and exit.
  26. echo_error () {
  27. echo "ERROR: $1" >&2
  28. exit 1
  29. }
  30. while [ -n "$1" ]; do
  31. case $1 in
  32. --tmpdir=*)
  33. tmpdir=`echo $1 | sed -e 's#^--tmpdir=##' | xargs readlink -e`
  34. [ -d "$tmpdir" ] || echo_error "Invalid argument to --tmpdir"
  35. shift
  36. ;;
  37. --whitelist=*)
  38. fwhitelist=`echo $1 | sed -e 's#^--whitelist=##' | xargs readlink -e`
  39. [ -f "$fwhitelist" ] || echo_error "Invalid argument to --whitelist"
  40. shift
  41. ;;
  42. --help|-h)
  43. usage
  44. exit 0
  45. ;;
  46. *)
  47. echo "Invalid arguments $*"
  48. echo_error "Try '$0 -h' for more information."
  49. ;;
  50. esac
  51. done
  52. # sstate cache directory, use environment variable TMPDIR
  53. # if it was not specified, otherwise, error.
  54. [ -n "$tmpdir" ] || tmpdir=$TMPDIR
  55. [ -n "$tmpdir" ] || echo_error "No tmpdir found!"
  56. [ -d "$tmpdir" ] || echo_error "Invalid tmpdir \"$tmpdir\""
  57. OUTPUT=${tmpdir}/sysroot.cruft.`date "+%s"`
  58. # top level directories
  59. WHITELIST="[^/]*"
  60. # generated by base-passwd recipe
  61. WHITELIST="${WHITELIST} \
  62. .*/etc/group-\? \
  63. .*/etc/passwd-\? \
  64. "
  65. # generated by pseudo-native
  66. WHITELIST="${WHITELIST} \
  67. .*/var/pseudo \
  68. .*/var/pseudo/[^/]* \
  69. "
  70. # generated by package.bbclass:SHLIBSDIRS = "${PKGDATA_DIR}/${MLPREFIX}shlibs"
  71. WHITELIST="${WHITELIST} \
  72. .*/shlibs \
  73. .*/pkgdata \
  74. "
  75. # generated by python
  76. WHITELIST="${WHITELIST} \
  77. .*\.pyc \
  78. .*\.pyo \
  79. "
  80. # generated by sgml-common-native
  81. WHITELIST="${WHITELIST} \
  82. .*/etc/sgml/sgml-docbook.bak \
  83. "
  84. # generated by toolchain
  85. WHITELIST="${WHITELIST} \
  86. [^/]*-tcbootstrap/lib \
  87. "
  88. # generated by useradd.bbclass
  89. WHITELIST="${WHITELIST} \
  90. [^/]*/home \
  91. [^/]*/home/xuser \
  92. "
  93. SYSROOTS="`readlink -f ${tmpdir}`/sysroots/"
  94. mkdir ${OUTPUT}
  95. find ${tmpdir}/sstate-control -name \*.populate-sysroot\* -o -name \*.populate_sysroot\* -o -name \*.package\* | xargs cat | grep sysroots | \
  96. sed 's#/$##g; s#///*#/#g' | \
  97. # work around for paths ending with / for directories and multiplied // (e.g. paths to native sysroot)
  98. sort | sed "s#^${SYSROOTS}##g" > ${OUTPUT}/master.list.all.txt
  99. sort -u ${OUTPUT}/master.list.all.txt > ${OUTPUT}/master.list.txt # -u because some directories are listed for more recipes
  100. find ${tmpdir}/sysroots/ | \
  101. sort | sed "s#^${SYSROOTS}##g" > ${OUTPUT}/sysroot.list.txt
  102. diff ${OUTPUT}/master.list.all.txt ${OUTPUT}/master.list.txt > ${OUTPUT}/duplicates.txt
  103. diff ${OUTPUT}/master.list.txt ${OUTPUT}/sysroot.list.txt > ${OUTPUT}/diff.all.txt
  104. grep "^> ." ${OUTPUT}/diff.all.txt | sed 's/^> //g' > ${OUTPUT}/diff.txt
  105. for item in ${WHITELIST}; do
  106. sed -i "\\#^${item}\$#d" ${OUTPUT}/diff.txt;
  107. echo "${item}" >> ${OUTPUT}/used.whitelist.txt
  108. done
  109. if [ -s "$fwhitelist" ] ; then
  110. cat $fwhitelist >> ${OUTPUT}/used.whitelist.txt
  111. cat $fwhitelist | grep -v '^#' | while read item; do
  112. sed -i "\\#^${item}\$#d" ${OUTPUT}/diff.txt;
  113. done
  114. fi
  115. # too many false positives for directories
  116. # echo "Following files are installed in sysroot at least twice"
  117. # cat ${OUTPUT}/duplicates
  118. RESULT=`cat ${OUTPUT}/diff.txt | wc -l`
  119. if [ "${RESULT}" != "0" ] ; then
  120. echo "ERROR: ${RESULT} issues were found."
  121. echo "ERROR: Following files are installed in sysroot, but not tracked by sstate:"
  122. cat ${OUTPUT}/diff.txt
  123. else
  124. echo "INFO: All files are tracked by sstate or were explicitly ignored by this script"
  125. fi
  126. echo "INFO: Output written in: ${OUTPUT}"
  127. exit ${RESULT}