add changes from actual run

This commit is contained in:
josch 2014-06-18 07:03:42 +02:00
parent 637aa89de1
commit d07f55519b
3 changed files with 108 additions and 41 deletions

View file

@ -20,5 +20,28 @@ which can be added to sbuild by applying
Any unused dependencies can then be found by investigating the file Any unused dependencies can then be found by investigating the file
`unneededdepends.list`. `unneededdepends.list`.
Bugs: when investigating which build dependencies are unused, virtual packages The process can be automated for multiple packages by passing `dsc` files to
are not taken into account. `run.sh`:
$ ./run.sh ../mysources/*.dsc
This script will put the successful builds in `buildsuccess.list` and the found
unused build dependencies as `*.unusedbd` for each `dsc` file in the current
directory. A second pass on the successfully built `dsc` files will then check
each of the found unused build dependencies for their validity by replacing
them by an empty equivs package one after another. The results of that run are
stored in `*.unusedbd.real` files for each `dsc` file in the current directory.
The `run.sh` script expects to find `findunusedbd.sh` directly under `/home`.
Best try this out in a chroot to not mess with the host system.
Customize the schroot:
$ sbuild-shell source:sid-amd64-sbuild
$ echo 'Acquire::Check-Valid-Until "false";' > /etc/apt/apt.conf.d/80-nocheckvaliduntil
$ apt-get install equivs --no-install-recommends
Bugs:
- when investigating which build dependencies are unused, virtual packages are not taken into account
- maybe the fake equivs package can be built outside the schroot to avoid the additional dependencies for installing equivs
- maybe equivs can be avoided altogether by finding a way to edit debian/control on the fly

84
findunusedbd.sh Executable file → Normal file
View file

@ -1,52 +1,52 @@
#!/bin/sh -ex #!/bin/sh -ex
# start this script without arguments and then start sbuild as: # start this script without arguments and then start sbuild as:
# #
# sbuild --chroot-setup-commands='/home/josch/prebuildcmd.sh chroot-setup' --pre-realbuild-commands='/home/josch/prebuildcmd.sh pre-realbuild' --post-realbuild-commands='/home/josch/prebuildcmd.sh post-realbuild' # sbuild --chroot-setup-commands='/home/prebuildcmd.sh chroot-setup' --pre-realbuild-commands='/home/prebuildcmd.sh pre-realbuild' --post-realbuild-commands='/home/prebuildcmd.sh post-realbuild'
if [ "$#" -ne 1 ]; then if [ "$#" -eq 0 ]; then
rm -rf /home/josch/myfifo /home/josch/myfifo2 /tmp/pkglists rm -rf /home/myfifo /home/myfifo2 /tmp/pkglists
mkfifo /home/josch/myfifo mkfifo /home/myfifo
mkfifo /home/josch/myfifo2 mkfifo /home/myfifo2
mkdir -p /tmp/pkglists mkdir -p /tmp/pkglists
# strip the architecture qualifier # strip the architecture qualifier
cat /home/josch/myfifo | cut -d ':' -f 1 | sort > initialselection.list cat /home/myfifo | cut -d ':' -f 1 | sort > initialselection.list
echo > /home/josch/myfifo2 echo > /home/myfifo2
cat /home/josch/myfifo | cut -d ':' -f 1 | sort > fullselection.list cat /home/myfifo | cut -d ':' -f 1 | sort > fullselection.list
echo > /home/josch/myfifo2 echo > /home/myfifo2
# get all packages that were installed on top of the base packages # get all packages that were installed on top of the base packages
comm -13 initialselection.list fullselection.list > bdselection.list comm -13 initialselection.list fullselection.list > bdselection.list
while true; do while true; do
pkgname=`cat /home/josch/myfifo | cut -d ':' -f 1` pkgname=`cat /home/myfifo | cut -d ':' -f 1`
echo > /home/josch/myfifo2 echo > /home/myfifo2
# end loop when packagename is empty # end loop when packagename is empty
[ -z "$pkgname" ] && break [ -z "$pkgname" ] && break
# check if the package was installed as its build dependencies # check if the package was installed as its build dependencies
if grep --line-regexp $pkgname bdselection.list; then if grep --line-regexp $pkgname bdselection.list; then
cat /home/josch/myfifo | sort > "/tmp/pkglists/$pkgname" cat /home/myfifo | sort > "/tmp/pkglists/$pkgname"
else else
cat /home/josch/myfifo > /dev/null cat /home/myfifo > /dev/null
fi fi
echo > /home/josch/myfifo2 echo > /home/myfifo2
done done
cat /home/josch/myfifo | sed 's/, \+/\n/'g \ cat /home/myfifo | sed 's/, \+/\n/'g \
| sed 's/\([a-zA-Z0-9][a-zA-Z0-9+.-]*\).*/\1/' \ | sed 's/\([a-zA-Z0-9][a-zA-Z0-9+.-]*\).*/\1/' \
> /tmp/sbuild-dummy-depends > /tmp/sbuild-dummy-depends
echo > /home/josch/myfifo2 echo > /home/myfifo2
SCHROOT_SESSION_ID=`cat /home/josch/myfifo`; SCHROOT_SESSION_ID=`cat /home/myfifo`;
echo > /home/josch/myfifo2 echo > /home/myfifo2
# start fatrace in the mounted directory # start fatrace in the mounted directory
( (
cd /var/lib/schroot/mount/$SCHROOT_SESSION_ID; cd /var/lib/schroot/mount/$SCHROOT_SESSION_ID;
sudo fatrace --current-mount > /home/josch/fatrace.log & fatrace --current-mount > /home/fatrace.log &
FATRACE_PID=$!; FATRACE_PID=$!;
cat /home/josch/myfifo > /dev/null; cat /home/myfifo > /dev/null;
echo > /home/josch/myfifo2 echo > /home/myfifo2
sudo kill $FATRACE_PID; kill $FATRACE_PID;
) )
# clean up the fatrace log to only include unique paths # clean up the fatrace log to only include unique paths
sed 's/\/var\/lib\/schroot\/mount\/[^\/]\+//' /home/josch/fatrace.log \ sed 's/\/var\/lib\/schroot\/mount\/[^\/]\+//' /home/fatrace.log \
| awk '{ print $3; }' \ | awk '{ print $3; }' \
| grep -v ^/build \ | grep -v ^/build \
| sort \ | sort \
@ -62,23 +62,23 @@ else
case "$1" in case "$1" in
chroot-setup) chroot-setup)
env env
dpkg --get-selections | awk '{ print $1; }' > /home/josch/myfifo dpkg --get-selections | awk '{ print $1; }' > /home/myfifo
cat /home/josch/myfifo2 > /dev/null cat /home/myfifo2 > /dev/null
;; ;;
pre-realbuild) pre-realbuild)
# get the current selection so that the parent script can find the additional packages that were installed # get the current selection so that the parent script can find the additional packages that were installed
dpkg --get-selections | awk '{ print $1; }' > /home/josch/myfifo dpkg --get-selections | awk '{ print $1; }' > /home/myfifo
cat /home/josch/myfifo2 > /dev/null cat /home/myfifo2 > /dev/null
# output the files belonging to all packages # output the files belonging to all packages
for pkg in `dpkg --get-selections | awk '{ print $1; }'`; do for pkg in `dpkg --get-selections | awk '{ print $1; }'`; do
echo $pkg > /home/josch/myfifo echo $pkg > /home/myfifo
cat /home/josch/myfifo2 > /dev/null cat /home/myfifo2 > /dev/null
dpkg -L $pkg > /home/josch/myfifo dpkg -L $pkg > /home/myfifo
cat /home/josch/myfifo2 > /dev/null cat /home/myfifo2 > /dev/null
done done
# output an empty line to indicate the end # output an empty line to indicate the end
echo > /home/josch/myfifo echo > /home/myfifo
cat /home/josch/myfifo2 > /dev/null cat /home/myfifo2 > /dev/null
# output the dependencies of the sbuild dummy package # output the dependencies of the sbuild dummy package
dpkg --get-selections | awk '{ print $1; }' \ dpkg --get-selections | awk '{ print $1; }' \
| grep sbuild-build-depends \ | grep sbuild-build-depends \
@ -86,15 +86,21 @@ else
| grep -v sbuild-build-depends-essential-dummy \ | grep -v sbuild-build-depends-essential-dummy \
| grep -v sbuild-build-depends-lintian-dummy \ | grep -v sbuild-build-depends-lintian-dummy \
| xargs -I {} dpkg-query --showformat='${Depends}\n' --show {} \ | xargs -I {} dpkg-query --showformat='${Depends}\n' --show {} \
> /home/josch/myfifo > /home/myfifo
cat /home/josch/myfifo2 > /dev/null cat /home/myfifo2 > /dev/null
# output the schroot id to start tracing # output the schroot id to start tracing
echo $SCHROOT_SESSION_ID > /home/josch/myfifo echo $SCHROOT_SESSION_ID > /home/myfifo
cat /home/josch/myfifo2 > /dev/null cat /home/myfifo2 > /dev/null
;; ;;
post-realbuild) post-realbuild)
echo "done" > /home/josch/myfifo echo "done" > /home/myfifo
cat /home/josch/myfifo2 > /dev/null cat /home/myfifo2 > /dev/null
;;
equivs)
pkgname="$2"
# create and install a package with same name and version but without dependencies
apt-cache show --no-all-versions $pkgname | grep -v "^Depends:" | grep -v "^Pre-Depends:" | equivs-build -
dpkg -i ${pkgname}_*.deb
;; ;;
*) *)
echo "invalid argument: $1" >&2 echo "invalid argument: $1" >&2

