Module Name:    src
Committed By:   riastradh
Date:           Wed May 29 02:06:46 UTC 2024

Modified Files:
        src/share/man/man5: mk.conf.5
        src/share/mk: bsd.own.mk
        src/sys/sys: cdefs_aout.h cdefs_elf.h

Log Message:
New make(1) variable NETBSD_REVISIONID in the NetBSD build.

This is intended to be a tree-wide revision identifier, like a commit
hash or similar.  This way, in builds from non-CVS trees where
per-file $NetBSD$ revision ids aren't incremented, we can still track
some version provenance of files with ident(1).

If defined, bsd.own.mk adds a macro _NETBSD_REVISIONID to CPPFLAGS
with the stringified text of NETBSD_REVISIONID.

In turn, if _NETBSD_REVISIONID is defined in sys/cdefs.h, then
__RCSID will put the concatenation of:
- `$NetBSD: '
- the file name
- ` '
- _NETBSD_REVISIONID
- ` $'
alongside the per-file revision id passed as an argument to __RCSID.

Since this is passed through command-line arguments, it doesn't cause
make to consider any dependencies to change when the revision id
changes -- so incremental builds remain incremental.  And if you
don't set it, nothing changes from the __RCSID we had before.

Currently nothing sets NETBSD_REVISIONID automatically yet -- subject
to experimentation.  Could just be verbatim commit hash, or could be
longer `hg identify' output -- or, in git, with the help of tags,
could be `git describe --dirty' output like

10.99.10-2924-gd01834fb75de

(or `10.99.10-2924-gd01834fb75de-dirty' if the working tree is dirty)
for the commit at
https://mail-index.netbsd.org/source-changes/2024/05/24/msg151526.html
which is 2924 linear commits after the commit bumping sys/param.h to
10.99.10 and (in the current git conversion) had commit hash starting
with d01834fb75de.  This may require some discipline around branching
and tagging but it's worth a shot -- we'll see.

Based on a patch from joerg@ a while ago.


To generate a diff of this commit:
cvs rdiff -u -r1.108 -r1.109 src/share/man/man5/mk.conf.5
cvs rdiff -u -r1.1373 -r1.1374 src/share/mk/bsd.own.mk
cvs rdiff -u -r1.20 -r1.21 src/sys/sys/cdefs_aout.h
cvs rdiff -u -r1.58 -r1.59 src/sys/sys/cdefs_elf.h

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/share/man/man5/mk.conf.5
diff -u src/share/man/man5/mk.conf.5:1.108 src/share/man/man5/mk.conf.5:1.109
--- src/share/man/man5/mk.conf.5:1.108	Sun Jul 23 16:52:37 2023
+++ src/share/man/man5/mk.conf.5	Wed May 29 02:06:45 2024
@@ -1,4 +1,4 @@
-.\"	$NetBSD: mk.conf.5,v 1.108 2023/07/23 16:52:37 lukem Exp $
+.\"	$NetBSD: mk.conf.5,v 1.109 2024/05/29 02:06:45 riastradh Exp $
 .\"
 .\"  Copyright (c) 1999-2023 The NetBSD Foundation, Inc.
 .\"  All rights reserved.
@@ -1859,6 +1859,16 @@ builds from real releases.
 .DFLTu
 .Pq I.e., Dq no .
 .
+.It Sy NETBSD_REVISIONID
+Tree-wide revision identifier, such as a Mercurial or Git commit hash
+or similar.
+If set, will be included in program notes where
+.Xr __RCSID 3
+and
+.Xr __KERNEL_RCSID 3
+are used, and will be reported by
+.Xr ident 1 .
+.DFLTu
 .It Sy NOCLEANDIR
 If set, avoids the
 .Dq make cleandir

