blob: b6166aa1b29c0c9ee37bc4d5f746902cec13e501 [file] [log] [blame]
Patrick Williamsc124f4f2015-09-15 14:41:29 -05001#!/bin/sh
2
3# Used to find files installed in sysroot which are not tracked by sstate manifest
4
5# Global vars
6tmpdir=
7
8usage () {
9 cat << EOF
10Welcome to sysroot cruft finding utility.
11$0 <OPTION>
12
13Options:
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.
29EOF
30}
31
32# Print error information and exit.
33echo_error () {
34 echo "ERROR: $1" >&2
35 exit 1
36}
37
38while [ -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
59done
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
67OUTPUT=${tmpdir}/sysroot.cruft.`date "+%s"`
68
69# top level directories
70WHITELIST="[^/]*"
71
72# generated by base-passwd recipe
73WHITELIST="${WHITELIST} \
74 .*/etc/group-\? \
75 .*/etc/passwd-\? \
76"
77# generated by pseudo-native
78WHITELIST="${WHITELIST} \
79 .*/var/pseudo \
80 .*/var/pseudo/[^/]* \
81"
82
83# generated by package.bbclass:SHLIBSDIRS = "${PKGDATA_DIR}/${MLPREFIX}shlibs"
84WHITELIST="${WHITELIST} \
85 .*/shlibs \
86 .*/pkgdata \
87"
88
89# generated by python
90WHITELIST="${WHITELIST} \
91 .*\.pyc \
92 .*\.pyo \
Patrick Williamsd8c66bc2016-06-20 12:57:21 -050093 .*/__pycache__ \
94"
95
96# generated by lua
97WHITELIST="${WHITELIST} \
98 .*\.luac \
Patrick Williamsc124f4f2015-09-15 14:41:29 -050099"
100
101# generated by sgml-common-native
102WHITELIST="${WHITELIST} \
103 .*/etc/sgml/sgml-docbook.bak \
104"
105
Patrick Williamsd8c66bc2016-06-20 12:57:21 -0500106# generated by php
107WHITELIST="${WHITELIST} \
108 .*/usr/lib/php5/php/.channels/.* \
109 .*/usr/lib/php5/php/.registry/.* \
110 .*/usr/lib/php5/php/.depdb \
111 .*/usr/lib/php5/php/.depdblock \
112 .*/usr/lib/php5/php/.filemap \
113 .*/usr/lib/php5/php/.lock \
114"
115
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500116# generated by toolchain
117WHITELIST="${WHITELIST} \
118 [^/]*-tcbootstrap/lib \
119"
120
121# generated by useradd.bbclass
122WHITELIST="${WHITELIST} \
123 [^/]*/home \
124 [^/]*/home/xuser \
Patrick Williamsd8c66bc2016-06-20 12:57:21 -0500125 [^/]*/home/xuser/.bashrc \
126 [^/]*/home/xuser/.profile \
127 [^/]*/home/builder \
128 [^/]*/home/builder/.bashrc \
129 [^/]*/home/builder/.profile \
130"
131
132# generated by image.py for WIC
133# introduced in oe-core commit 861ce6c5d4836df1a783be3b01d2de56117c9863
134WHITELIST="${WHITELIST} \
135 [^/]*/imgdata \
136 [^/]*/imgdata/[^/]*\.env \
137"
138
139# generated by fontcache.bbclass
140WHITELIST="${WHITELIST} \
141 .*/var/cache/fontconfig/ \
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500142"
143
Brad Bishop37a0e4d2017-12-04 01:01:44 -0500144# created by oe.utils.write_ld_so_conf which is used from few bbclasses and recipes:
145# meta/classes/image-prelink.bbclass: oe.utils.write_ld_so_conf(d)
146# meta/classes/insane.bbclass: oe.utils.write_ld_so_conf(d)
147# meta/classes/insane.bbclass: oe.utils.write_ld_so_conf(d)
148# meta/recipes-gnome/gobject-introspection/gobject-introspection_1.48.0.bb: oe.utils.write_ld_so_conf(d)
149# meta/recipes-gnome/gobject-introspection/gobject-introspection_1.48.0.bb: oe.utils.write_ld_so_conf(d)
150# introduced in oe-core commit 7fd1d7e639c2ed7e0699937a5cb245c187b7c811
151# and more visible since added to gobject-introspection in 10e0c1a3a452baa05d160a92a54b2e33cf0fd061
152WHITELIST="${WHITELIST} \
153 [^/]*/etc/ld.so.conf \
154"
155
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500156SYSROOTS="`readlink -f ${tmpdir}`/sysroots/"
157
158mkdir ${OUTPUT}
159find ${tmpdir}/sstate-control -name \*.populate-sysroot\* -o -name \*.populate_sysroot\* -o -name \*.package\* | xargs cat | grep sysroots | \
160 sed 's#/$##g; s#///*#/#g' | \
161 # work around for paths ending with / for directories and multiplied // (e.g. paths to native sysroot)
162 sort | sed "s#^${SYSROOTS}##g" > ${OUTPUT}/master.list.all.txt
163sort -u ${OUTPUT}/master.list.all.txt > ${OUTPUT}/master.list.txt # -u because some directories are listed for more recipes
164find ${tmpdir}/sysroots/ | \
165 sort | sed "s#^${SYSROOTS}##g" > ${OUTPUT}/sysroot.list.txt
166
167diff ${OUTPUT}/master.list.all.txt ${OUTPUT}/master.list.txt > ${OUTPUT}/duplicates.txt
168diff ${OUTPUT}/master.list.txt ${OUTPUT}/sysroot.list.txt > ${OUTPUT}/diff.all.txt
169
170grep "^> ." ${OUTPUT}/diff.all.txt | sed 's/^> //g' > ${OUTPUT}/diff.txt
171for item in ${WHITELIST}; do
172 sed -i "\\#^${item}\$#d" ${OUTPUT}/diff.txt;
173 echo "${item}" >> ${OUTPUT}/used.whitelist.txt
174done
175
176if [ -s "$fwhitelist" ] ; then
177 cat $fwhitelist >> ${OUTPUT}/used.whitelist.txt
178 cat $fwhitelist | grep -v '^#' | while read item; do
179 sed -i "\\#^${item}\$#d" ${OUTPUT}/diff.txt;
180 done
181fi
182# too many false positives for directories
183# echo "Following files are installed in sysroot at least twice"
184# cat ${OUTPUT}/duplicates
185
186RESULT=`cat ${OUTPUT}/diff.txt | wc -l`
187
188if [ "${RESULT}" != "0" ] ; then
189 echo "ERROR: ${RESULT} issues were found."
190 echo "ERROR: Following files are installed in sysroot, but not tracked by sstate:"
191 cat ${OUTPUT}/diff.txt
192else
193 echo "INFO: All files are tracked by sstate or were explicitly ignored by this script"
194fi
195
196echo "INFO: Output written in: ${OUTPUT}"
197exit ${RESULT}