sstate-sysroot-cruft.sh 5.2 KB

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