From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.io!.POSTED.blaine.gmane.org!not-for-mail From: =?UTF-8?Q?Bj=C3=B6rn?= Bidar via "Bug reports for GNU Emacs, the Swiss army knife of text editors" Newsgroups: gmane.emacs.bugs Subject: bug#74413: [PATCH] Allow to store and read repository information of VCS builds Date: Mon, 18 Nov 2024 16:21:28 +0200 Message-ID: <15254.7609222651$1731939811@news.gmane.org> References: <86frnovhg8.fsf@gnu.org> Reply-To: =?UTF-8?Q?Bj=C3=B6rn?= Bidar Mime-Version: 1.0 Content-Type: multipart/mixed; boundary="=-=-=" Injection-Info: ciao.gmane.io; posting-host="blaine.gmane.org:116.202.254.214"; logging-data="20179"; mail-complaints-to="usenet@ciao.gmane.io" User-Agent: Gnus/5.13 (Gnus v5.13) Cc: Po Lu , 74413@debbugs.gnu.org To: Eli Zaretskii Original-X-From: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane-mx.org@gnu.org Mon Nov 18 15:23:22 2024 Return-path: Envelope-to: geb-bug-gnu-emacs@m.gmane-mx.org Original-Received: from lists.gnu.org ([209.51.188.17]) by ciao.gmane.io with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1tD2ew-000540-2f for geb-bug-gnu-emacs@m.gmane-mx.org; Mon, 18 Nov 2024 15:23:22 +0100 Original-Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1tD2eh-0001o7-QN; Mon, 18 Nov 2024 09:23:08 -0500 Original-Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1tD2ed-0001nc-8T for bug-gnu-emacs@gnu.org; Mon, 18 Nov 2024 09:23:05 -0500 Original-Received: from debbugs.gnu.org ([2001:470:142:5::43]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1tD2ec-0003mI-Ns for bug-gnu-emacs@gnu.org; Mon, 18 Nov 2024 09:23:03 -0500 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=debbugs.gnu.org; s=debbugs-gnu-org; h=MIME-Version:Date:References:In-Reply-To:From:To:Subject; bh=iSKF+aOv+zNc9chE83lAnWVcmp+/Ph5w70G8vy1y/Cw=; b=SDT4VmqqWrROturOIsb/9E+hpMPybzacpLfPNE30275y4AldPtTMGA9SxyxqJwNStm7MVVoqP5qNQmOdMnU/XLNu1NngWt8329+gIQTkrZUGVk5JwCqyodtL2Se30Jy8Rx/LQk/RRRDLCnVZTV3WSuG/hK1r+qkpygCfzVlq2M4S2/yHDJCHT96JSwKmplhuH82lhQGqw0UD/2kpC53cbxq1oSYR6353BL/dB3ayBmJqXops1PAKZuZTzcvKFzI5j7FRZUIVZSUaLCV1P4mEIfZs/jyQ4DWvG01rEhWzjq6ZN5bLkSqHpGt0WafpWOHkxb8G8gEqC4t4RW7uVASgqQ==; Original-Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1tD2ec-0004aD-6X for bug-gnu-emacs@gnu.org; Mon, 18 Nov 2024 09:23:02 -0500 X-Loop: help-debbugs@gnu.org Resent-From: =?UTF-8?Q?Bj=C3=B6rn?= Bidar Original-Sender: "Debbugs-submit" Resent-CC: bug-gnu-emacs@gnu.org Resent-Date: Mon, 18 Nov 2024 14:23:02 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: followup 74413 X-GNU-PR-Package: emacs X-GNU-PR-Keywords: patch Original-Received: via spool by 74413-submit@debbugs.gnu.org id=B74413.173193972217538 (code B ref 74413); Mon, 18 Nov 2024 14:23:02 +0000 Original-Received: (at 74413) by debbugs.gnu.org; 18 Nov 2024 14:22:02 +0000 Original-Received: from localhost ([127.0.0.1]:60685 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1tD2dd-0004Ya-Hr for submit@debbugs.gnu.org; Mon, 18 Nov 2024 09:22:02 -0500 Original-Received: from thaodan.de ([185.216.177.71]:57660) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1tD2db-0004YN-SH for 74413@debbugs.gnu.org; Mon, 18 Nov 2024 09:22:00 -0500 Original-Received: from odin (dsl-trebng12-50dc7b-49.dhcp.inet.fi [80.220.123.49]) by thaodan.de (Postfix) with ESMTPSA id A392ED0008E; Mon, 18 Nov 2024 16:21:28 +0200 (EET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=thaodan.de; s=mail; t=1731939688; bh=o8kAOZrLR6Jx0472X32+glrUgAH+zgUTiWapCl7+Brg=; h=From:To:Cc:Subject:In-Reply-To:References:Date; b=jsUJC4LvNwKfAXhYnNMCHb2RBMzfHE65dRIppnLKHlQ0lr+Y2LnOfc/h3z3trcBDE ccp3+sOzRBb7sig5J/FhUPS/PnMAKEXUG3t/NfXUtegLDp0E12jWMFouMpfIcUi14B qM46hiyv1QruV3tdAZnc77FLbKnGkJ3ZdWHwARO8t6q4RseR7rCaX9gMpPuiSUuDIs cT2H/vfNbAL5mhI2PWf54sep3UfT/sAlXZpNJ6JOy0MYtv3O6mYfkz8Tv+vgE4jA9z EvK+LBwVIQHayTEueb8dOr5x7AjjAiQ86AsRkDDRjWP9Oe7vhjggT5Z1zt+T3++Mpl m3WTXUyAkaGSr4Bojp7fh01lhZT0A3Sf82kXuvnSoYsxN3hvhwDPejzzNniSHV3X51 IUrV+fYmDVqqUKAbhSq9Csjm4s+vt6HKezHq7eMGOi0Zp6zbnZdv3Izr1evfcbDFiJ cfnHLzQkEFvqw15nYTKfqonriCAJkUeAmevniY3w2neFy32QuP8ibXOSfsqVBoLfWr fXD4NUXXC1EiDsHAT7xRSzuXWw+P0CyZmiLCSROS13R6Qar74GGoTw2l6KdRZpqyyv T5NxgX1LdbKm26jcMsN3oJfrX1IAFr/7UJmfmnZ7EMIyc0LPbOsDqvvidAAjXjwubN MYY0RbM9iSNyjfCzIkWpuhrE= In-Reply-To: <86frnovhg8.fsf@gnu.org> (Eli Zaretskii's message of "Mon, 18 Nov 2024 14:45:27 +0200") Autocrypt: addr=bjorn.bidar@thaodan.de; prefer-encrypt=nopreference; keydata= mDMEZNfpPhYJKwYBBAHaRw8BAQdACBEmr+0xwIIHZfIDlZmm7sa+lHHSb0g9FZrN6qE6ru60JUJq w7ZybiBCaWRhciA8Ympvcm4uYmlkYXJAdGhhb2Rhbi5kZT6IlgQTFgoAPgIbAwULCQgHAgIiAgYV CgkICwIEFgIDAQIeBwIXgBYhBFHxdut1RzAepymoq1wbdKFlHF9oBQJk1/YmAhkBAAoJEFwbdKFl HF9oB9cBAJoIIGQKXm4cpap+Flxc/EGnYl0123lcEyzuduqvlDT0AQC3OlFKm/OiqJ8IMTrzJRZ8 phFssTkSrrFXnM2jm5PYDoiTBBMWCgA7FiEEUfF263VHMB6nKairXBt0oWUcX2gFAmTX6T4CGwMF CwkIBwICIgIGFQoJCAsCBBYCAwECHgcCF4AACgkQXBt0oWUcX2hbCQEAtru7kvM8hi8zo6z9ux2h K+B5xViKuo7Z8K3IXuK5ugwA+wUfKzomzdBPhfxDsqLcEziGRxoyx0Q3ld9aermBUccHtBxCasO2 cm4gQmlkYXIgPG1lQHRoYW9kYW4uZGU+iJMEExYKADsCGwMFCwkIBwICIgIGFQoJCAsCBBYCAwEC HgcCF4AWIQRR8XbrdUcwHqcpqKtcG3ShZRxfaAUCZNf2FQAKCRBcG3ShZRxfaCzSAP4hZ7cSp0YN XYpcjHdsySh2MuBhhoPeLGXs+2kSiqBiOwD/TP8AgPEg/R+SI9GI9on7fBJJ0mp2IT8kZ2rhDOjg gA6IkwQTFgoAOxYhBFHxdut1RzAepymoq1wbdKFlH X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list X-BeenThere: bug-gnu-emacs@gnu.org List-Id: "Bug reports for GNU Emacs, the Swiss army knife of text editors" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane-mx.org@gnu.org Original-Sender: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane-mx.org@gnu.org Xref: news.gmane.io gmane.emacs.bugs:295597 Archived-At: --=-=-= Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable Eli Zaretskii writes: >> Date: Mon, 18 Nov 2024 10:18:11 +0200 >> From: Bj=C3=B6rn Bidar via "Bug reports for GNU Emacs, >> the Swiss army knife of text editors" >>=20 >> Emacs has the feature to read the repository version and >> branch if git is installed during the build and afterwards if also >> the sources including the VCS repository is present. >>=20 >> For the Android builds the feature was added to store and read the >> information mentioned above in a special version file. > > Po Lu, why is that needed in the Android build, and how is it used > there? > >> This patch reuses that mechanism so it can be reused on other platforms >> to use for the same reasons its available for Android and to also be >> able to use the information on CI workers without git installed and/or a >> full source checkout. > > Doesn't that go against the tendency to have _less_ detailed/private > information in the build? We've lately removed some relatively useful > infos from what we report in commands that use the build information. The information added is only the branch and the repository similarly as used by the Android builds. There's no private information there unless the exact change reference Emacs was built on is private. > More generally, could you present the motivation and the rationale for > making this information available in production builds? The information wouldn't be only available to production builds but also testing/developer builds that are builtin in a CI environment to e.g. provide test builds for developers to use or to instruct user to use to try to reproduce a bug. Even for production builds it could be useful for convenience to track down the exact reference/branch a build came from from, that's side effect only thou. >> The things I'm not sure about for this patch are: >> - Is the generating of the version file in the right place in >> Makefile.in > > It should be in the build tree, yes. I was more talking if the section for the file should be in a separate recipe or if etc-emacsver fits this purpose, I think the usecase is quite close so it does sound ok to me. >> - Is the data directory the right place to store the file > > Not sure, but I don't see why not. OK I was just mostly wondering about the macOS builds who don't ship the etc dir but since the information is be present also during dumping if so desired it shouldn't be a big issue anyway. >> - Should the creation of the version file be shared between the Android >> builds and the other platforms > > Let's first discuss whether this is at all needed and a good idea, > okay? Sure np, I was mostly speaking out load. > >> - ${INSTALL_PROGRAM} $(INSTALL_STRIP) src/emacs${EXEEXT} "$(DESTDIR)${bi= ndir}/$(EMACSFULL)" >> + ${INSTALL_PROGRAM} $(INSTALL_STRIP) src/emacs${EXEEXT} "$(DESTDIR)${bi= ndir}/$(EMACS)" > > Why this change (and other similar ones)? What does EMACSFULL have to > do with the repository version data? > >> @@ -826,6 +837,7 @@ install-man: >> umask 022; ${MKDIR_P} "$(DESTDIR)${man1dir}" >> thisdir=3D`pwd -P`; \ >> cd ${mansrcdir}; \ >> + cp ctags.1 gnuctags.1; \ > > This hunk also looks unrelated. I'm sorry these changes came in accidentally. I attached a fixed patch belo= w: --=-=-= Content-Type: text/x-patch Content-Disposition: attachment; filename=0001-Allow-to-store-and-read-repository-information-of-VC.patch >From d522173a61a84237d098690ee5289d2c11307306 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bj=C3=B6rn=20Bidar?= Date: Mon, 18 Nov 2024 16:18:40 +0200 Subject: [PATCH] Allow to store and read repository information of VCS builds Store repository information in version file if Emacs is build from source while VCS is present. The version file can also be stored in the Emacs sources prior built to indicate if Emacs was built from VCS sources. An example use case could be if Emacs runs on a system where the version control system isn't available, e.g. similarly as it is intended for Android builds. Another one is to be able to set the VCS information for workers in a CI environment where sources are generated separately from VCS but it or the VCS repository isn't present on the worker. Reuse the same mechanism that exist for Android builds if the version file is present. * Makefile.in (etc-emacsver): Generate etc/version file with revision and branch if git is installed and Emacs sources are VCS sources. * lisp/version.el (emacs-repository-get-branch) (emacs-repository-get-version, emacs-repository-branch-static) (emacs-repository-version-static): Implement static versions that can use the information generated during build if present. --- .gitignore | 1 + Makefile.in | 13 ++++++++++++- lisp/version.el | 44 ++++++++++++++++++++++++++++++++------------ 3 files changed, 45 insertions(+), 13 deletions(-) diff --git a/.gitignore b/.gitignore index c1f31514d06..d3b737d590c 100644 --- a/.gitignore +++ b/.gitignore @@ -314,6 +314,7 @@ doc/misc/modus-themes.texi doc/misc/org.texi etc/DOC etc/refcards/emacsver.tex +etc/version gnustmp* /info/ diff --git a/Makefile.in b/Makefile.in index 30a762ed03b..2817742af86 100644 --- a/Makefile.in +++ b/Makefile.in @@ -452,7 +452,18 @@ etc-emacsver: sed "s/[@]majorversion@/$${majorversion}/" \ ${srcdir}/etc/refcards/emacsver.tex.in > emacsver.tex.$$$$ && \ ${srcdir}/build-aux/move-if-change emacsver.tex.$$$$ \ - ${srcdir}/etc/refcards/emacsver.tex + ${srcdir}/etc/refcards/emacsver.tex; \ + if [ -e $(srcdir)/.git ] && \ + which git > /dev/null ; then \ + { (cd $(srcdir) \ + && git rev-parse HEAD || echo "Unknown") \ + && (git rev-parse --abbrev-ref HEAD \ + || echo "Unknown") } 2> /dev/null > \ + ${top_builddir}/etc/version.$$$$; \ + ${srcdir}/build-aux/move-if-change \ + ${top_builddir}/etc/version.$$$$ \ + ${top_builddir}/etc/version; \ + else : ;fi # The shared gamedir name as a C string literal, or a null ptr if not in use. PATH_GAME = $(if $(use_gamedir),"$(gamedir)",((char const *) 0)) diff --git a/lisp/version.el b/lisp/version.el index db2afd55694..3b2c91c03dc 100644 --- a/lisp/version.el +++ b/lisp/version.el @@ -171,15 +171,21 @@ emacs-repository-version-git (looking-at "[[:xdigit:]]\\{40\\}")) (match-string 0))))) -(defun emacs-repository-version-android () +(defun emacs-repository-version-static (dir) "Return the Emacs repository revision Emacs was built from. Value is nil if Emacs was not built from a repository checkout. -Use information from the `/assets/version' special file." +Use information from the `DIR/version' special file." (with-temp-buffer - (insert-file-contents "/assets/version") + (insert-file-contents (expand-file-name "version" dir)) (let ((string (buffer-substring 1 (line-end-position)))) (and (not (equal string "Unknown")) string)))) +(defun emacs-repository-version-android () + "Return the Emacs repository revision Emacs was built from. +Value is nil if Emacs was not built from a repository checkout. +Use information from the `/assets/version' special file." + (emacs-repository-version-static "/assets")) + (defun emacs-repository-get-version (&optional dir _external) "Try to return as a string the repository revision of the Emacs sources. The format of the returned string is dependent on the VCS in use. @@ -194,9 +200,13 @@ emacs-repository-get-version Optional argument DIR is a directory to use instead of `source-directory'. Optional argument EXTERNAL is ignored." - (cond ((and (featurep 'android) - (eq system-type 'android)) - (emacs-repository-version-android)) + (cond ((and (or (and (featurep 'android) + (eq system-type 'android) + (setq dir "/assets")) + (and (not dir) + (file-exists-p (expand-file-name "version" data-directory)) + (setq dir data-directory))) + (emacs-repository-version-static dir))) (t (emacs-repository-version-git (or dir source-directory))))) @@ -209,8 +219,14 @@ emacs-repository-branch-android "Return the Emacs repository branch Emacs was built from. Value is nil if Emacs was not built from a repository checkout. Use information from the `/assets/version' special file." + (emacs-repository-branch-static "/assets")) + +(defun emacs-repository-branch-static (dir) + "Return the Emacs repository branch Emacs was built from. +Value is nil if Emacs was not built from a repository checkout. +Use information from the `DIR/version' special file." (with-temp-buffer - (insert-file-contents "/assets/version") + (insert-file-contents (expand-file-name "version" dir)) (end-of-line) (forward-char) (let ((string (buffer-substring (point) (line-end-position)))) @@ -232,8 +248,8 @@ emacs-repository-get-branch "Try to return as a string the repository branch of the Emacs sources. The format of the returned string is dependent on the VCS in use. -If Emacs is built for Android, use the version information -embedded in the Emacs installation package. +If Emacs is built for Android or contains version file, +use the version information embedded in the Emacs installation package. Value is nil if the sources do not seem to be under version control, or if we could not determine the branch. Note that @@ -241,9 +257,13 @@ emacs-repository-get-branch correspond to the running Emacs. Optional argument DIR is a directory to use instead of `source-directory'." - (cond ((and (featurep 'android) - (eq system-type 'android)) - (emacs-repository-branch-android)) + (cond ((and (or (and (featurep 'android) + (eq system-type 'android) + (setq dir "/assets")) + (and (not dir) + (file-exists-p (expand-file-name "version" data-directory)) + (setq dir data-directory))) + (emacs-repository-branch-static dir))) (t (emacs-repository-branch-git (or dir source-directory))))) -- 2.45.2 --=-=-=--