Speedup for pkg_version
Stephen Montgomery-Smith
stephen at math.missouri.edu
Sun Jul 29 00:44:43 UTC 2007
This is a kludge, but it makes pkg_version 4 times faster on my set up.
The idea is that "make -V PKGNAME" should ordinarily be a very fast
operation. So it runs a very cut down version of bsd.port.mk. If that
bombs with an error, then it does the full bsd.port.mk.
Maybe portsmanager and similar tools could use this idea.
-------------- next part --------------
--- usr.sbin/pkg_install/version/perform.c-orig 2007-07-28 19:20:33.000000000 -0500
+++ usr.sbin/pkg_install/version/perform.c 2007-07-28 19:24:23.000000000 -0500
@@ -124,6 +124,30 @@
* we look for it's corresponding Makefile. If that fails we pull in
* the INDEX, and check there.
*/
+char exec_string[] =
+"makefile=`grep -v -E '\\.include.*\\<bsd\\.port\\.' Makefile`\n"
+"if ! make -V PKGNAME -f - 2>/dev/null <<EOM\n"
+"$makefile\n"
+".if defined(PORTVERSION)\n"
+"DISTVERSION?= \\${PORTVERSION:S/:/::/g}\n"
+".elif defined(DISTVERSION)\n"
+"PORTVERSION= \\${DISTVERSION:L:C/([a-z])[a-z]+/\\1/g:C/([0-9])([a-z])/\\1.\\2/g:C/:(.)/\\1/g:C/[^a-z0-9+]+/./g}\n"
+".endif\n"
+"PORTREVISION?= 0\n"
+".if \\${PORTREVISION} != 0\n"
+"_SUF1= _\\${PORTREVISION}\n"
+".endif\n"
+"PORTEPOCH?= 0\n"
+".if \\${PORTEPOCH} != 0\n"
+"_SUF2= ,\\${PORTEPOCH}\n"
+".endif\n"
+"PKGVERSION= \\${PORTVERSION:C/[-_,]/./g}\\${_SUF1}\\${_SUF2}\n"
+"PKGNAME= \\${PKGNAMEPREFIX}\\${PORTNAME}\\${PKGNAMESUFFIX}-\\${PKGVERSION}\n"
+"DISTNAME?= \\${PORTNAME}-\\${DISTVERSIONPREFIX}\\${DISTVERSION:C/:(.)/\\1/g}\\${DISTVERSIONSUFFIX}\n"
+"EOM\n"
+"then make -V PKGNAME\n"
+"fi\n";
+
static int
pkg_do(char *pkg)
{
@@ -158,7 +182,7 @@
if (plist.origin != NULL && !UseINDEXOnly) {
snprintf(tmp, PATH_MAX, "%s/%s", PORTS_DIR, plist.origin);
if (isdir(tmp) && chdir(tmp) != FAIL && isfile("Makefile")) {
- if ((latest = vpipe("/usr/bin/make -V PKGNAME", tmp)) == NULL)
+ if ((latest = vpipe(exec_string, tmp)) == NULL)
warnx("Failed to get PKGNAME from %s/Makefile!", tmp);
else
show_version(plist, latest, "port");
More information about the freebsd-ports
mailing list