From 256d995a314d7add086e744c78ec28176be917e8 Mon Sep 17 00:00:00 2001 From: riastradh Date: Wed, 29 May 2024 02:06:45 +0000 Subject: [PATCH] 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. --- share/man/man5/mk.conf.5 | 12 +++++++++++- share/mk/bsd.own.mk | 10 +++++++++- sys/sys/cdefs_aout.h | 9 ++++++++- sys/sys/cdefs_elf.h | 11 +++++++++-- 4 files changed, 37 insertions(+), 5 deletions(-) diff --git a/share/man/man5/mk.conf.5 b/share/man/man5/mk.conf.5 index 98d3395e49a2..4406063ee1ca 100644 --- a/share/man/man5/mk.conf.5 +++ b/share/man/man5/mk.conf.5 @@ -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 diff --git a/share/mk/bsd.own.mk b/share/mk/bsd.own.mk index 8e6404ee10c3..83c151265ec9 100644 --- a/share/mk/bsd.own.mk +++ b/share/mk/bsd.own.mk @@ -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) @@ -235,6 +235,14 @@ PRINTOBJDIR= ${MAKE} -V .OBJDIR PRINTOBJDIR= echo /error/bsd.own.mk/PRINTOBJDIR # avoid infinite recursion .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, diff --git a/sys/sys/cdefs_aout.h b/sys/sys/cdefs_aout.h index b58e72f6d7ec..f62546d8cf48 100644 --- a/sys/sys/cdefs_aout.h +++ b/sys/sys/cdefs_aout.h @@ -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 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 */ diff --git a/sys/sys/cdefs_elf.h b/sys/sys/cdefs_elf.h index bf997c84b378..bea672a3523f 100644 --- a/sys/sys/cdefs_elf.h +++ b/sys/sys/cdefs_elf.h @@ -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)