38
run.sh Normal file
View file

@ -0,0 +1,38 @@
#!/bin/sh -x
if [ $# -eq 0 ]; then
echo "usage: $0 foo.dsc [bar.dsc ...]"
exit 1
fi
echo > buildsuccess.list
for dsc in $1; do
echo $dsc
/home/findunusedbd.sh &
sbuild --no-arch-all \
--chroot-setup-commands='/home/findunusedbd.sh chroot-setup' \
--pre-realbuild-commands='/home/findunusedbd.sh pre-realbuild' \
--post-realbuild-commands='/home/findunusedbd.sh post-realbuild' \
"$dsc"
ret=$?
rm -f *.deb *.udeb *.changes
if [ $ret -eq 0 ] && [ -s unneededdepends.list ]; then
mv unneededdepends.list `basename $dsc .dsc`.unusedbd
echo $dsc >> buildsuccess.list
fi
done
while read dscname; do
echo $dscname
unusedbdname=`basename $dscname .dsc`.unusedbd
while read bd; do
# now run sbuild with "findunusedbd.sh equivs" creating a fake equivs package
sbuild --no-arch-all \
--chroot-setup-commands="/home/findunusedbd.sh equivs $bd" \
"$dscname"
if [ $? -eq 0 ]; then
echo $bd >> "${unusedbdname}".real
fi
rm -f *.deb *.udeb *.changes
done < $unusedbdname
done < buildsuccess.list