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