2007-03-05 00:14:16 +03:00
#!/bin/sh -efu
2002-03-25 23:37:46 +03:00
#
2006-01-11 03:46:13 +03:00
# Copyright (C) 2000-2006 Dmitry V. Levin <ldv@altlinux.org>
2007-03-05 00:14:16 +03:00
# Copyright (C) 2007 Alexey Tourbin <at@altlinux.org>
2003-04-22 17:49:49 +04:00
#
2002-03-25 23:37:46 +03:00
# find-requires - generate list of linux-specific package requires.
# Inspired by tool with same name from RPM distribution.
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
#
2006-01-11 19:36:22 +03:00
. @RPMCONFIGDIR@/functions
ValidateBuildRoot
2002-03-25 23:37:46 +03:00
2007-03-05 00:14:16 +03:00
workdir=
2003-04-22 17:48:31 +04:00
exit_handler()
2002-03-25 23:37:46 +03:00
{
2003-04-22 17:48:31 +04:00
local rc=$?
trap - EXIT
2007-03-05 00:14:16 +03:00
[ -z "$workdir" ] || rm -rf "$workdir"
cat >/dev/null
2003-04-22 17:48:31 +04:00
exit $rc
2002-03-25 23:37:46 +03:00
}
2007-03-05 00:14:16 +03:00
trap exit_handler EXIT HUP INT QUIT PIPE TERM
methods=$(SetupMethods req "$RPM_FINDREQ_METHOD")
if [ -z "$methods" ]; then
Info "AutoReq disabled, nothing to do"
exit 0
fi
workdir=$(mktemp -dt "$PROG".XXXXXXXX)
# filter file list through TOPDIR and SKIPLIST patterns
while IFS= read -r f; do
fname="${f#$RPM_BUILD_ROOT}"
2008-03-30 03:14:38 +04:00
printf '%s\n' "$fname" >&3
2007-03-05 00:14:16 +03:00
if [ -n "${RPM_FINDREQ_TOPDIR-}" ] && [ -z "${fname%%$RPM_FINDREQ_TOPDIR/*}" ]; then
Debug "skip $f due to RPM_FINDREQ_TOPDIR=$RPM_FINDREQ_TOPDIR"
continue
fi
if [ -n "${RPM_FINDREQ_SKIPLIST-}" ]; then
for skip in $RPM_FINDREQ_SKIPLIST; do
if [ -z "${fname##$skip}" ]; then
Debug "skip $f due to RPM_FINDREQ_SKIPLIST pattern $skip"
continue 2
fi
done
fi
2011-02-09 06:56:08 +03:00
# absolute symbolic links should not be passed down to file(1)
if [ -L "$f" ]; then
to="$(readlink "$f")"
if [ -n "$to" -a -z "${to##/*}" ]; then
if [ -e "$f" ]; then
printf '%s\t symbolic link to `%s'\''\n' "$f" "$to"
else
printf '%s\t broken symbolic link to `%s'\''\n' "$f" "$to"
fi
continue
fi >&4
fi
2008-01-22 22:06:54 +03:00
printf '%s\n' "$f"
2011-02-09 06:56:08 +03:00
done >"$workdir"/files 3>"$RPM_BUILD_ROOT/.files:$RPM_SUBPACKAGE_NAME" 4>"$workdir"/files+types
2007-03-05 00:14:16 +03:00
if ! [ -s "$workdir"/files ]; then
Info "empty file list, nothing to do"
exit 0
fi
# filter file list through file(1) to append types
2011-02-09 06:56:08 +03:00
if ! file -NF$'\t' -f "$workdir"/files >>"$workdir"/files+types; then
2007-03-05 00:14:16 +03:00
sed -n '/\t *ERROR:/p' "$workdir"/files+types >&2
exit 1
fi
found=
RunMethod()
{
local exe="$1"; shift
local filter="$exe".files
if ! [ -x "$filter" ]; then
# XXX should be Fatal
Info "$filter not available"
return
fi
local filelist="$workdir/${exe##*/}".files
local deplist="$workdir/${exe##*/}".deps
Debug "running $filter"
2008-06-04 03:26:23 +04:00
"$filter" <"$workdir"/files+types >"$filelist" ||
Fatal "$filter failed"
2007-03-05 00:14:16 +03:00
Verbose "$filter: $(wc -l <"$filelist") files"
[ -s "$filelist" ] || return 0
# XXX validate $filelist
Debug "running $exe"
2008-06-04 03:26:23 +04:00
"$exe" <"$filelist" >"$deplist" ||
Fatal "$exe failed"
2007-08-11 00:56:43 +04:00
if [ -s "$deplist" ]; then
LC_COLLATE=C sort -u -o "$deplist" "$deplist"
Verbose "$exe: $(wc -l <"$deplist") dependencies"
found=1
else
rm -f "$deplist"
fi
2007-03-05 00:14:16 +03:00
}
2009-09-08 23:37:14 +04:00
export RPM_FINDPACKAGE_COMMANDS_LOG="$RPM_BUILD_ROOT"/.findpackage-commands
>"$RPM_FINDPACKAGE_COMMANDS_LOG"
2007-03-05 00:14:16 +03:00
Info "running scripts ($methods)"
RunMethods req "$methods" RunMethod
2011-01-22 23:35:34 +03:00
if [ -n "$found" ]; then
(set +f && LC_ALL=C sort -u -m "$workdir"/*.deps) >"$workdir"/find-requires-deps || false
if [ -n "${RPM_FIND_REQUIRES_FILTER-}" ]; then
(eval "set -x; $RPM_FIND_REQUIRES_FILTER") <"$workdir"/find-requires-deps >"$workdir"/filter-requires-deps
[ $? = 0 ] || Fatal "filter failed"
(cd "$workdir" && diff -U1 find-requires-deps filter-requires-deps) >&2 ||:
cat "$workdir"/filter-requires-deps
else
cat "$workdir"/find-requires-deps
fi
fi
2009-09-08 23:37:14 +04:00
if [ -s "$RPM_FINDPACKAGE_COMMANDS_LOG" ]; then
LC_ALL=C sort -u -o "$RPM_FINDPACKAGE_COMMANDS_LOG"{,}
Info "FINDPACKAGE-COMMANDS:" $(cat <"$RPM_FINDPACKAGE_COMMANDS_LOG")
fi