rpm-build/scripts/find-package.in

500 lines
16 KiB
Plaintext
Raw Normal View History

#!/bin/sh -efu
2002-03-25 23:37:46 +03:00
#
2007-08-08 00:49:48 +04:00
# This file provides FindPackage() function which maps paths and
# commands, such as found in shell scripts, to rpm dependencies.
#
# Usage:
# . @RPMCONFIGDIR@/find-package
2007-08-08 00:49:48 +04:00
# FindPackage src [path...] [command...]
#
# Arguments:
# src - the file being processed, used for diagnostics;
# also, if the file appears to reside under */sbin/
# directory, the PATH search order is adjusted
# so as to better match root code
2007-08-08 00:49:48 +04:00
# path - absolute path to file, e.g. /bin/cat
# command - executable expected to reside under standard
# PATH directories, e.g. cat
#
2003-04-22 19:11:52 +04:00
# Copyright (C) 2002-2003 Dmitry V. Levin <ldv@altlinux.org>
2008-01-24 22:28:01 +03:00
# Copyright (C) 2007,2008 Alexey Tourbin <at@altlinux.org>
2002-03-25 23:37:46 +03:00
#
# 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
#
2003-11-09 19:47:45 +03:00
. @RPMCONFIGDIR@/functions
2002-03-25 23:37:46 +03:00
# We use different PATHs for */sbin/ and non-/sbin scripts. However,
# the distinction is not quite reliable -- there is simply no easy way
# to discriminate between root-only and user-capable shell code. Thus
# we must use rather conservative path adjustment: 1) the set of user
# and root directories is the same, it is only the order that differs;
# 2) / has main priority over /usr, while as "bin vs sbin" distinction has
# only secondary priority. The reason is that / has only "most important"
# contents, and /usr is used virtually "for everything else", whatever it is.
# Now that / has a boost, there are simply less chances to end up with
# unrelated dependencies.
DEF_RPM_FINDPACKAGE_USER_PATH=/bin:/sbin:/usr/bin:/usr/sbin:/usr/X11R6/bin:/usr/games
DEF_RPM_FINDPACKAGE_ROOT_PATH=/sbin:/bin:/usr/sbin:/usr/bin:/usr/X11R6/bin:/usr/games
# RPM_FINDPACKAGE_PATH is exported by rpm-build
RPM_FINDPACKAGE_USER_PATH="$(IFS="$IFS:"; set -f; echo '' ${RPM_FINDPACKAGE_PATH-} $DEF_RPM_FINDPACKAGE_USER_PATH |sed -e 's/ */:/g; s/^://')"
RPM_FINDPACKAGE_ROOT_PATH="$(IFS="$IFS:"; set -f; echo '' ${RPM_FINDPACKAGE_PATH-} $DEF_RPM_FINDPACKAGE_ROOT_PATH |sed -e 's/ */:/g; s/^://')"
Debug "RPM_FINDPACKAGE_USER_PATH=$RPM_FINDPACKAGE_USER_PATH"
Debug "RPM_FINDPACKAGE_ROOT_PATH=$RPM_FINDPACKAGE_ROOT_PATH"
# Below we use 'local Verbose=Info' to increase per-case verbosity.
Verbose=Verbose
find-package: enhanced path lookups under buildroot, added special case for dir dependencies $ less alterator-install-common-desktop-0.11-alt1.i586.rpm |grep help -rwxr-xr-x 1 root root 972 Oct 30 18:38 /usr/share/alterator/help/ru_RU/basesystem.html -rwxr-xr-x 1 root root 340 Oct 30 18:38 /usr/share/alterator/help/ru_RU/kbd.html -rwxr-xr-x 1 root root 2233 Oct 30 18:38 /usr/share/alterator/help/ru_RU/license.html -rwxr-xr-x 1 root root 1280 Oct 30 18:38 /usr/share/alterator/help/ru_RU/lilo.html -rwxr-xr-x 1 root root 3032 Oct 30 18:38 /usr/share/alterator/help/ru_RU/network.html -rwxr-xr-x 1 root root 4840 Oct 30 18:38 /usr/share/alterator/help/ru_RU/packages.html -rwxr-xr-x 1 root root 1928 Oct 30 18:38 /usr/share/alterator/help/ru_RU/root.html -rwxr-xr-x 1 root root 1387 Oct 30 18:38 /usr/share/alterator/help/ru_RU/time.html -rwxr-xr-x 1 root root 1223 Oct 30 18:38 /usr/share/alterator/help/ru_RU/user.html -rwxr-xr-x 1 root root 11024 Oct 30 18:38 /usr/share/alterator/help/ru_RU/vm.html -rwxr-xr-x 1 root root 1789 Oct 30 18:38 /usr/share/alterator/help/ru_RU/x11.html lrwxrwxrwx 1 root root 31 Oct 30 18:38 /usr/share/alterator/help/ru_UA -> /usr/share/alterator/help/ru_RU $ %files ... %_datadir/alterator/help/ru_RU/* %_datadir/alterator/help/ru_UA The package referes ru_RU directory but does not own the directory. Old behaviour: unmet dependency. > alterator-icons-lite-0.4.0-alt1 Requires(rpmlib) rpmlib(PayloadFilesHavePrefix) <= 4.0-1 > +alterator-install-common-desktop-0.11-alt1 Requires /usr/share/alterator/help/ru_RU > alterator-install-common-desktop-0.11-alt1 Requires alterator-autoinstall New behaviour: though the package does not explicitly own the directory, it has some files packaged under the directory. Because of this, ru_UA symlink will not be broken after install. We chose to be forgiving: symlinks.req: WARNING: /usr/src/tmp/alterator-install2-desktop-buildroot/usr/share/alterator/help/ru_UA: directory /usr/share/alterator/help/ru_RU not owned by the package
2008-01-23 01:26:43 +03:00
FindByPathUnderBuildroot()
{
local f="$1" rep="$2" xbrep; shift 2 || return
[ -n "${RPM_BUILD_ROOT-}" ] || return 0
MatchBuildroot()
{
[ -n "$1" ] &&
[ -z "${1##$RPM_BUILD_ROOT/*}" ]
}
StatPrint()
{
[ -e "$1" -o -L "$1" ] &&
printf '%s\n' "${1#$RPM_BUILD_ROOT}"
}
find-package: enhanced path lookups under buildroot, added special case for dir dependencies $ less alterator-install-common-desktop-0.11-alt1.i586.rpm |grep help -rwxr-xr-x 1 root root 972 Oct 30 18:38 /usr/share/alterator/help/ru_RU/basesystem.html -rwxr-xr-x 1 root root 340 Oct 30 18:38 /usr/share/alterator/help/ru_RU/kbd.html -rwxr-xr-x 1 root root 2233 Oct 30 18:38 /usr/share/alterator/help/ru_RU/license.html -rwxr-xr-x 1 root root 1280 Oct 30 18:38 /usr/share/alterator/help/ru_RU/lilo.html -rwxr-xr-x 1 root root 3032 Oct 30 18:38 /usr/share/alterator/help/ru_RU/network.html -rwxr-xr-x 1 root root 4840 Oct 30 18:38 /usr/share/alterator/help/ru_RU/packages.html -rwxr-xr-x 1 root root 1928 Oct 30 18:38 /usr/share/alterator/help/ru_RU/root.html -rwxr-xr-x 1 root root 1387 Oct 30 18:38 /usr/share/alterator/help/ru_RU/time.html -rwxr-xr-x 1 root root 1223 Oct 30 18:38 /usr/share/alterator/help/ru_RU/user.html -rwxr-xr-x 1 root root 11024 Oct 30 18:38 /usr/share/alterator/help/ru_RU/vm.html -rwxr-xr-x 1 root root 1789 Oct 30 18:38 /usr/share/alterator/help/ru_RU/x11.html lrwxrwxrwx 1 root root 31 Oct 30 18:38 /usr/share/alterator/help/ru_UA -> /usr/share/alterator/help/ru_RU $ %files ... %_datadir/alterator/help/ru_RU/* %_datadir/alterator/help/ru_UA The package referes ru_RU directory but does not own the directory. Old behaviour: unmet dependency. > alterator-icons-lite-0.4.0-alt1 Requires(rpmlib) rpmlib(PayloadFilesHavePrefix) <= 4.0-1 > +alterator-install-common-desktop-0.11-alt1 Requires /usr/share/alterator/help/ru_RU > alterator-install-common-desktop-0.11-alt1 Requires alterator-autoinstall New behaviour: though the package does not explicitly own the directory, it has some files packaged under the directory. Because of this, ru_UA symlink will not be broken after install. We chose to be forgiving: symlinks.req: WARNING: /usr/src/tmp/alterator-install2-desktop-buildroot/usr/share/alterator/help/ru_UA: directory /usr/share/alterator/help/ru_RU not owned by the package
2008-01-23 01:26:43 +03:00
xbrep=$(CanonPath "$RPM_BUILD_ROOT$rep")
if MatchBuildroot "$xbrep"; then
find-package: enhanced path lookups under buildroot, added special case for dir dependencies $ less alterator-install-common-desktop-0.11-alt1.i586.rpm |grep help -rwxr-xr-x 1 root root 972 Oct 30 18:38 /usr/share/alterator/help/ru_RU/basesystem.html -rwxr-xr-x 1 root root 340 Oct 30 18:38 /usr/share/alterator/help/ru_RU/kbd.html -rwxr-xr-x 1 root root 2233 Oct 30 18:38 /usr/share/alterator/help/ru_RU/license.html -rwxr-xr-x 1 root root 1280 Oct 30 18:38 /usr/share/alterator/help/ru_RU/lilo.html -rwxr-xr-x 1 root root 3032 Oct 30 18:38 /usr/share/alterator/help/ru_RU/network.html -rwxr-xr-x 1 root root 4840 Oct 30 18:38 /usr/share/alterator/help/ru_RU/packages.html -rwxr-xr-x 1 root root 1928 Oct 30 18:38 /usr/share/alterator/help/ru_RU/root.html -rwxr-xr-x 1 root root 1387 Oct 30 18:38 /usr/share/alterator/help/ru_RU/time.html -rwxr-xr-x 1 root root 1223 Oct 30 18:38 /usr/share/alterator/help/ru_RU/user.html -rwxr-xr-x 1 root root 11024 Oct 30 18:38 /usr/share/alterator/help/ru_RU/vm.html -rwxr-xr-x 1 root root 1789 Oct 30 18:38 /usr/share/alterator/help/ru_RU/x11.html lrwxrwxrwx 1 root root 31 Oct 30 18:38 /usr/share/alterator/help/ru_UA -> /usr/share/alterator/help/ru_RU $ %files ... %_datadir/alterator/help/ru_RU/* %_datadir/alterator/help/ru_UA The package referes ru_RU directory but does not own the directory. Old behaviour: unmet dependency. > alterator-icons-lite-0.4.0-alt1 Requires(rpmlib) rpmlib(PayloadFilesHavePrefix) <= 4.0-1 > +alterator-install-common-desktop-0.11-alt1 Requires /usr/share/alterator/help/ru_RU > alterator-install-common-desktop-0.11-alt1 Requires alterator-autoinstall New behaviour: though the package does not explicitly own the directory, it has some files packaged under the directory. Because of this, ru_UA symlink will not be broken after install. We chose to be forgiving: symlinks.req: WARNING: /usr/src/tmp/alterator-install2-desktop-buildroot/usr/share/alterator/help/ru_UA: directory /usr/share/alterator/help/ru_RU not owned by the package
2008-01-23 01:26:43 +03:00
# Good. The path was canonicalized against buildroot.
StatPrint "$xbrep" && return 0
find-package: enhanced path lookups under buildroot, added special case for dir dependencies $ less alterator-install-common-desktop-0.11-alt1.i586.rpm |grep help -rwxr-xr-x 1 root root 972 Oct 30 18:38 /usr/share/alterator/help/ru_RU/basesystem.html -rwxr-xr-x 1 root root 340 Oct 30 18:38 /usr/share/alterator/help/ru_RU/kbd.html -rwxr-xr-x 1 root root 2233 Oct 30 18:38 /usr/share/alterator/help/ru_RU/license.html -rwxr-xr-x 1 root root 1280 Oct 30 18:38 /usr/share/alterator/help/ru_RU/lilo.html -rwxr-xr-x 1 root root 3032 Oct 30 18:38 /usr/share/alterator/help/ru_RU/network.html -rwxr-xr-x 1 root root 4840 Oct 30 18:38 /usr/share/alterator/help/ru_RU/packages.html -rwxr-xr-x 1 root root 1928 Oct 30 18:38 /usr/share/alterator/help/ru_RU/root.html -rwxr-xr-x 1 root root 1387 Oct 30 18:38 /usr/share/alterator/help/ru_RU/time.html -rwxr-xr-x 1 root root 1223 Oct 30 18:38 /usr/share/alterator/help/ru_RU/user.html -rwxr-xr-x 1 root root 11024 Oct 30 18:38 /usr/share/alterator/help/ru_RU/vm.html -rwxr-xr-x 1 root root 1789 Oct 30 18:38 /usr/share/alterator/help/ru_RU/x11.html lrwxrwxrwx 1 root root 31 Oct 30 18:38 /usr/share/alterator/help/ru_UA -> /usr/share/alterator/help/ru_RU $ %files ... %_datadir/alterator/help/ru_RU/* %_datadir/alterator/help/ru_UA The package referes ru_RU directory but does not own the directory. Old behaviour: unmet dependency. > alterator-icons-lite-0.4.0-alt1 Requires(rpmlib) rpmlib(PayloadFilesHavePrefix) <= 4.0-1 > +alterator-install-common-desktop-0.11-alt1 Requires /usr/share/alterator/help/ru_RU > alterator-install-common-desktop-0.11-alt1 Requires alterator-autoinstall New behaviour: though the package does not explicitly own the directory, it has some files packaged under the directory. Because of this, ru_UA symlink will not be broken after install. We chose to be forgiving: symlinks.req: WARNING: /usr/src/tmp/alterator-install2-desktop-buildroot/usr/share/alterator/help/ru_UA: directory /usr/share/alterator/help/ru_RU not owned by the package
2008-01-23 01:26:43 +03:00
else
# Too bad. The path was canonicalized outside buildroot.
# They should fix their symbolic links.
find-package: enhanced path lookups under buildroot, added special case for dir dependencies $ less alterator-install-common-desktop-0.11-alt1.i586.rpm |grep help -rwxr-xr-x 1 root root 972 Oct 30 18:38 /usr/share/alterator/help/ru_RU/basesystem.html -rwxr-xr-x 1 root root 340 Oct 30 18:38 /usr/share/alterator/help/ru_RU/kbd.html -rwxr-xr-x 1 root root 2233 Oct 30 18:38 /usr/share/alterator/help/ru_RU/license.html -rwxr-xr-x 1 root root 1280 Oct 30 18:38 /usr/share/alterator/help/ru_RU/lilo.html -rwxr-xr-x 1 root root 3032 Oct 30 18:38 /usr/share/alterator/help/ru_RU/network.html -rwxr-xr-x 1 root root 4840 Oct 30 18:38 /usr/share/alterator/help/ru_RU/packages.html -rwxr-xr-x 1 root root 1928 Oct 30 18:38 /usr/share/alterator/help/ru_RU/root.html -rwxr-xr-x 1 root root 1387 Oct 30 18:38 /usr/share/alterator/help/ru_RU/time.html -rwxr-xr-x 1 root root 1223 Oct 30 18:38 /usr/share/alterator/help/ru_RU/user.html -rwxr-xr-x 1 root root 11024 Oct 30 18:38 /usr/share/alterator/help/ru_RU/vm.html -rwxr-xr-x 1 root root 1789 Oct 30 18:38 /usr/share/alterator/help/ru_RU/x11.html lrwxrwxrwx 1 root root 31 Oct 30 18:38 /usr/share/alterator/help/ru_UA -> /usr/share/alterator/help/ru_RU $ %files ... %_datadir/alterator/help/ru_RU/* %_datadir/alterator/help/ru_UA The package referes ru_RU directory but does not own the directory. Old behaviour: unmet dependency. > alterator-icons-lite-0.4.0-alt1 Requires(rpmlib) rpmlib(PayloadFilesHavePrefix) <= 4.0-1 > +alterator-install-common-desktop-0.11-alt1 Requires /usr/share/alterator/help/ru_RU > alterator-install-common-desktop-0.11-alt1 Requires alterator-autoinstall New behaviour: though the package does not explicitly own the directory, it has some files packaged under the directory. Because of this, ru_UA symlink will not be broken after install. We chose to be forgiving: symlinks.req: WARNING: /usr/src/tmp/alterator-install2-desktop-buildroot/usr/share/alterator/help/ru_UA: directory /usr/share/alterator/help/ru_RU not owned by the package
2008-01-23 01:26:43 +03:00
Warning "$f: $rep cannot be canonicalized under RPM_BUILD_ROOT"
# Consider this: RPM_BUILD_ROOT/A/B/C -> /D/C
# `-> /D
# It still makes sense to check /D/C under RPM_BUILD_ROOT.
xbrep=$(CanonPath "$RPM_BUILD_ROOT$xbrep")
MatchBuildroot "$xbrep" && StatPrint "$xbrep" && return 0
find-package: enhanced path lookups under buildroot, added special case for dir dependencies $ less alterator-install-common-desktop-0.11-alt1.i586.rpm |grep help -rwxr-xr-x 1 root root 972 Oct 30 18:38 /usr/share/alterator/help/ru_RU/basesystem.html -rwxr-xr-x 1 root root 340 Oct 30 18:38 /usr/share/alterator/help/ru_RU/kbd.html -rwxr-xr-x 1 root root 2233 Oct 30 18:38 /usr/share/alterator/help/ru_RU/license.html -rwxr-xr-x 1 root root 1280 Oct 30 18:38 /usr/share/alterator/help/ru_RU/lilo.html -rwxr-xr-x 1 root root 3032 Oct 30 18:38 /usr/share/alterator/help/ru_RU/network.html -rwxr-xr-x 1 root root 4840 Oct 30 18:38 /usr/share/alterator/help/ru_RU/packages.html -rwxr-xr-x 1 root root 1928 Oct 30 18:38 /usr/share/alterator/help/ru_RU/root.html -rwxr-xr-x 1 root root 1387 Oct 30 18:38 /usr/share/alterator/help/ru_RU/time.html -rwxr-xr-x 1 root root 1223 Oct 30 18:38 /usr/share/alterator/help/ru_RU/user.html -rwxr-xr-x 1 root root 11024 Oct 30 18:38 /usr/share/alterator/help/ru_RU/vm.html -rwxr-xr-x 1 root root 1789 Oct 30 18:38 /usr/share/alterator/help/ru_RU/x11.html lrwxrwxrwx 1 root root 31 Oct 30 18:38 /usr/share/alterator/help/ru_UA -> /usr/share/alterator/help/ru_RU $ %files ... %_datadir/alterator/help/ru_RU/* %_datadir/alterator/help/ru_UA The package referes ru_RU directory but does not own the directory. Old behaviour: unmet dependency. > alterator-icons-lite-0.4.0-alt1 Requires(rpmlib) rpmlib(PayloadFilesHavePrefix) <= 4.0-1 > +alterator-install-common-desktop-0.11-alt1 Requires /usr/share/alterator/help/ru_RU > alterator-install-common-desktop-0.11-alt1 Requires alterator-autoinstall New behaviour: though the package does not explicitly own the directory, it has some files packaged under the directory. Because of this, ru_UA symlink will not be broken after install. We chose to be forgiving: symlinks.req: WARNING: /usr/src/tmp/alterator-install2-desktop-buildroot/usr/share/alterator/help/ru_UA: directory /usr/share/alterator/help/ru_RU not owned by the package
2008-01-23 01:26:43 +03:00
fi
# They might also ask if /etc/init.d/foo is under RPM_BUILD_ROOT.
# That would be /etc/rc.d/init.d/foo.
xbrep=$(CanonPath "$rep")
xbrep=$(CanonPath "$RPM_BUILD_ROOT$xbrep")
MatchBuildroot "$xbrep" && StatPrint "$xbrep" && return 0
# Not there. Not now.
:
find-package: enhanced path lookups under buildroot, added special case for dir dependencies $ less alterator-install-common-desktop-0.11-alt1.i586.rpm |grep help -rwxr-xr-x 1 root root 972 Oct 30 18:38 /usr/share/alterator/help/ru_RU/basesystem.html -rwxr-xr-x 1 root root 340 Oct 30 18:38 /usr/share/alterator/help/ru_RU/kbd.html -rwxr-xr-x 1 root root 2233 Oct 30 18:38 /usr/share/alterator/help/ru_RU/license.html -rwxr-xr-x 1 root root 1280 Oct 30 18:38 /usr/share/alterator/help/ru_RU/lilo.html -rwxr-xr-x 1 root root 3032 Oct 30 18:38 /usr/share/alterator/help/ru_RU/network.html -rwxr-xr-x 1 root root 4840 Oct 30 18:38 /usr/share/alterator/help/ru_RU/packages.html -rwxr-xr-x 1 root root 1928 Oct 30 18:38 /usr/share/alterator/help/ru_RU/root.html -rwxr-xr-x 1 root root 1387 Oct 30 18:38 /usr/share/alterator/help/ru_RU/time.html -rwxr-xr-x 1 root root 1223 Oct 30 18:38 /usr/share/alterator/help/ru_RU/user.html -rwxr-xr-x 1 root root 11024 Oct 30 18:38 /usr/share/alterator/help/ru_RU/vm.html -rwxr-xr-x 1 root root 1789 Oct 30 18:38 /usr/share/alterator/help/ru_RU/x11.html lrwxrwxrwx 1 root root 31 Oct 30 18:38 /usr/share/alterator/help/ru_UA -> /usr/share/alterator/help/ru_RU $ %files ... %_datadir/alterator/help/ru_RU/* %_datadir/alterator/help/ru_UA The package referes ru_RU directory but does not own the directory. Old behaviour: unmet dependency. > alterator-icons-lite-0.4.0-alt1 Requires(rpmlib) rpmlib(PayloadFilesHavePrefix) <= 4.0-1 > +alterator-install-common-desktop-0.11-alt1 Requires /usr/share/alterator/help/ru_RU > alterator-install-common-desktop-0.11-alt1 Requires alterator-autoinstall New behaviour: though the package does not explicitly own the directory, it has some files packaged under the directory. Because of this, ru_UA symlink will not be broken after install. We chose to be forgiving: symlinks.req: WARNING: /usr/src/tmp/alterator-install2-desktop-buildroot/usr/share/alterator/help/ru_UA: directory /usr/share/alterator/help/ru_RU not owned by the package
2008-01-23 01:26:43 +03:00
}
FindByPath()
2002-03-25 23:37:46 +03:00
{
# Dependence name starts with `/'.
local f="$1" rep="$2" package; shift 2 || return
2002-03-25 23:37:46 +03:00
# Does it start with %_builddir or %buildroot?
if [ -n "${RPM_BUILD_DIR-}" ] && [ -z "${rep##$RPM_BUILD_DIR*}" ]; then
Info "$f: invalid dependency: $rep"
return 1
fi
if [ -n "${RPM_BUILD_ROOT-}" ] && [ -z "${rep##$RPM_BUILD_ROOT*}" ]; then
Info "$f: invalid dependency: $rep"
return 1
fi
2003-04-22 19:11:52 +04:00
# Does it belong to buildroot?
find-package: enhanced path lookups under buildroot, added special case for dir dependencies $ less alterator-install-common-desktop-0.11-alt1.i586.rpm |grep help -rwxr-xr-x 1 root root 972 Oct 30 18:38 /usr/share/alterator/help/ru_RU/basesystem.html -rwxr-xr-x 1 root root 340 Oct 30 18:38 /usr/share/alterator/help/ru_RU/kbd.html -rwxr-xr-x 1 root root 2233 Oct 30 18:38 /usr/share/alterator/help/ru_RU/license.html -rwxr-xr-x 1 root root 1280 Oct 30 18:38 /usr/share/alterator/help/ru_RU/lilo.html -rwxr-xr-x 1 root root 3032 Oct 30 18:38 /usr/share/alterator/help/ru_RU/network.html -rwxr-xr-x 1 root root 4840 Oct 30 18:38 /usr/share/alterator/help/ru_RU/packages.html -rwxr-xr-x 1 root root 1928 Oct 30 18:38 /usr/share/alterator/help/ru_RU/root.html -rwxr-xr-x 1 root root 1387 Oct 30 18:38 /usr/share/alterator/help/ru_RU/time.html -rwxr-xr-x 1 root root 1223 Oct 30 18:38 /usr/share/alterator/help/ru_RU/user.html -rwxr-xr-x 1 root root 11024 Oct 30 18:38 /usr/share/alterator/help/ru_RU/vm.html -rwxr-xr-x 1 root root 1789 Oct 30 18:38 /usr/share/alterator/help/ru_RU/x11.html lrwxrwxrwx 1 root root 31 Oct 30 18:38 /usr/share/alterator/help/ru_UA -> /usr/share/alterator/help/ru_RU $ %files ... %_datadir/alterator/help/ru_RU/* %_datadir/alterator/help/ru_UA The package referes ru_RU directory but does not own the directory. Old behaviour: unmet dependency. > alterator-icons-lite-0.4.0-alt1 Requires(rpmlib) rpmlib(PayloadFilesHavePrefix) <= 4.0-1 > +alterator-install-common-desktop-0.11-alt1 Requires /usr/share/alterator/help/ru_RU > alterator-install-common-desktop-0.11-alt1 Requires alterator-autoinstall New behaviour: though the package does not explicitly own the directory, it has some files packaged under the directory. Because of this, ru_UA symlink will not be broken after install. We chose to be forgiving: symlinks.req: WARNING: /usr/src/tmp/alterator-install2-desktop-buildroot/usr/share/alterator/help/ru_UA: directory /usr/share/alterator/help/ru_RU not owned by the package
2008-01-23 01:26:43 +03:00
local xbrep
xbrep=$(FindByPathUnderBuildroot "$f" "$rep")
if [ -n "$xbrep" ]; then
# The file is under buildroot. We emit file-level dependency.
# If the file is in the same package, rpm-build will optimize
# out the dependency. Otherwise, the file is to be packaged
# into another subpackage, and we get something like more strict
# dependencies between subpackages.
if [ ! -L "$RPM_BUILD_ROOT$xbrep" -a -d "$RPM_BUILD_ROOT$xbrep" ]; then
# They require a directory. Here we do only "weak" directory
# dependencies (i.e. sometimes we prefer to omit such dependencies).
# We only need to make sure that the directory actually exists after
# install, which is the case if there are packaged files under the
# directory.
local dirfiles
if dirfiles=$(PackagedFiles |fgrep "$xbrep") &&
dirfiles=$(echo '' $dirfiles '') &&
[ -n "${dirfiles##* $xbrep *}" ] &&
[ -z "${dirfiles##* $xbrep/*}" ]; then
Warning "$f: directory $xbrep not owned by the package"
return 0
fi
fi
find-package: enhanced path lookups under buildroot, added special case for dir dependencies $ less alterator-install-common-desktop-0.11-alt1.i586.rpm |grep help -rwxr-xr-x 1 root root 972 Oct 30 18:38 /usr/share/alterator/help/ru_RU/basesystem.html -rwxr-xr-x 1 root root 340 Oct 30 18:38 /usr/share/alterator/help/ru_RU/kbd.html -rwxr-xr-x 1 root root 2233 Oct 30 18:38 /usr/share/alterator/help/ru_RU/license.html -rwxr-xr-x 1 root root 1280 Oct 30 18:38 /usr/share/alterator/help/ru_RU/lilo.html -rwxr-xr-x 1 root root 3032 Oct 30 18:38 /usr/share/alterator/help/ru_RU/network.html -rwxr-xr-x 1 root root 4840 Oct 30 18:38 /usr/share/alterator/help/ru_RU/packages.html -rwxr-xr-x 1 root root 1928 Oct 30 18:38 /usr/share/alterator/help/ru_RU/root.html -rwxr-xr-x 1 root root 1387 Oct 30 18:38 /usr/share/alterator/help/ru_RU/time.html -rwxr-xr-x 1 root root 1223 Oct 30 18:38 /usr/share/alterator/help/ru_RU/user.html -rwxr-xr-x 1 root root 11024 Oct 30 18:38 /usr/share/alterator/help/ru_RU/vm.html -rwxr-xr-x 1 root root 1789 Oct 30 18:38 /usr/share/alterator/help/ru_RU/x11.html lrwxrwxrwx 1 root root 31 Oct 30 18:38 /usr/share/alterator/help/ru_UA -> /usr/share/alterator/help/ru_RU $ %files ... %_datadir/alterator/help/ru_RU/* %_datadir/alterator/help/ru_UA The package referes ru_RU directory but does not own the directory. Old behaviour: unmet dependency. > alterator-icons-lite-0.4.0-alt1 Requires(rpmlib) rpmlib(PayloadFilesHavePrefix) <= 4.0-1 > +alterator-install-common-desktop-0.11-alt1 Requires /usr/share/alterator/help/ru_RU > alterator-install-common-desktop-0.11-alt1 Requires alterator-autoinstall New behaviour: though the package does not explicitly own the directory, it has some files packaged under the directory. Because of this, ru_UA symlink will not be broken after install. We chose to be forgiving: symlinks.req: WARNING: /usr/src/tmp/alterator-install2-desktop-buildroot/usr/share/alterator/help/ru_UA: directory /usr/share/alterator/help/ru_RU not owned by the package
2008-01-23 01:26:43 +03:00
$Verbose "$f: $rep -> \$RPM_BUILD_ROOT$xbrep"
printf '%s\n' "$xbrep"
return 0
fi
2003-04-22 19:11:52 +04:00
find-package (FindByPath): implemented smart check for alternatives, cf. bug #13374 Some examples. 1) $ sh -efu -c '. scripts/find-package.in; FindPackage script /usr/share/libtool' /usr/share/libtool $ sh -efu -c '. scripts/find-package.in; FindPackage script /usr/share/libtool/' /usr/share/libtool $ This shows that alterntaives check is no longer restricted to deficient readlink "$rep" |grep '^/etc/alternatives/' logic. Old behaviour was: $ sh -efu -c '. /usr/lib/rpm/find-package; FindPackage script /usr/share/libtool' /usr/share/libtool $ sh -efu -c '. /usr/lib/rpm/find-package; FindPackage script /usr/share/libtool/' sh: script: checking contents_index_all for /usr/share/libtool-1.5 sh: script: /usr/share/libtool-1.5 -> libtool_1.5 (via contents_index_all) libtool_1.5 $ 2) $ sh -efu -c '. scripts/find-package.in; FindPackage script /usr/share/libtool/../autoconf' /usr/share/autoconf /usr/share/libtool $ This shows that any number of alternatives can be resolved within a single path. 3) $ sh -efu -c '. scripts/find-package.in; FindPackage script /usr/share/libtool/config.guess' /usr/share/libtool sh: script: alternative /usr/share/libtool prevents /usr/share/libtool/config.guess resolution $ This shows that we cannot resolve paths under alternatives directory. 4) $ sh -efu -c '. scripts/find-package.in; FindPackage script /usr/share/libtool/../../bin/perl' /usr/share/libtool perl-base $ This shows that we actually CAN resolve paths which are not under alternatives directory.
2007-11-17 15:03:19 +03:00
# Is it an alternative? Path components can be alternatives, too.
local p="$rep" alt_break= alt xalt xrep
xrep=$(readlink -vm "$rep")
find-package (FindByPath): implemented smart check for alternatives, cf. bug #13374 Some examples. 1) $ sh -efu -c '. scripts/find-package.in; FindPackage script /usr/share/libtool' /usr/share/libtool $ sh -efu -c '. scripts/find-package.in; FindPackage script /usr/share/libtool/' /usr/share/libtool $ This shows that alterntaives check is no longer restricted to deficient readlink "$rep" |grep '^/etc/alternatives/' logic. Old behaviour was: $ sh -efu -c '. /usr/lib/rpm/find-package; FindPackage script /usr/share/libtool' /usr/share/libtool $ sh -efu -c '. /usr/lib/rpm/find-package; FindPackage script /usr/share/libtool/' sh: script: checking contents_index_all for /usr/share/libtool-1.5 sh: script: /usr/share/libtool-1.5 -> libtool_1.5 (via contents_index_all) libtool_1.5 $ 2) $ sh -efu -c '. scripts/find-package.in; FindPackage script /usr/share/libtool/../autoconf' /usr/share/autoconf /usr/share/libtool $ This shows that any number of alternatives can be resolved within a single path. 3) $ sh -efu -c '. scripts/find-package.in; FindPackage script /usr/share/libtool/config.guess' /usr/share/libtool sh: script: alternative /usr/share/libtool prevents /usr/share/libtool/config.guess resolution $ This shows that we cannot resolve paths under alternatives directory. 4) $ sh -efu -c '. scripts/find-package.in; FindPackage script /usr/share/libtool/../../bin/perl' /usr/share/libtool perl-base $ This shows that we actually CAN resolve paths which are not under alternatives directory.
2007-11-17 15:03:19 +03:00
while [ -n "$p" ]; do
# Check each path component whether it is an alternative.
if [ -L "$p" ] && readlink -v "$p" |grep -qs '^/etc/alternatives/'; then
alt=$(CanonPath "$p")
Verbose "$f: $rep -> $p -> $alt (alternative)"
printf '%s\n' "$alt"
# Now we have to decide if this alternative should eventually
# prevent final $rep dependency resolution.
xalt=$(readlink -vm "$p")
case "$xrep" in
"$xalt")
# alternative and $rep are more or less the same
find-package (FindByPath): implemented smart check for alternatives, cf. bug #13374 Some examples. 1) $ sh -efu -c '. scripts/find-package.in; FindPackage script /usr/share/libtool' /usr/share/libtool $ sh -efu -c '. scripts/find-package.in; FindPackage script /usr/share/libtool/' /usr/share/libtool $ This shows that alterntaives check is no longer restricted to deficient readlink "$rep" |grep '^/etc/alternatives/' logic. Old behaviour was: $ sh -efu -c '. /usr/lib/rpm/find-package; FindPackage script /usr/share/libtool' /usr/share/libtool $ sh -efu -c '. /usr/lib/rpm/find-package; FindPackage script /usr/share/libtool/' sh: script: checking contents_index_all for /usr/share/libtool-1.5 sh: script: /usr/share/libtool-1.5 -> libtool_1.5 (via contents_index_all) libtool_1.5 $ 2) $ sh -efu -c '. scripts/find-package.in; FindPackage script /usr/share/libtool/../autoconf' /usr/share/autoconf /usr/share/libtool $ This shows that any number of alternatives can be resolved within a single path. 3) $ sh -efu -c '. scripts/find-package.in; FindPackage script /usr/share/libtool/config.guess' /usr/share/libtool sh: script: alternative /usr/share/libtool prevents /usr/share/libtool/config.guess resolution $ This shows that we cannot resolve paths under alternatives directory. 4) $ sh -efu -c '. scripts/find-package.in; FindPackage script /usr/share/libtool/../../bin/perl' /usr/share/libtool perl-base $ This shows that we actually CAN resolve paths which are not under alternatives directory.
2007-11-17 15:03:19 +03:00
alt_break=1 ;;
"$xalt"/*)
# $rep is under alternative dir, too bad
Info "$f: alternative $alt prevents $rep dependency resolution"
find-package (FindByPath): implemented smart check for alternatives, cf. bug #13374 Some examples. 1) $ sh -efu -c '. scripts/find-package.in; FindPackage script /usr/share/libtool' /usr/share/libtool $ sh -efu -c '. scripts/find-package.in; FindPackage script /usr/share/libtool/' /usr/share/libtool $ This shows that alterntaives check is no longer restricted to deficient readlink "$rep" |grep '^/etc/alternatives/' logic. Old behaviour was: $ sh -efu -c '. /usr/lib/rpm/find-package; FindPackage script /usr/share/libtool' /usr/share/libtool $ sh -efu -c '. /usr/lib/rpm/find-package; FindPackage script /usr/share/libtool/' sh: script: checking contents_index_all for /usr/share/libtool-1.5 sh: script: /usr/share/libtool-1.5 -> libtool_1.5 (via contents_index_all) libtool_1.5 $ 2) $ sh -efu -c '. scripts/find-package.in; FindPackage script /usr/share/libtool/../autoconf' /usr/share/autoconf /usr/share/libtool $ This shows that any number of alternatives can be resolved within a single path. 3) $ sh -efu -c '. scripts/find-package.in; FindPackage script /usr/share/libtool/config.guess' /usr/share/libtool sh: script: alternative /usr/share/libtool prevents /usr/share/libtool/config.guess resolution $ This shows that we cannot resolve paths under alternatives directory. 4) $ sh -efu -c '. scripts/find-package.in; FindPackage script /usr/share/libtool/../../bin/perl' /usr/share/libtool perl-base $ This shows that we actually CAN resolve paths which are not under alternatives directory.
2007-11-17 15:03:19 +03:00
alt_break=1 ;;
esac
fi
p=${p%/*}
done
[ -z "$alt_break" ] || return 0
unset p alt_break alt xalt xrep ||:
2003-04-22 19:11:52 +04:00
# Hard time checking $rep path components is over.
# Now we are ready to apply our know-how.
rep=$(CanonPath "$rep")
# Ignore pseudo-filesystem dependencies.
local dir="${rep#/}"; dir="${dir%%/*}"
case "$dir" in
dev | proc | sys )
$Verbose "$f: $rep -> /$dir (skip)"
return ;;
esac
unset dir
# Opimize out bulk dependencies.
case "${rep#/bin/}" in
sh | cat | rm | mv | cp | mkdir | ln )
$Verbose "$f: $rep (skip, bulk)"
return ;;
esac
# Ideally, we'd like to output all file-level dependencies here just as the are.
# However, due to current Sisyphus design (separate $arch and noarch repos),
# this can result in cross-arch "semi-unmet" dependencies. For now, we check
# if the dependency is "safe enough" to put it as is.
# APT can handle certain file-level dependencies as is.
case "$rep" in
*/bin/* | */sbin/* | */etc/* )
$Verbose "$f: $rep -> $rep (raw, APT-firendly)"
printf %s\\n "$rep"
return ;;
esac
# Check if this path is explicitly provided.
local prov n1 n2
if prov=$(rpmquery --queryformat='%{NAME}\n' --whatprovides "$rep" 2>/dev/null) &&
n1=$(echo "$prov" |wc -l) &&
n2=$(rpmquery --queryformat='%{NAME}\n' -f "$rep" 2>/dev/null |wc -l) &&
[ "$n1" -gt "$n2" ]; then
prov=$(echo "$prov" |LC_COLLATE=C sort -u)
$Verbose "$f: $rep -> $rep (raw, provided by$(echo '' $prov))"
printf %s\\n "$rep"
return
fi
# The path is also "safe enough" if it is already required by someone.
local req
if req=$(rpmquery --queryformat='%{NAME}\n' --whatrequires "$rep" 2>/dev/null); then
req=$(echo "$req" |LC_COLLATE=C sort -u)
$Verbose "$f: $rep -> $rep (raw, required by$(echo '' $req))"
printf %s\\n "$rep"
return
fi
# Always try package binary index.
local idx_bin="${RPM_PKG_CONTENTS_INDEX_BIN-}" try_idx_bin=1
[ -n "$idx_bin" ] && [ -s "$idx_bin" ] && [ -r "$idx_bin" ] || try_idx_bin=
if [ -n "$try_idx_bin" ]; then
package="$(awk -v "f=$rep" '($1 == f) {print $2}' "$idx_bin" |sort -u)"
local n="$(IFS=$'\n'; set -- $package; echo $#)"
if [ "$n" = 1 ]; then
$Verbose "$f: $rep -> $package (via contents_index_bin)"
printf %s\\n "$package"
return
elif [ "$n" -gt 1 ]; then
Info "$f: $rep indexed by:$(echo '' $package)"
Info "$f: $rep -> $rep (raw, ambiguous, via contents_index_bin)"
printf %s\\n "$rep"
return
fi
fi
# Maybe try pkg complete index.
local idx_all="${RPM_PKG_CONTENTS_INDEX_ALL-}" try_idx_all=1
[ -n "$idx_all" ] && [ -s "$idx_all" ] && [ -r "$idx_all" ] || try_idx_all=
case "$try_idx_bin$rep" in
1/bin/* | 1/sbin/* | 1/usr/bin/* | 1/usr/sbin/* )
# Binary index already checked for standard *bin/* entries.
# No need to check complete index.
try_idx_all=
esac
if [ -n "$try_idx_all" ]; then
# Checking complete index is expensive.
local Verbose=Info
Info "$f: checking contents_index_all for $rep"
# Complete package index is possibly gzipped.
package="$(gzip -cdfq "$idx_all" |awk -v "f=$rep" '($1 == f) {print $2}' |sort -u)"
local n="$(IFS=$'\n'; set -- $package; echo $#)"
if [ "$n" = 1 ]; then
Info "$f: $rep -> $package (via contents_index_all)"
printf %s\\n "$package"
return
elif [ "$n" -gt 1 ]; then
Info "$f: $rep indexed by:$(echo '' $package)"
Info "$f: $rep -> $rep (raw, ambiguous, via contents_index_all)"
printf %s\\n "$rep"
return
fi
fi
2003-04-22 19:11:52 +04:00
# Check package database.
if package="$(rpmquery --whatprovides --queryformat='%{NAME}\n' -- "$rep" 2>/dev/null)"; then
package="$(printf %s "$package" |LC_COLLATE=C sort -u)"
local n="$(IFS=$'\n'; set -- $package; echo $#)"
if [ "$n" = 1 ]; then
$Verbose "$f: $rep -> $package (via rpmdb)"
printf %s\\n "$package"
return
elif [ "$n" -gt 1 ]; then
Info "$f: $rep provided by:$(echo '' $package)"
Info "$f: $rep -> $rep (raw, ambiguous, via rpmdb)"
printf %s\\n "$rep"
return
fi
fi
2003-04-22 19:11:52 +04:00
# Not found; output raw dependence.
Info "$f: $rep -> $rep (raw, not found)"
printf %s\\n "$rep"
}
2003-04-22 19:11:52 +04:00
FindByName()
{
local f="$1" r="$2" rep package; shift 2 || return
2003-04-22 19:11:52 +04:00
# Opimize out bulk dependencies.
case "$r" in
sh | cat | rm | mv | cp | mkdir | ln )
$Verbose "$f: $r (skip, bulk)"
return ;;
esac
local dir="${f%/*}"; dir="${dir#${RPM_BUILD_ROOT-}}"
local findpackage_path="$RPM_FINDPACKAGE_USER_PATH"
case "$dir" in
*/sbin | "" ) # %buildroot dir is used to save scriptlets
findpackage_path="$RPM_FINDPACKAGE_ROOT_PATH" ;;
/etc/*)
dir="${dir#/etc/}"; dir="${dir%%/*}"
case "$dir" in
# The sbin-ish places. WARNING: Explicit Content!
rc.d | init.d | control.d | chroot.d | net | ppp | cron* | hotplug* )
Debug "$f: root PATH on"
findpackage_path="$RPM_FINDPACKAGE_ROOT_PATH" ;;
esac
;;
esac
unset dir
# Check buildroot first.
if [ -n "${RPM_BUILD_ROOT-}" ]; then
rep=$(IFS="$IFS:"; set -f
for dir in $findpackage_path; do
rep="$dir/$r"
BR_rep="$RPM_BUILD_ROOT/$rep"
if [ -f "$BR_rep" -o -L "$BR_rep" ]; then
printf '%s\n' "$rep"
break
fi
done)
if [ -n "$rep" ]; then
$Verbose "$f: $r -> \$RPM_BUILD_ROOT$rep"
printf '%s\n' "$rep"
return
fi
fi
2003-04-22 19:11:52 +04:00
# Check for pkg contents binary index.
local save_rep= save_package=
if [ -n "${RPM_PKG_CONTENTS_INDEX_BIN-}" ] && [ -s "$RPM_PKG_CONTENTS_INDEX_BIN" ] && [ -r "$RPM_PKG_CONTENTS_INDEX_BIN" ]; then
local out="$(awk -v r="$r" -v findpackage_path="$findpackage_path" '
BEGIN {
# Here we enumerate all possible paths to keep the order;
# later we sort the result with "sort -n".
n = split(findpackage_path, ary, ":")
for (i = 1; i <= n; i++) {
dir = ary[i]
sub("/+$", "", dir)
find-package (FindByName): optimized awk script It looks like that, unlike in perl, pattern matching in awk is very slow. Perhaps they just don't have regexp engine hackers like Larry Wall or Ilya Zakharevich (or, most recently, Yves Orton aka demerphq). That's okay, since I can rewrite the script without pattern matching at all. That is, I don't have to split each index line into dir+basename, because I can prepare all valid absolute pathnames in advance. Old speed: $ time /usr/lib/rpm/shell.req -v /dev/stdin <<<`rpm -ql rpm-utils |sed -n 's|/usr/bin/||p'` shell.req: add_changelog -> /usr/bin/add_changelog -> rpm-utils (via content index) shell.req: buildreq -> /usr/bin/buildreq -> rpm-utils (via content index) shell.req: cleanup_spec -> /usr/bin/cleanup_spec -> rpm-utils (via content index) shell.req: compare_packages -> /usr/bin/compare_packages -> rpm-utils (via content index) shell.req: filereq -> /usr/bin/filereq -> rpm-utils (via content index) shell.req: packageof -> /usr/bin/packageof -> rpm-utils (via content index) shell.req: packagereq -> /usr/bin/packagereq -> rpm-utils (via content index) shell.req: rebuild_package -> /usr/bin/rebuild_package -> rpm-utils (via content index) shell.req: rebuild_packages -> /usr/bin/rebuild_packages -> rpm-utils (via content index) shell.req: rpmdups -> /usr/bin/rpmdups -> rpm-utils (via content index) shell.req: rpmevrcmp -> /usr/bin/rpmevrcmp -> rpm-utils (via content index) shell.req: rpmrdups -> /usr/bin/rpmrdups -> rpm-utils (via content index) shell.req: rpmvercmp -> /usr/bin/rpmvercmp -> rpm-utils (via content index) shell.req: stamp_spec -> /usr/bin/stamp_spec -> rpm-utils (via content index) rpm-utils /usr/lib/rpm/shell.req -v /dev/stdin <<< 5.37s user 0.11s system 96% cpu 5.683 total $ New speed: $ time /usr/lib/rpm/shell.req -v /dev/stdin <<<`rpm -ql rpm-utils |sed -n 's|/usr/bin/||p'` shell.req: add_changelog -> /usr/bin/add_changelog -> rpm-utils (via content index) shell.req: buildreq -> /usr/bin/buildreq -> rpm-utils (via content index) shell.req: cleanup_spec -> /usr/bin/cleanup_spec -> rpm-utils (via content index) shell.req: compare_packages -> /usr/bin/compare_packages -> rpm-utils (via content index) shell.req: filereq -> /usr/bin/filereq -> rpm-utils (via content index) shell.req: packageof -> /usr/bin/packageof -> rpm-utils (via content index) shell.req: packagereq -> /usr/bin/packagereq -> rpm-utils (via content index) shell.req: rebuild_package -> /usr/bin/rebuild_package -> rpm-utils (via content index) shell.req: rebuild_packages -> /usr/bin/rebuild_packages -> rpm-utils (via content index) shell.req: rpmdups -> /usr/bin/rpmdups -> rpm-utils (via content index) shell.req: rpmevrcmp -> /usr/bin/rpmevrcmp -> rpm-utils (via content index) shell.req: rpmrdups -> /usr/bin/rpmrdups -> rpm-utils (via content index) shell.req: rpmvercmp -> /usr/bin/rpmvercmp -> rpm-utils (via content index) shell.req: stamp_spec -> /usr/bin/stamp_spec -> rpm-utils (via content index) rpm-utils /usr/lib/rpm/shell.req -v /dev/stdin <<< 0.34s user 0.10s system 88% cpu 0.499 total $ More than ten times faster, wow! I didn't know regexp engine could be that slow, really.
2007-03-11 23:40:37 +03:00
file = dir "/" r
if (dir && !(file in FILES))
FILES[file] = i
}
# By now FILES is normally something like this:
# /bin/r 1
# /sbin/r 2
# /usr/bin/r 3
# /usr/sbin/r 4
# ...
}
find-package (FindByName): optimized awk script It looks like that, unlike in perl, pattern matching in awk is very slow. Perhaps they just don't have regexp engine hackers like Larry Wall or Ilya Zakharevich (or, most recently, Yves Orton aka demerphq). That's okay, since I can rewrite the script without pattern matching at all. That is, I don't have to split each index line into dir+basename, because I can prepare all valid absolute pathnames in advance. Old speed: $ time /usr/lib/rpm/shell.req -v /dev/stdin <<<`rpm -ql rpm-utils |sed -n 's|/usr/bin/||p'` shell.req: add_changelog -> /usr/bin/add_changelog -> rpm-utils (via content index) shell.req: buildreq -> /usr/bin/buildreq -> rpm-utils (via content index) shell.req: cleanup_spec -> /usr/bin/cleanup_spec -> rpm-utils (via content index) shell.req: compare_packages -> /usr/bin/compare_packages -> rpm-utils (via content index) shell.req: filereq -> /usr/bin/filereq -> rpm-utils (via content index) shell.req: packageof -> /usr/bin/packageof -> rpm-utils (via content index) shell.req: packagereq -> /usr/bin/packagereq -> rpm-utils (via content index) shell.req: rebuild_package -> /usr/bin/rebuild_package -> rpm-utils (via content index) shell.req: rebuild_packages -> /usr/bin/rebuild_packages -> rpm-utils (via content index) shell.req: rpmdups -> /usr/bin/rpmdups -> rpm-utils (via content index) shell.req: rpmevrcmp -> /usr/bin/rpmevrcmp -> rpm-utils (via content index) shell.req: rpmrdups -> /usr/bin/rpmrdups -> rpm-utils (via content index) shell.req: rpmvercmp -> /usr/bin/rpmvercmp -> rpm-utils (via content index) shell.req: stamp_spec -> /usr/bin/stamp_spec -> rpm-utils (via content index) rpm-utils /usr/lib/rpm/shell.req -v /dev/stdin <<< 5.37s user 0.11s system 96% cpu 5.683 total $ New speed: $ time /usr/lib/rpm/shell.req -v /dev/stdin <<<`rpm -ql rpm-utils |sed -n 's|/usr/bin/||p'` shell.req: add_changelog -> /usr/bin/add_changelog -> rpm-utils (via content index) shell.req: buildreq -> /usr/bin/buildreq -> rpm-utils (via content index) shell.req: cleanup_spec -> /usr/bin/cleanup_spec -> rpm-utils (via content index) shell.req: compare_packages -> /usr/bin/compare_packages -> rpm-utils (via content index) shell.req: filereq -> /usr/bin/filereq -> rpm-utils (via content index) shell.req: packageof -> /usr/bin/packageof -> rpm-utils (via content index) shell.req: packagereq -> /usr/bin/packagereq -> rpm-utils (via content index) shell.req: rebuild_package -> /usr/bin/rebuild_package -> rpm-utils (via content index) shell.req: rebuild_packages -> /usr/bin/rebuild_packages -> rpm-utils (via content index) shell.req: rpmdups -> /usr/bin/rpmdups -> rpm-utils (via content index) shell.req: rpmevrcmp -> /usr/bin/rpmevrcmp -> rpm-utils (via content index) shell.req: rpmrdups -> /usr/bin/rpmrdups -> rpm-utils (via content index) shell.req: rpmvercmp -> /usr/bin/rpmvercmp -> rpm-utils (via content index) shell.req: stamp_spec -> /usr/bin/stamp_spec -> rpm-utils (via content index) rpm-utils /usr/lib/rpm/shell.req -v /dev/stdin <<< 0.34s user 0.10s system 88% cpu 0.499 total $ More than ten times faster, wow! I didn't know regexp engine could be that slow, really.
2007-03-11 23:40:37 +03:00
NF==2 && ($1 in FILES) {
# Possible output is like this:
# 3 /usr/bin/r pkgA
# 1 /bin/r pkgB
find-package (FindByName): optimized awk script It looks like that, unlike in perl, pattern matching in awk is very slow. Perhaps they just don't have regexp engine hackers like Larry Wall or Ilya Zakharevich (or, most recently, Yves Orton aka demerphq). That's okay, since I can rewrite the script without pattern matching at all. That is, I don't have to split each index line into dir+basename, because I can prepare all valid absolute pathnames in advance. Old speed: $ time /usr/lib/rpm/shell.req -v /dev/stdin <<<`rpm -ql rpm-utils |sed -n 's|/usr/bin/||p'` shell.req: add_changelog -> /usr/bin/add_changelog -> rpm-utils (via content index) shell.req: buildreq -> /usr/bin/buildreq -> rpm-utils (via content index) shell.req: cleanup_spec -> /usr/bin/cleanup_spec -> rpm-utils (via content index) shell.req: compare_packages -> /usr/bin/compare_packages -> rpm-utils (via content index) shell.req: filereq -> /usr/bin/filereq -> rpm-utils (via content index) shell.req: packageof -> /usr/bin/packageof -> rpm-utils (via content index) shell.req: packagereq -> /usr/bin/packagereq -> rpm-utils (via content index) shell.req: rebuild_package -> /usr/bin/rebuild_package -> rpm-utils (via content index) shell.req: rebuild_packages -> /usr/bin/rebuild_packages -> rpm-utils (via content index) shell.req: rpmdups -> /usr/bin/rpmdups -> rpm-utils (via content index) shell.req: rpmevrcmp -> /usr/bin/rpmevrcmp -> rpm-utils (via content index) shell.req: rpmrdups -> /usr/bin/rpmrdups -> rpm-utils (via content index) shell.req: rpmvercmp -> /usr/bin/rpmvercmp -> rpm-utils (via content index) shell.req: stamp_spec -> /usr/bin/stamp_spec -> rpm-utils (via content index) rpm-utils /usr/lib/rpm/shell.req -v /dev/stdin <<< 5.37s user 0.11s system 96% cpu 5.683 total $ New speed: $ time /usr/lib/rpm/shell.req -v /dev/stdin <<<`rpm -ql rpm-utils |sed -n 's|/usr/bin/||p'` shell.req: add_changelog -> /usr/bin/add_changelog -> rpm-utils (via content index) shell.req: buildreq -> /usr/bin/buildreq -> rpm-utils (via content index) shell.req: cleanup_spec -> /usr/bin/cleanup_spec -> rpm-utils (via content index) shell.req: compare_packages -> /usr/bin/compare_packages -> rpm-utils (via content index) shell.req: filereq -> /usr/bin/filereq -> rpm-utils (via content index) shell.req: packageof -> /usr/bin/packageof -> rpm-utils (via content index) shell.req: packagereq -> /usr/bin/packagereq -> rpm-utils (via content index) shell.req: rebuild_package -> /usr/bin/rebuild_package -> rpm-utils (via content index) shell.req: rebuild_packages -> /usr/bin/rebuild_packages -> rpm-utils (via content index) shell.req: rpmdups -> /usr/bin/rpmdups -> rpm-utils (via content index) shell.req: rpmevrcmp -> /usr/bin/rpmevrcmp -> rpm-utils (via content index) shell.req: rpmrdups -> /usr/bin/rpmrdups -> rpm-utils (via content index) shell.req: rpmvercmp -> /usr/bin/rpmvercmp -> rpm-utils (via content index) shell.req: stamp_spec -> /usr/bin/stamp_spec -> rpm-utils (via content index) rpm-utils /usr/lib/rpm/shell.req -v /dev/stdin <<< 0.34s user 0.10s system 88% cpu 0.499 total $ More than ten times faster, wow! I didn't know regexp engine could be that slow, really.
2007-03-11 23:40:37 +03:00
print FILES[$1] "\t" $1 "\t" $2
}
' "$RPM_PKG_CONTENTS_INDEX_BIN" |
# Best paths go first:
sort -n |
# For each package, keep only the best path:
sort -u -k3 |
# Best paths still go first:
sort -n |
# Well done, discard numbers.
cut -f2-)"
local n="$(IFS=$'\n'; set -- $out; echo $#)"
if [ "$n" = 1 ]; then
rep="$(IFS=$'\t\n'; set -- $out; printf %s "$1")"
package="$(IFS=$'\t\n'; set -- $out; printf %s "$2")"
$Verbose "$f: $r -> $rep -> $package (via contents_index_bin)"
printf %s\\n "$package"
return
elif [ "$n" -gt 1 ]; then
# Content index search produced a confict: we have 2 or more paths
# from different packages. Consider this case:
# /usr/bin/r pkgA
# /usr/bin/r pkgB
# /usr/sbin/r pkgC
# Remember that best paths go first, and each package has only the best path.
# Now if the first two paths are the same, we produce raw dependency on /usr/bin/r.
local Verbose=Info
Info "$f: $r indexed by:$(printf %s "$out" |sed -e 's/\t/ -> /; s/$/,/; $s/,$//' |xargs echo '')"
rep="$(IFS=$'\t\n'; set -- $out; printf %s "$1")"
package="$(IFS=$'\t\n'; set -- $out; printf %s "$2")"
# Actually our contents_index generator already handles path dups,
# so the above example is likely to transform into this:
# /usr/bin/r /usr/bin/r
# /usr/sbin/r pkgC
# So we first check if path = package.
if [ "$rep" = "$package" ]; then
Info "$f: $r -> $rep -> $rep (ambiguous, via contents_index_bin)"
printf %s\\n "$rep"
return
fi
# And then we check if the first two paths are the same.
local rep2="$(IFS=$'\t\n'; set -- $out; printf %s "$3")"
if [ "$rep" = "$rep2" ]; then
Info "$f: $r -> $rep -> $rep (raw, ambiguous, via contents_index_bin)"
printf %s\\n "$rep"
return
2002-03-25 23:37:46 +03:00
fi
# However, consider yet worse real-life case:
# /usr/bin/arpsend arpsend
# /usr/sbin/arpsend vzctl
# In this case, we perfer to put aside the conflict for a while, and query
# the host system first. There's a good chance that the right package, either
# arpsend or vzctl, IS installed, and other unrelated packages are NOT installed.
# However, if the host system does not provide any candidate, we have to produce
# the dependency on /usr/bin/arpsend -> arpsend.
save_rep="$rep" save_package="$package"
fi
fi
# Lookup in the host system.
rep=$(IFS="$IFS:"; set -f
for dir in $findpackage_path; do
rep="$dir/$r"
if [ -f "$rep" ]; then
printf '%s\n' "$rep"
fi
done)
if [ -n "$rep" ]; then
local n="$(IFS=$'\n'; set -- $rep; echo $#)"
if [ "$n" -gt 1 ]; then
# We've got a few paths, e.g. awk -> {/bin/awk,/usr/bin/awk};
# we check if all paths really point to the same file.
n="$(IFS=$'\n'; for f in $rep; do readlink -vm "$f"; done |sort -u |wc -l)"
if [ "$n" -gt 1 ]; then
local Verbose=Info
Info "$f: host_env $r:$(echo '' $rep)"
fi
# But we select the first path, which is the best, anyway.
rep="$(IFS=$'\n'; set -- $rep; printf %s "$1")"
fi
if [ -n "$rep" ]; then
$Verbose "$f: $r -> $rep -> ... (via host_env)"
FindByPath "$f" "$rep"
return
fi
fi
# Reconsult package binary index.
if [ -n "$save_rep" ] && [ -n "$save_package" ]; then
rep="$save_rep" package="$save_package"
$Verbose "$f: $r -> $rep -> $package (via contents_index_bin)"
printf %s\\n "$package"
return
fi
# Not found.
local maybe_function=
case "$r" in
*[!A-Za-z0-9_]*) ;;
[!A-Za-z_]*) ;;
*[A-Z_]*) maybe_function=1 ;;
esac
if [ -n "$maybe_function" ]; then
$Verbose "$f: $r not found (skip, maybe function)"
else
Info "$f: $r not found (skip)"
fi
}
FindPackage()
{
local f="$1" r; shift || return
for r; do
local Verbose=Verbose
# Only these characters are allowed for pathnames or commands:
valid='A-Za-z0-9/@=.,:_+-'
case "$r" in
/*[!$valid]*)
Info "$f: invalid pathname: $r" ;;
/*[!/.]*)
FindByPath "$f" "$r" ;;
*/*)
Info "$f: invalid pathname: $r" ;;
-*)
Info "$f: invalid command: $r" ;;
*[!$valid]*)
Info "$f: invalid command: $r" ;;
'')
Verbose "$f: empty command?" ;;
*)
FindByName "$f" "$r" ;;
esac
2002-03-25 23:37:46 +03:00
done
}