Index: src/share/mk/bsd.own.mk
diff -u src/share/mk/bsd.own.mk:1.1373 src/share/mk/bsd.own.mk:1.1374
--- src/share/mk/bsd.own.mk:1.1373	Sun Apr 28 08:01:04 2024
+++ src/share/mk/bsd.own.mk	Wed May 29 02:06:45 2024
@@ -1,4 +1,4 @@
-#	$NetBSD: bsd.own.mk,v 1.1373 2024/04/28 08:01:04 nia Exp $
+#	$NetBSD: bsd.own.mk,v 1.1374 2024/05/29 02:06:45 riastradh Exp $
 
 # This needs to be before bsd.init.mk
 .if defined(BSD_MK_COMPAT_FILE)
@@ -236,6 +236,14 @@ PRINTOBJDIR=	echo /error/bsd.own.mk/PRIN
 .endif
 
 #
+# Make sure we set _NETBSD_REVISIONID in CPPFLAGS if requested.
+#
+.ifdef NETBSD_REVISIONID
+_NETBSD_REVISIONID_STR=	"${NETBSD_REVISIONID}"
+CPPFLAGS+=	-D_NETBSD_REVISIONID=${_NETBSD_REVISIONID_STR:Q}
+.endif
+
+#
 # Determine if running in the NetBSD source tree by checking for the
 # existence of build.sh and tools/ in the current or a parent directory,
 # and setting _SRC_TOP_ to the result.

Index: src/sys/sys/cdefs_aout.h
diff -u src/sys/sys/cdefs_aout.h:1.20 src/sys/sys/cdefs_aout.h:1.21
--- src/sys/sys/cdefs_aout.h:1.20	Thu May 18 17:55:38 2006
+++ src/sys/sys/cdefs_aout.h	Wed May 29 02:06:46 2024
@@ -1,4 +1,4 @@
-/*	$NetBSD: cdefs_aout.h,v 1.20 2006/05/18 17:55:38 christos Exp $	*/
+/*	$NetBSD: cdefs_aout.h,v 1.21 2024/05/29 02:06:46 riastradh Exp $	*/
 
 /*
  * Written by J.T. Conklin <j...@wimsey.com> 01/17/95.
@@ -77,7 +77,14 @@
 
 #undef __KERNEL_RCSID
 
+#ifdef _NETBSD_REVISIONID
+#define	__RCSID(_s)							      \
+	__IDSTRING(rcsid,_s);						      \
+	__IDSTRING(revisionid,						      \
+	    "$" "NetBSD: " __FILE__ " " _NETBSD_REVISIONID " $")
+#else
 #define	__RCSID(_s)	__IDSTRING(rcsid,_s)
+#endif
 #define	__SCCSID(_s)
 #define	__SCCSID2(_s)
 #if 0	/* XXX userland __COPYRIGHTs have \ns in them */

Index: src/sys/sys/cdefs_elf.h
diff -u src/sys/sys/cdefs_elf.h:1.58 src/sys/sys/cdefs_elf.h:1.59
--- src/sys/sys/cdefs_elf.h:1.58	Fri Jun  4 01:58:02 2021
+++ src/sys/sys/cdefs_elf.h	Wed May 29 02:06:46 2024
@@ -1,4 +1,4 @@
-/*	$NetBSD: cdefs_elf.h,v 1.58 2021/06/04 01:58:02 thorpej Exp $	*/
+/*	$NetBSD: cdefs_elf.h,v 1.59 2024/05/29 02:06:46 riastradh Exp $	*/
 
 /*
  * Copyright (c) 1995, 1996 Carnegie-Mellon University.
@@ -162,7 +162,14 @@
 
 #define	__IDSTRING(_n,_s)		__SECTIONSTRING(.ident,_s)
 
-#define	__RCSID(_s)			__IDSTRING(rcsid,_s)
+#ifdef _NETBSD_REVISIONID
+#define	__RCSID(_s)							      \
+	__IDSTRING(rcsid,_s);						      \
+	__IDSTRING(revisionid,						      \
+	    "$" "NetBSD: " __FILE__ " " _NETBSD_REVISIONID " $")
+#else
+#define	__RCSID(_s)	__IDSTRING(rcsid,_s)
+#endif
 #define	__SCCSID(_s)
 #define __SCCSID2(_s)
 #define	__COPYRIGHT(_s)			__SECTIONSTRING(.copyright,_s)

Reply via email to