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