sstate-sysroot-cruft.sh 5.1 KB

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