diff options
| -rwxr-xr-x | scripts/sstate-sysroot-cruft.sh | 96 |
1 files changed, 85 insertions, 11 deletions
diff --git a/scripts/sstate-sysroot-cruft.sh b/scripts/sstate-sysroot-cruft.sh index ca2316cdcc..f62485eaaa 100755 --- a/scripts/sstate-sysroot-cruft.sh +++ b/scripts/sstate-sysroot-cruft.sh | |||
| @@ -17,6 +17,15 @@ Options: | |||
| 17 | --tmpdir=<tmpdir> | 17 | --tmpdir=<tmpdir> |
| 18 | Specify tmpdir, will use the environment variable TMPDIR if it is not specified. | 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). | 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. | ||
| 20 | EOF | 29 | EOF |
| 21 | } | 30 | } |
| 22 | 31 | ||
| @@ -33,6 +42,11 @@ while [ -n "$1" ]; do | |||
| 33 | [ -d "$tmpdir" ] || echo_error "Invalid argument to --tmpdir" | 42 | [ -d "$tmpdir" ] || echo_error "Invalid argument to --tmpdir" |
| 34 | shift | 43 | shift |
| 35 | ;; | 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 | ;; | ||
| 36 | --help|-h) | 50 | --help|-h) |
| 37 | usage | 51 | usage |
| 38 | exit 0 | 52 | exit 0 |
| @@ -51,28 +65,88 @@ done | |||
| 51 | [ -d "$tmpdir" ] || echo_error "Invalid tmpdir \"$tmpdir\"" | 65 | [ -d "$tmpdir" ] || echo_error "Invalid tmpdir \"$tmpdir\"" |
| 52 | 66 | ||
| 53 | OUTPUT=${tmpdir}/sysroot.cruft.`date "+%s"` | 67 | OUTPUT=${tmpdir}/sysroot.cruft.`date "+%s"` |
| 54 | WHITELIST="\/var\/pseudo\($\|\/[^\/]*$\) \/shlibs$ \.pyc$ \.pyo$" | 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 \ | ||
| 93 | " | ||
| 94 | |||
| 95 | # generated by sgml-common-native | ||
| 96 | WHITELIST="${WHITELIST} \ | ||
| 97 | .*/etc/sgml/sgml-docbook.bak \ | ||
| 98 | " | ||
| 99 | |||
| 100 | # generated by toolchain | ||
| 101 | WHITELIST="${WHITELIST} \ | ||
| 102 | [^/]*-tcbootstrap/lib \ | ||
| 103 | " | ||
| 104 | |||
| 105 | # generated by useradd.bbclass | ||
| 106 | WHITELIST="${WHITELIST} \ | ||
| 107 | [^/]*/home \ | ||
| 108 | [^/]*/home/xuser \ | ||
| 109 | " | ||
| 110 | |||
| 111 | SYSROOTS="`readlink -f ${tmpdir}`/sysroots/" | ||
| 55 | 112 | ||
| 56 | mkdir ${OUTPUT} | 113 | mkdir ${OUTPUT} |
| 57 | find ${tmpdir}/sstate-control -name \*.populate-sysroot\* -o -name \*.package\* | xargs cat | grep sysroots | \ | 114 | find ${tmpdir}/sstate-control -name \*.populate-sysroot\* -o -name \*.populate_sysroot\* -o -name \*.package\* | xargs cat | grep sysroots | \ |
| 58 | sed 's#/$##g; s#///*#/#g' | \ | 115 | sed 's#/$##g; s#///*#/#g' | \ |
| 59 | # work around for paths ending with / for directories and multiplied // (e.g. paths to native sysroot) | 116 | # work around for paths ending with / for directories and multiplied // (e.g. paths to native sysroot) |
| 60 | sort > ${OUTPUT}/master.list.all | 117 | sort | sed "s#^${SYSROOTS}##g" > ${OUTPUT}/master.list.all.txt |
| 61 | sort -u ${OUTPUT}/master.list.all > ${OUTPUT}/master.list # -u because some directories are listed for more recipes | 118 | sort -u ${OUTPUT}/master.list.all.txt > ${OUTPUT}/master.list.txt # -u because some directories are listed for more recipes |
| 62 | find ${tmpdir}/sysroots/ | \ | 119 | find ${tmpdir}/sysroots/ | \ |
| 63 | sort > ${OUTPUT}/sysroot.list | 120 | sort | sed "s#^${SYSROOTS}##g" > ${OUTPUT}/sysroot.list.txt |
| 64 | 121 | ||
| 65 | diff ${OUTPUT}/master.list.all ${OUTPUT}/master.list > ${OUTPUT}/duplicates | 122 | diff ${OUTPUT}/master.list.all.txt ${OUTPUT}/master.list.txt > ${OUTPUT}/duplicates.txt |
| 66 | diff ${OUTPUT}/master.list ${OUTPUT}/sysroot.list > ${OUTPUT}/diff.all | 123 | diff ${OUTPUT}/master.list.txt ${OUTPUT}/sysroot.list.txt > ${OUTPUT}/diff.all.txt |
| 67 | 124 | ||
| 68 | cp ${OUTPUT}/diff.all ${OUTPUT}/diff | 125 | grep "^> ." ${OUTPUT}/diff.all.txt | sed 's/^> //g' > ${OUTPUT}/diff.txt |
| 69 | for item in ${WHITELIST}; do | 126 | for item in ${WHITELIST}; do |
| 70 | sed -i "/${item}/d" ${OUTPUT}/diff; | 127 | sed -i "\\#^${item}\$#d" ${OUTPUT}/diff.txt; |
| 128 | echo "${item}" >> ${OUTPUT}/used.whitelist.txt | ||
| 71 | done | 129 | done |
| 72 | 130 | ||
| 131 | if [ -s "$fwhitelist" ] ; then | ||
| 132 | cat $fwhitelist >> ${OUTPUT}/used.whitelist.txt | ||
| 133 | cat $fwhitelist | grep -v '^#' | while read item; do | ||
| 134 | sed -i "\\#^${item}\$#d" ${OUTPUT}/diff.txt; | ||
| 135 | done | ||
| 136 | fi | ||
| 73 | # too many false positives for directories | 137 | # too many false positives for directories |
| 74 | # echo "Following files are installed in sysroot at least twice" | 138 | # echo "Following files are installed in sysroot at least twice" |
| 75 | # cat ${OUTPUT}/duplicates | 139 | # cat ${OUTPUT}/duplicates |
| 76 | 140 | ||
| 77 | echo "Following files are installed in sysroot, but not tracked by sstate" | 141 | RESULT=`cat ${OUTPUT}/diff.txt | wc -l` |
| 78 | cat ${OUTPUT}/diff | 142 | |
| 143 | if [ "${RESULT}" != "0" ] ; then | ||
| 144 | echo "ERROR: ${RESULT} issues were found." | ||
| 145 | echo "ERROR: Following files are installed in sysroot, but not tracked by sstate:" | ||
| 146 | cat ${OUTPUT}/diff.txt | ||
| 147 | else | ||
| 148 | echo "INFO: All files are tracked by sstate or were explicitly ignored by this script" | ||
| 149 | fi | ||
| 150 | |||
| 151 | echo "INFO: Output written in: ${OUTPUT}" | ||
| 152 | exit ${RESULT} | ||
