Skip site navigation (1)Skip section navigation (2)
Date:      Tue, 9 Apr 2002 23:29:28 +0400 (MSD)
From:      "Lev A. Serebryakov" <lev@serebryakov.spb.ru>
To:        FreeBSD-gnats-submit@FreeBSD.org
Subject:   ports/36933: [PATHCES] New feature for pkg_create and port subsystem: BUILDHOST comment for +CONTENT files
Message-ID:  <200204091929.g39JTSu61245@ftp.translate.ru>

next in thread | raw e-mail | index | archive | help

>Number:         36933
>Category:       ports
>Synopsis:       [PATHCES] New feature for pkg_create and port subsystem: BUILDHOST comment for +CONTENT files
>Confidential:   no
>Severity:       non-critical
>Priority:       low
>Responsible:    freebsd-ports
>State:          open
>Quarter:        
>Keywords:       
>Date-Required:
>Class:          update
>Submitter-Id:   current-users
>Arrival-Date:   Tue Apr 09 12:30:21 PDT 2002
>Closed-Date:
>Last-Modified:
>Originator:     Lev A. Serebryakov <lev@serebryakov.spb.ru>
>Release:        FreeBSD 4.4-STABLE i386
>Organization:
>Environment:
System: FreeBSD freebsd.sereb.net 4.4-STABLE FreeBSD 4.4-STABLE #0: Fri Feb 8 21:06:14 MSK 2002 root@freebsd.sereb.net:/usr/src/sys/compile/LEVMAIL i386


>Description:

 It will be great, to have ability distinguish ports installed from ports and
ports installed form packages.
 There is simple solution: have reference to machine, on which port (package)
was build.
 There is THREE patches: two for source tree (pkg_create and pkg_info) and for
ports tree (for Mk/bsd.port.mk)
 
 Patch for pkg_create adds new parameter for pkg_create(1): `-H buildhost'
 If this parameter is given, pkg_create add such line in +COMMENT-file right
after `@comment ORIGIN' line:

@comment BUILDHOST:host decimalunixtime

 Patch for pkg_info adds ability ti show this information (-H option).

 Patch for bsd.port.mk adds support for this parameter (PKGBUILDHOST is 
defaulted to "`hostname`").
 Patch for bsd.port.mk is not RIGHT, because it doesn't check OSVERSION when
