sstate-sysroot-cruft.sh 5.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199
  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. .*/__pycache__ \
  80. "
  81. # generated by lua
  82. WHITELIST="${WHITELIST} \
  83. .*\.luac \
  84. "
  85. # generated by sgml-common-native
  86. WHITELIST="${WHITELIST} \
  87. .*/etc/sgml/sgml-docbook.bak \
  88. "
  89. # generated by php
  90. WHITELIST="${WHITELIST} \
  91. .*/usr/lib/php5/php/.channels \
  92. .*/usr/lib/php5/php/.channels/.* \
  93. .*/usr/lib/php5/php/.registry \
  94. .*/usr/lib/php5/php/.registry/.* \
  95. .*/usr/lib/php5/php/.depdb \
  96. .*/usr/lib/php5/php/.depdblock \
  97. .*/usr/lib/php5/php/.filemap \
  98. .*/usr/lib/php5/php/.lock \
  99. "
  100. # generated by toolchain
  101. WHITELIST="${WHITELIST} \
  102. [^/]*-tcbootstrap/lib \
  103. "
  104. # generated by useradd.bbclass
  105. WHITELIST="${WHITELIST} \
  106. [^/]*/home \
  107. [^/]*/home/xuser \
  108. [^/]*/home/xuser/.bashrc \
  109. [^/]*/home/xuser/.profile \
  110. [^/]*/home/builder \
  111. [^/]*/home/builder/.bashrc \
  112. [^/]*/home/builder/.profile \
  113. "
  114. # generated by image.py for WIC
  115. # introduced in oe-core commit 861ce6c5d4836df1a783be3b01d2de56117c9863
  116. WHITELIST="${WHITELIST} \
  117. [^/]*/imgdata \
  118. [^/]*/imgdata/[^/]*\.env \
  119. "
  120. # generated by fontcache.bbclass
  121. WHITELIST="${WHITELIST} \
  122. .*/var/cache/fontconfig/ \
  123. "
  124. # created by oe.utils.write_ld_so_conf which is used from few bbclasses and recipes:
  125. # meta/classes/image-prelink.bbclass: oe.utils.write_ld_so_conf(d)
  126. # meta/classes/insane.bbclass: oe.utils.write_ld_so_conf(d)
  127. # meta/classes/insane.bbclass: oe.utils.write_ld_so_conf(d)
  128. # meta/recipes-gnome/gobject-introspection/gobject-introspection_1.48.0.bb: oe.utils.write_ld_so_conf(d)
  129. # meta/recipes-gnome/gobject-introspection/gobject-introspection_1.48.0.bb: oe.utils.write_ld_so_conf(d)
  130. # introduced in oe-core commit 7fd1d7e639c2ed7e0699937a5cb245c187b7c811
  131. # and more visible since added to gobject-introspection in 10e0c1a3a452baa05d160a92a54b2e33cf0fd061
  132. WHITELIST="${WHITELIST} \
  133. [^/]*/etc/ld.so.conf \
  134. "
  135. SYSROOTS="`readlink -f ${tmpdir}`/sysroots/"
  136. mkdir ${OUTPUT}
  137. find ${tmpdir}/sstate-control -name \*.populate-sysroot\* -o -name \*.populate_sysroot\* -o -name \*.package\* | xargs cat | grep sysroots | \
  138. sed 's#/$##g; s#///*#/#g' | \
  139. # work around for paths ending with / for directories and multiplied // (e.g. paths to native sysroot)
  140. sort | sed "s#^${SYSROOTS}##g" > ${OUTPUT}/master.list.all.txt
  141. sort -u ${OUTPUT}/master.list.all.txt > ${OUTPUT}/master.list.txt # -u because some directories are listed for more recipes
  142. find ${tmpdir}/sysroots/ | \
  143. sort | sed "s#^${SYSROOTS}##g" > ${OUTPUT}/sysroot.list.txt
  144. diff ${OUTPUT}/master.list.all.txt ${OUTPUT}/master.list.txt > ${OUTPUT}/duplicates.txt
  145. diff ${OUTPUT}/master.list.txt ${OUTPUT}/sysroot.list.txt > ${OUTPUT}/diff.all.txt
  146. grep "^> ." ${OUTPUT}/diff.all.txt | sed 's/^> //g' > ${OUTPUT}/diff.txt
  147. for item in ${WHITELIST}; do
  148. sed -i "\\#^${item}\$#d" ${OUTPUT}/diff.txt;
  149. echo "${item}" >> ${OUTPUT}/used.whitelist.txt
  150. done
  151. if [ -s "$fwhitelist" ] ; then
  152. cat $fwhitelist >> ${OUTPUT}/used.whitelist.txt
  153. cat $fwhitelist | grep -v '^#' | while read item; do
  154. sed -i "\\#^${item}\$#d" ${OUTPUT}/diff.txt;
  155. done
  156. fi
  157. # too many false positives for directories
  158. # echo "Following files are installed in sysroot at least twice"
  159. # cat ${OUTPUT}/duplicates
  160. RESULT=`cat ${OUTPUT}/diff.txt | wc -l`
  161. if [ "${RESULT}" != "0" ] ; then
  162. echo "ERROR: ${RESULT} issues were found."
  163. echo "ERROR: Following files are installed in sysroot, but not tracked by sstate:"
  164. cat ${OUTPUT}/diff.txt
  165. else
  166. echo "INFO: All files are tracked by sstate or were explicitly ignored by this script"
  167. fi
  168. echo "INFO: Output written in: ${OUTPUT}"
  169. exit ${RESULT}