Commit Graph

13 Commits

Author SHA1 Message Date
Alexey Tourbin
5909f93e30 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-12 15:06:11 +03:00
Alexey Tourbin
b1b2fab77c find-package (FindPackage): require either absolute path or no slashes 2007-03-12 15:06:10 +03:00
Alexey Tourbin
47fe2b2b3f find-package (FindByName): if the index search detects real conflict, try /usr/bin/which first
E.g. if the content index search detected something like

	/usr/bin/arpsend -> arpsend
	/usr/sbin/arpsend -> vzctl

then we should consult the host system first.  There's a good chance
that the right package, either arpsend or vzctl, IS installed, and
other candidate packages are NOT installed.  However, if /usr/bin/which
cannot find any candidate, we should reconsult the index again.
2007-03-12 15:06:05 +03:00
Alexey Tourbin
83e2b0cfe7 find-package: introduced RPM_FINDPACKAGE_PATH, which makes PATH search fully configurable
$ RPM_FINDPACKAGE_PATH=/usr/bin /usr/lib/rpm/shell.req -v /dev/stdin <<<arpsend
shell.req: /dev/stdin: arpsend indexed by: /usr/bin/arpsend -> arpsend, /usr/sbin/arpsend -> vzctl
shell.req: /dev/stdin: arpsend -> /usr/bin/arpsend -> arpsend (via content index)
arpsend
$ RPM_FINDPACKAGE_PATH=/usr/sbin /usr/lib/rpm/shell.req -v /dev/stdin <<<arpsend
shell.req: /dev/stdin: arpsend indexed by: /usr/sbin/arpsend -> vzctl, /usr/bin/arpsend -> arpsend
shell.req: /dev/stdin: arpsend -> /usr/sbin/arpsend -> vzctl (via content index)
vzctl
$

Also added %add_findpackage_path() and %set_findpackage_path() to platform.in.
2007-03-12 15:06:04 +03:00
Alexey Tourbin
f060b30e6c find-package (FindByName): enhanced content index part
Old behaviour:

$ /usr/lib/rpm/shell.req -v /dev/stdin <<<arpsend
shell.req: arpsend -> /usr/sbin/arpsend -> vzctl (via content index)
vzctl
$

New behaviour:

$ /usr/lib/rpm/shell.req -v /dev/stdin <<<arpsend
shell.req: /dev/stdin: arpsend indexed by: /usr/bin/arpsend -> arpsend, /usr/sbin/arpsend -> vzctl
shell.req: /dev/stdin: arpsend -> /usr/bin/arpsend -> arpsend (via content index)
arpsend
$ /usr/lib/rpm/shell.req -v /dev/stdin <<<ifup
shell.req: /dev/stdin: ifup indexed by: /sbin/ifup -> etcnet, /sbin/ifup -> net-scripts
shell.req: /dev/stdin: ifup -> /sbin/ifup -> /sbin/ifup (raw, ambiguous, via content index)
/sbin/ifup
$
2007-03-12 15:06:03 +03:00
Alexey Tourbin
b208a5725d find-package (FindByPath): enhanced content index part
There's a problem with content index:

$ /usr/lib/rpm/shell.req -v /dev/stdin <<</sbin/ifup
shell.req: /dev/stdin: /sbin/ifup -> etcnet (via content index)
etcnet
$ grep /sbin/ifup ~tmp/build/cache/contents/contents_index_bin
/sbin/ifup      etcnet
/sbin/ifup      net-scripts
$

After this change:

$ /usr/lib/rpm/shell.req -v /dev/stdin <<</sbin/ifup
shell.req: /dev/stdin: /sbin/ifup indexed by: etcnet net-scripts
shell.req: /dev/stdin: /sbin/ifup -> /sbin/ifup (raw, ambiguous, via content index)
/sbin/ifup
$

Also improved diagnostics and updated copyright statement.
2007-03-12 15:06:02 +03:00
Alexey Tourbin
5852768964 find-package (FindByName): enhanced /usr/bin/which part
There's been a few problems.

