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