blob: 9c948e932def11f8d53d934e46e7dcf47a084da7 [file] [log] [blame]
Patrick Williamsc124f4f2015-09-15 14:41:29 -05001#!/bin/sh
Brad Bishopc342db32019-05-15 21:57:59 -04002#
3# SPDX-License-Identifier: GPL-2.0-only
4#
Patrick Williamsc124f4f2015-09-15 14:41:29 -05005# Used to find files installed in sysroot which are not tracked by sstate manifest
6
7# Global vars
8tmpdir=
9
10usage () {
11 cat << EOF
12Welcome to sysroot cruft finding utility.
13$0 <OPTION>
14
15Options:
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.
31EOF
32}
33
34# Print error information and exit.
35echo_error () {
36 echo "ERROR: $1" >&2
37 exit 1
38}
39
40while [ -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
61done
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
69OUTPUT=${tmpdir}/sysroot.cruft.`date "+%s"`
70
71# top level directories
72WHITELIST="[^/]*"
73
74# generated by base-passwd recipe
75WHITELIST="${WHITELIST} \
76 .*/etc/group-\? \
77 .*/etc/passwd-\? \
78"
79# generated by pseudo-native
80WHITELIST="${WHITELIST} \
81 .*/var/pseudo \
82 .*/var/pseudo/[^/]* \
83"
84
85# generated by package.bbclass:SHLIBSDIRS = "${PKGDATA_DIR}/${MLPREFIX}shlibs"
86WHITELIST="${WHITELIST} \
87 .*/shlibs \
88 .*/pkgdata \
89"
90
91# generated by python
92WHITELIST="${WHITELIST} \
93 .*\.pyc \
94 .*\.pyo \
Patrick Williamsd8c66bc2016-06-20 12:57:21 -050095 .*/__pycache__ \
96"
97
98# generated by lua
99WHITELIST="${WHITELIST} \
100 .*\.luac \
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500101"
102
103# generated by sgml-common-native
104WHITELIST="${WHITELIST} \
105 .*/etc/sgml/sgml-docbook.bak \
106"
107
Patrick Williamsd8c66bc2016-06-20 12:57:21 -0500108# generated by php
109WHITELIST="${WHITELIST} \
Brad Bishopd7bf8c12018-02-25 22:55:05 -0500110 .*/usr/lib/php5/php/.channels \
Patrick Williamsd8c66bc2016-06-20 12:57:21 -0500111 .*/usr/lib/php5/php/.channels/.* \
Brad Bishopd7bf8c12018-02-25 22:55:05 -0500112 .*/usr/lib/php5/php/.registry \
Patrick Williamsd8c66bc2016-06-20 12:57:21 -0500113 .*/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 Williamsc124f4f2015-09-15 14:41:29 -0500120# generated by toolchain
121WHITELIST="${WHITELIST} \
122 [^/]*-tcbootstrap/lib \
123"
124
125# generated by useradd.bbclass
126WHITELIST="${WHITELIST} \
127 [^/]*/home \
128 [^/]*/home/xuser \
Patrick Williamsd8c66bc2016-06-20 12:57:21 -0500129 [^/]*/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
138WHITELIST="${WHITELIST} \
139 [^/]*/imgdata \
140 [^/]*/imgdata/[^/]*\.env \
141"
142
143# generated by fontcache.bbclass
144WHITELIST="${WHITELIST} \
145 .*/var/cache/fontconfig/ \
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500146"
147
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500148SYSROOTS="`readlink -f ${tmpdir}`/sysroots/"
149
150mkdir ${OUTPUT}
151find ${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
155sort -u ${OUTPUT}/master.list.all.txt > ${OUTPUT}/master.list.txt # -u because some directories are listed for more recipes
156find ${tmpdir}/sysroots/ | \
157 sort | sed "s#^${SYSROOTS}##g" > ${OUTPUT}/sysroot.list.txt
158
159diff ${OUTPUT}/master.list.all.txt ${OUTPUT}/master.list.txt > ${OUTPUT}/duplicates.txt
160diff ${OUTPUT}/master.list.txt ${OUTPUT}/sysroot.list.txt > ${OUTPUT}/diff.all.txt
161
162grep "^> ." ${OUTPUT}/diff.all.txt | sed 's/^> //g' > ${OUTPUT}/diff.txt
163for item in ${WHITELIST}; do
164 sed -i "\\#^${item}\$#d" ${OUTPUT}/diff.txt;
165 echo "${item}" >> ${OUTPUT}/used.whitelist.txt
166done
167
168if [ -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
173fi
174# too many false positives for directories
175# echo "Following files are installed in sysroot at least twice"
176# cat ${OUTPUT}/duplicates
177
178RESULT=`cat ${OUTPUT}/diff.txt | wc -l`
179
180if [ "${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
184else
185 echo "INFO: All files are tracked by sstate or were explicitly ignored by this script"
186fi
187
188echo "INFO: Output written in: ${OUTPUT}"
189exit ${RESULT}