1) ~/bin should not be checked.

$ /usr/lib/rpm/shell.req -v /dev/stdin <<<vim
warning: no package provides /home/at/bin/vim
shell.req: /dev/stdin: vim not found (skip)
$

Fortunately /usr/bin/which has --skip-tilde option.

2) Check for /etc/alternatives was missing.

$ PATH=/bin:/usr/bin /usr/lib/rpm/shell.req -v /dev/stdin <<<vim
shell.req: /dev/stdin: vim -> /usr/bin/vim -> vim-X11
vim-console
vim-enhanced (via rpmdb)
vim-X11
vim-console
vim-enhanced
$

This is why FindByName should ultimately call FindByPath.
After this change, it works just fine:

$ scripts/shell.req.in -v /dev/stdin <<<vim
shell.req.in: /dev/stdin: vim -> /usr/bin/vim -> ... (via which)
shell.req.in: /dev/stdin: /usr/bin/vim -> /usr/bin/vim (alternative)
/usr/bin/vim
$

Also enabled /usr/bin/which --all option and added diagnostics
for really ambiguous cases.
2007-03-12 15:06:00 +03:00
Alexey Tourbin
8d2821443d find-package: factored FindByPath() and FindByName()
Actually if you think about it a few hours or so... you may come to
know that FindByName() should ultimately call FindByPath().  But this
will be the next commit.
2007-03-12 15:05:59 +03:00
Alexey Tourbin
f9a7e6dea2 find-package: if some path is provided by two or more rpmdb packages, output raw dependence
Here is the problem:

$ /usr/lib/rpm/shell.req -v /dev/stdin <<</usr/bin/openssl-config
shell.req: /dev/stdin: /usr/bin/openssl-config -> libssl-devel<STDERR-NEWLINE>
openssl (via rpmdb)
libssl-devel
openssl
$

Here is the solution:

$ /usr/lib/rpm/shell.req -v /dev/stdin <<</usr/bin/openssl-config
shell.req: /dev/stdin: /usr/bin/openssl-config provided by: libssl-devel openssl
shell.req: /dev/stdin: /usr/bin/openssl-config -> /usr/bin/openssl-config (raw)
/usr/bin/openssl-config
$

Note that this new behaviour now matches content index search:

$ grep openssl-config ~tmp/build/cache/contents/contents_index_bin
/usr/bin/openssl-config /usr/bin/openssl-config
$
2007-03-12 15:05:58 +03:00
Alexey Tourbin
ed12439edd scripts/find-package.in: added verbosity
Now it works like this:

$ /usr/lib/rpm/shell.req -v /usr/bin/buildreq
shell.req: /usr/bin/buildreq: cat -> /bin/cat -> coreutils (via rpmdb)
shell.req: /usr/bin/buildreq: cmp -> /usr/bin/cmp -> diffutils (via rpmdb)
shell.req: /usr/bin/buildreq: function(Info) not found (skip)
shell.req: /usr/bin/buildreq: function(show_help) not found (skip)
shell.req: /usr/bin/buildreq: function(show_usage) not found (skip)
shell.req: /usr/bin/buildreq: rm -> /bin/rm -> coreutils (via rpmdb)
shell.req: /usr/bin/buildreq: sed -> /bin/sed -> sed (via rpmdb)
coreutils
diffutils
sed
$

It looks like there's a problem with function(Info) here.
Verbosity is a good thing.
2007-03-11 15:00:25 +03:00
Alexey Tourbin
2bce0efdba scripts/find-package.in: adapted for empty RPM_BUILD_ROOT and `sh -u'
Note: this is non-essential change, so I won't update copyright notice.
2007-03-11 15:00:22 +03:00
5416277102 Removed cvsid tags. 2006-05-14 17:05:34 +04:00
ebc53cf631 use functions 2003-11-09 16:47:45 +00:00