From c5332d1a4a65ad6b124d0919d275c0ddde045842 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bj=C3=B6rn=20Bidar?= Date: Sun, 17 Nov 2024 13:37:21 +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 | 20 ++++++++++++++++---- lisp/version.el | 44 ++++++++++++++++++++++++++++++++------------ 3 files changed, 49 insertions(+), 16 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..202b0417282 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)) @@ -627,7 +638,7 @@ install-arch-dep: umask 022; ${MKDIR_P} "$(DESTDIR)${bindir}" $(MAKE) -C lib-src install ifeq (${ns_self_contained},no) - ${INSTALL_PROGRAM} $(INSTALL_STRIP) src/emacs${EXEEXT} "$(DESTDIR)${bindir}/$(EMACSFULL)" + ${INSTALL_PROGRAM} $(INSTALL_STRIP) src/emacs${EXEEXT} "$(DESTDIR)${bindir}/$(EMACS)" ifeq (${HAVE_BE_APP},yes) ${INSTALL_PROGRAM} $(INSTALL_STRIP) src/Emacs "$(DESTDIR)${prefix}/apps/Emacs" endif @@ -637,7 +648,7 @@ install-arch-dep: endif ${INSTALL_DATA} src/emacs.pdmp "$(DESTDIR)${libexecdir}/emacs/${version}/${configuration}"/emacs-${EMACS_PDMP} endif - -chmod 755 "$(DESTDIR)${bindir}/$(EMACSFULL)" + -chmod 755 "$(DESTDIR)${bindir}/$(EMACS)" ifndef NO_BIN_LINK rm -f "$(DESTDIR)${bindir}/$(EMACS)" cd "$(DESTDIR)${bindir}" && $(LN_S_FILEONLY) "$(EMACSFULL)" "$(EMACS)" @@ -826,6 +837,7 @@ install-man: umask 022; ${MKDIR_P} "$(DESTDIR)${man1dir}" thisdir=`pwd -P`; \ cd ${mansrcdir}; \ + cp ctags.1 gnuctags.1; \ for page in *.1; do \ test "$$page" = ChangeLog.1 && continue; \ dest=`echo "$${page}" | sed -e 's/\.1$$//' -e '$(TRANSFORM)'`.1; \ @@ -969,7 +981,7 @@ uninstall: for page in *.1; do \ rm -f "$(DESTDIR)${man1dir}"/`echo "$${page}" | sed -e 's/\.1$$//' -e '$(TRANSFORM)'`.1$$ext; done; \ fi) - rm -f "$(DESTDIR)${bindir}/$(EMACS)" "$(DESTDIR)${bindir}/$(EMACSFULL)" + rm -f "$(DESTDIR)${bindir}/$(EMACS)" (if cd "$(DESTDIR)${icondir}"; then \ rm -f hicolor/*x*/apps/"${EMACS_NAME}.png" \ "hicolor/scalable/apps/${EMACS_NAME}.svg" \ 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