set PKGBUILDHOST. PLEASE, fix this. I could not determine, which OSVERSION will
be right, because I don't rule this variable.

 WARNING! Here are THREE patches from DIFFERENT places in `Fix:' section of PR!

>How-To-Repeat:
   

>Fix:
diff -ruN create.orig/create.h create/create.h
--- create.orig/create.h	Tue Apr  9 22:14:16 2002
+++ create/create.h	Tue Apr  9 22:22:49 2002
@@ -37,6 +37,7 @@
 extern char	*ExcludeFrom;
 extern char	*Mtree;
 extern char	*Pkgdeps;
+extern char	*HostAndTime;
 extern char	*Origin;
 extern char	*InstalledPkg;
 extern char	PlayPen[];
diff -ruN create.orig/main.c create/main.c
--- create.orig/main.c	Tue Apr  9 22:14:16 2002
+++ create/main.c	Tue Apr  9 22:30:53 2002
@@ -18,7 +18,7 @@
 #include "lib.h"
 #include "create.h"
 
-static char Options[] = "YNOhvyf:p:P:c:d:i:I:k:K:r:t:X:D:m:s:o:b:";
+static char Options[] = "YNOhvyf:p:P:c:d:i:I:k:K:r:t:X:D:m:s:o:b:H:";
 
 char	*Prefix		= NULL;
 char	*Comment        = NULL;
@@ -35,6 +35,7 @@
 char	*Mtree		= NULL;
 char	*Pkgdeps	= NULL;
 char	*Origin		= NULL;
+char	*HostAndTime	= NULL;
 char	*InstalledPkg	= NULL;
 char	PlayPen[FILENAME_MAX];
 int	Dereference	= FALSE;
@@ -116,6 +117,10 @@
 	    ExcludeFrom = optarg;
 	    break;
 
+	case 'H':
+	    HostAndTime = optarg;
+	    break;
+
 	case 'h':
 	    Dereference = TRUE;
 	    break;
@@ -195,7 +200,7 @@
 "usage: pkg_create [-YNOhvy] [-P pkgs] [-p prefix] [-f contents] [-i iscript]",
 "                  [-I piscript] [-k dscript] [-K pdscript] [-r rscript] ",
 "                  [-t template] [-X excludefile] [-D displayfile] ",
-"                  [-m mtreefile] [-o origin] -c comment -d description ",
+"                  [-m mtreefile] [-o origin] [-H buildhost] -c comment -d description ",
 "                  -f packlist pkg-filename",
 "       pkg_create [-YNhvy] -b pkg-name [pkg-filename]");
     exit(1);
diff -ruN create.orig/perform.c create/perform.c
--- create.orig/perform.c	Tue Apr  9 22:14:16 2002
+++ create/perform.c	Tue Apr  9 22:21:40 2002
@@ -104,6 +104,12 @@
     if (Origin)
 	add_plist(&plist, PLIST_COMMENT, strconcat("ORIGIN:", Origin));
 
+    /* Add host and time of building */
+    if (HostAndTime) {
+	asprintf(&cp,"BUILDHOST:%s %ld",HostAndTime,time(NULL));
+	add_plist(&plist, PLIST_COMMENT, cp);
+    }
+
     /* Stick the dependencies, if any, at the top */
     if (Pkgdeps) {
 	char **deps;
diff -ruN create.orig/pkg_create.1 create/pkg_create.1
--- create.orig/pkg_create.1	Tue Apr  9 22:14:16 2002
+++ create/pkg_create.1	Tue Apr  9 23:12:21 2002
@@ -46,6 +46,7 @@
 .Op Fl D Ar displayfile
 .Op Fl m Ar mtreefile
 .Op Fl o Ar originpath
+.Op Fl H Ar buildhost
 .Fl c Ar comment
 .Fl d Ar description
 .Fl f Ar packlist
@@ -260,6 +261,8 @@
 .Em "Ports Collection" .
 It should be in the form
 .Pa MASTERCATEGORY/PORTDIR .
+.It Fl H Ar buildhost
+Record host where package build and current time as time of build.
 .It Fl y
 Use
 .Xr bzip2 1
=8<===============================================
diff -ruN info.orig/info.h info/info.h
--- info.orig/info.h	Tue Apr  9 22:51:56 2002
+++ info/info.h	Tue Apr  9 22:55:18 2002
@@ -33,22 +33,23 @@
 #define MAXNAMESIZE  20
 #endif
 
-#define	SHOW_COMMENT	0x0001
-#define SHOW_DESC	0x0002
-#define SHOW_PLIST	0x0004
-#define SHOW_INSTALL	0x0008
-#define SHOW_DEINSTALL	0x0010
-#define SHOW_REQUIRE	0x0020
-#define SHOW_PREFIX	0x0040
-#define SHOW_INDEX	0x0080
-#define SHOW_FILES	0x0100
-#define SHOW_DISPLAY	0x0200
-#define SHOW_REQBY	0x0400
-#define SHOW_MTREE	0x0800
-#define SHOW_SIZE	0x1000
-#define SHOW_ORIGIN	0x2000
-#define SHOW_CKSUM	0x4000
-#define SHOW_FMTREV	0x8000
+#define	SHOW_COMMENT	0x00000001
+#define SHOW_DESC	0x00000002
+#define SHOW_PLIST	0x00000004
+#define SHOW_INSTALL	0x00000008
+#define SHOW_DEINSTALL	0x00000010
+#define SHOW_REQUIRE	0x00000020
+#define SHOW_PREFIX	0x00000040
+#define SHOW_INDEX	0x00000080
+#define SHOW_FILES	0x00000100
+#define SHOW_DISPLAY	0x00000200
+#define SHOW_REQBY	0x00000400
+#define SHOW_MTREE	0x00000800
+#define SHOW_SIZE	0x00001000
+#define SHOW_ORIGIN	0x00002000
+#define SHOW_CKSUM	0x00004000
+#define SHOW_FMTREV	0x00008000
+#define SHOW_BUILDHOST	0x00010000
 
 struct which_entry {
     TAILQ_ENTRY(which_entry) next;
@@ -74,5 +75,6 @@
 extern void	show_cksum(const char *, Package *);
 extern void	show_origin(const char *, Package *);
 extern void	show_fmtrev(const char *, Package *);
+extern void	show_buildhost(const char *, Package *);
 
 #endif	/* _INST_INFO_H_INCLUDE */
diff -ruN info.orig/main.c info/main.c
--- info.orig/main.c	Tue Apr  9 22:51:56 2002
+++ info/main.c	Tue Apr  9 23:08:57 2002
@@ -28,7 +28,7 @@
   "$FreeBSD: src/usr.sbin/pkg_install/info/main.c,v 1.22.2.11 2001/11/19 09:45:30 sobomax Exp $";
 #endif
 
-static char Options[] = "acdDe:fgGhiIkl:LmopqrRst:vVW:x";
+static char Options[] = "acdDe:fgGhiIkl:LmopqrRst:vVW:xH";
 
 int	Flags		= 0;
 match_t	MatchType	= MATCH_GLOB;
@@ -138,6 +138,10 @@
 	    Flags |= SHOW_FMTREV;
 	    break;
 
+	case 'H':
+	    Flags |= SHOW_BUILDHOST;
+	    break;
+
 	case 'l':
 	    InfoPrefix = optarg;
 	    break;
@@ -220,7 +224,7 @@
 usage()
 {
     fprintf(stderr, "%s\n%s\n%s\n",
-	"usage: pkg_info [-cdDfGiIkLmopqrRsvVx] [-e package] [-l prefix]",
+	"usage: pkg_info [-cdDfGiIkLmopqrRsvVxH] [-e package] [-l prefix]",
 	"                [-t template] [-W filename] [pkg-name ...]",
 	"       pkg_info -a [flags]");
     exit(1);
diff -ruN info.orig/perform.c info/perform.c
--- info.orig/perform.c	Tue Apr  9 22:51:56 2002
+++ info/perform.c	Tue Apr  9 23:05:28 2002
@@ -216,6 +216,8 @@
 	    show_origin("Origin:\n", &plist);
 	if (Flags & SHOW_FMTREV)
 	    show_fmtrev("Packing list format revision:\n", &plist);
+	if (Flags & SHOW_BUILDHOST)
+	    show_buildhost("Build by:\n", &plist);
 	if (!Quiet)
 	    puts(InfoPrefix);
     }
diff -ruN info.orig/pkg_info.1 info/pkg_info.1
--- info.orig/pkg_info.1	Tue Apr  9 22:51:56 2002
+++ info/pkg_info.1	Tue Apr  9 23:12:56 2002
@@ -25,7 +25,7 @@
 .Nd a utility for displaying information on software packages
 .Sh SYNOPSIS
 .Nm
-.Op Fl cdDfgGiIkLmopqrRsvVx
+.Op Fl cdDfgGiIkLmopqrRsvVxH
 .Op Fl e Ar package
 .Op Fl l Ar prefix
 .Op Fl t Ar template
@@ -99,6 +99,9 @@
 package was generated, is located in the
 .Fx
 .Em "Ports Collection" .
+.It Fl H
+Show hostname of machine where package was build and time when it was
+happened. 
 .It Fl G
 Do not try to expand shell glob patterns in the
 .Ar pkg-name
diff -ruN info.orig/show.c info/show.c
--- info.orig/show.c	Tue Apr  9 22:51:56 2002
+++ info/show.c	Tue Apr  9 23:08:00 2002
@@ -316,3 +316,31 @@
 	printf("%s%s", InfoPrefix, title);
     printf("%d.%d\n", plist->fmtver_maj, plist->fmtver_mnr);
 }
+
+/* show buidhost and date */
+void
+show_buildhost(const char *title, Package *plist)
+{
+    char ts[64];
+    char *pc;
+    time_t t;
+    PackingList p;
+
+    if (!Quiet)
+	printf("%s%s", InfoPrefix, title);
+    for (p = plist->head; p != NULL; p = p->next)
+	if (p->type == PLIST_COMMENT && !strncmp(p->name, "BUILDHOST:", 10)) {
+	    pc = strchr(p->name + 10,' ');
+            if (!pc)
+		break;
+            *pc = '\0';
+	    pc++;
+            if (1 != sscanf(pc, "%ld", &t))
+		break;
+	    strftime(ts,64,"%x %X", gmtime(&t));
+	    printf("%s at %s\n", p->name + 10, ts);
+	    break;
+	}
+
+}
+
=8<===============================================
--- bsd.port.mk.orig	Tue Apr  9 22:24:42 2002
+++ bsd.port.mk	Tue Apr  9 22:29:50 2002
@@ -1222,6 +1222,7 @@
 _PORTDIRNAME!=	${BASENAME} ${.CURDIR}
 PORTDIRNAME?=	${_PORTDIRNAME}
 PKGORIGIN?=		${PKGCATEGORY}/${PORTDIRNAME}
+PKGBUILDHOST?=	"`hostname`"
 .endif
 
 PKG_CMD?=		/usr/sbin/pkg_create
@@ -1246,6 +1247,9 @@
 .endif
 .if defined(PKGORIGIN)
 PKG_ARGS+=		-o ${PKGORIGIN}
+.endif
+.if defined(PKGBUILDHOST)
+PKG_ARGS+=		-H ${PKGBUILDHOST}
 .endif
 .endif
 .if defined(PKG_NOCOMPRESS)
>Release-Note:
>Audit-Trail:
>Unformatted:

To Unsubscribe: send mail to majordomo@FreeBSD.org
with "unsubscribe freebsd-ports" in the body of the message




Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?200204091929.g39JTSu61245>