sstate-sysroot-cruft.sh 5.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185
  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/.registry/.* \
  93. .*/usr/lib/php5/php/.depdb \
  94. .*/usr/lib/php5/php/.depdblock \
  95. .*/usr/lib/php5/php/.filemap \
  96. .*/usr/lib/php5/php/.lock \
  97. "
  98. # generated by toolchain
  99. WHITELIST="${WHITELIST} \
  100. [^/]*-tcbootstrap/lib \
  101. "
  102. # generated by useradd.bbclass
  103. WHITELIST="${WHITELIST} \
  104. [^/]*/home \
  105. [^/]*/home/xuser \
  106. [^/]*/home/xuser/.bashrc \
  107. [^/]*/home/xuser/.profile \
  108. [^/]*/home/builder \
  109. [^/]*/home/builder/.bashrc \
  110. [^/]*/home/builder/.profile \
  111. "
  112. # generated by image.py for WIC
  113. # introduced in oe-core commit 861ce6c5d4836df1a783be3b01d2de56117c9863
  114. WHITELIST="${WHITELIST} \
  115. [^/]*/imgdata \
  116. [^/]*/imgdata/[^/]*\.env \
  117. "
  118. # generated by fontcache.bbclass
  119. WHITELIST="${WHITELIST} \
  120. .*/var/cache/fontconfig/ \
  121. "
  122. SYSROOTS="`readlink -f ${tmpdir}`/sysroots/"
  123. mkdir ${OUTPUT}
  124. find ${tmpdir}/sstate-control -name \*.populate-sysroot\* -o -name \*.populate_sysroot\* -o -name \*.package\* | xargs cat | grep sysroots | \
  125. sed 's#/$##g; s#///*#/#g' | \
  126. # work around for paths ending with / for directories and multiplied // (e.g. paths to native sysroot)
  127. sort | sed "s#^${SYSROOTS}##g" > ${OUTPUT}/master.list.all.txt
  128. sort -u ${OUTPUT}/master.list.all.txt > ${OUTPUT}/master.list.txt # -u because some directories are listed for more recipes
  129. find ${tmpdir}/sysroots/ | \
  130. sort | sed "s#^${SYSROOTS}##g" > ${OUTPUT}/sysroot.list.txt
  131. diff ${OUTPUT}/master.list.all.txt ${OUTPUT}/master.list.txt > ${OUTPUT}/duplicates.txt
  132. diff ${OUTPUT}/master.list.txt ${OUTPUT}/sysroot.list.txt > ${OUTPUT}/diff.all.txt
  133. grep "^> ." ${OUTPUT}/diff.all.txt | sed 's/^> //g' > ${OUTPUT}/diff.txt
  134. for item in ${WHITELIST}; do
  135. sed -i "\\#^${item}\$#d" ${OUTPUT}/diff.txt;
  136. echo "${item}" >> ${OUTPUT}/used.whitelist.txt
  137. done
  138. if [ -s "$fwhitelist" ] ; then
  139. cat $fwhitelist >> ${OUTPUT}/used.whitelist.txt
  140. cat $fwhitelist | grep -v '^#' | while read item; do
  141. sed -i "\\#^${item}\$#d" ${OUTPUT}/diff.txt;
  142. done
  143. fi
  144. # too many false positives for directories
  145. # echo "Following files are installed in sysroot at least twice"
  146. # cat ${OUTPUT}/duplicates
  147. RESULT=`cat ${OUTPUT}/diff.txt | wc -l`
  148. if [ "${RESULT}" != "0" ] ; then
  149. echo "ERROR: ${RESULT} issues were found."
  150. echo "ERROR: Following files are installed in sysroot, but not tracked by sstate:"
  151. cat ${OUTPUT}/diff.txt
  152. else
  153. echo "INFO: All files are tracked by sstate or were explicitly ignored by this script"
  154. fi
  155. echo "INFO: Output written in: ${OUTPUT}"
  156. exit ${RESULT}