From 3946dbb956afcd005cba0f1899acae5a74a109d4 Mon Sep 17 00:00:00 2001 Message-Id: <3946dbb956afcd005cba0f1899acae5a74a109d4.1682849409.git.yantar92@posteo.net> From: Ihor Radchenko Date: Sat, 1 Apr 2023 12:00:48 +0200 Subject: [PATCH v4 1/8] Upgrade Org build system to handle third-party dependencies * mk/default.mk (pkgdir_top): New variable holding the location of third-party packages to be downloaded if necessary during compilation. (EMACS_VERSION): New variable holding current Emacs version, according to EMACS. (pkgdir): New variable holding subdir where the third-party packages are downloaded, according to EMACS_VERSION. (EMACSFLAGS): New variable holding extra flags to be passed to Emacs executable when running make. We follow "PROGRAMFLAGS" convention as requested by GNU standards: https://www.gnu.org/prep/standards/html_node/Command-Variables.html (EPACKAGES): List of packages to be installed (unless already present in the `load-path') during compilation. (package-install): (INSTALL_PACKAGES): New command to download and install missing packages. (EMACSQ): Update, setting default package location to pkgdir. * mk/targets.mk (uppkg): New target to download install missing packages. (check test): (repro): (compile compile-dirty): Use the new uppkg target. (cleanpkg): New target cleaning up the downloaded packages. (cleanall): Use the new target. (.PHONY): (CONF_BASE): (CONF_DEST): (CONF_CALL): Update according to the new variables and targets. * .gitignore: Ignore the downloaded packages. This commit paves the way towards third-party built-time dependencies for Org. In particular, towards including compat.el dependency. According to EPACKAGES, we can auto-download necessary packages, unless they are manually specified via -L switches in EMACSFLAGS. Link: https://orgmode.org/list/87v8ks6rhf.fsf@localhost --- .gitignore | 1 + mk/default.mk | 31 ++++++++++++++++++++++++++++++- mk/targets.mk | 25 ++++++++++++++++--------- 3 files changed, 47 insertions(+), 10 deletions(-) diff --git a/.gitignore b/.gitignore index 4bb81c359..0d9c5b297 100644 --- a/.gitignore +++ b/.gitignore @@ -48,6 +48,7 @@ local*.mk .gitattributes mk/x11idle ChangeLog +pkg-deps/ # Files generated during `make packages/org` in a clone of `elpa.git`. diff --git a/mk/default.mk b/mk/default.mk index fa46661e8..393d7336a 100644 --- a/mk/default.mk +++ b/mk/default.mk @@ -6,6 +6,7 @@ # Name of your emacs binary EMACS = emacs +EMACS_VERSION := $(shell $(EMACS) -Q --batch --eval '(message "%s" emacs-version)' 2>&1) # Where local software is found prefix = /usr/share @@ -31,6 +32,17 @@ GIT_BRANCH = TMPDIR ?= /tmp testdir = $(TMPDIR)/tmp-orgtest +# Where to store Org dependencies +top_builddir := $(shell pwd) +pkgdir_top := $(top_builddir)/pkg-deps +pkgdir := $(pkgdir_top)/$(EMACS_VERSION) + +# Extra flags to be passed to Emacs +EMACSFLAGS ?= + +# Third-party packages to install when running make +EPACKAGES ?= + # Configuration for testing # Verbose ERT summary by default for Emacs-28 and above. # To override: @@ -72,12 +84,25 @@ REPRO_ARGS ?= req-ob-lang = --eval '(require '"'"'ob-$(ob-lang))' lst-ob-lang = ($(ob-lang) . t) req-extra = --eval '(require '"'"'$(req))' +package-define-refresh-mark = --eval '(setq org--compile-packages-missing nil)' +package-need-refresh-mark = --eval '(unless (require '"'"'$(package) nil t) (setq org--compile-packages-missing t))' +package-refresh-maybe = --eval '(if org--compile-packages-missing (package-refresh-contents) (message "No third-party packages need to be installed"))' +package-install-maybe = --eval '(unless (require '"'"'$(package) nil t) (package-install '"'"'$(package)))' BTEST_RE ?= \\(org\\|ob\\|ox\\) BTEST_LOAD = \ --eval '(add-to-list '"'"'load-path (concat default-directory "lisp"))' \ --eval '(add-to-list '"'"'load-path (concat default-directory "testing"))' BTEST_INIT = $(BTEST_PRE) $(BTEST_LOAD) $(BTEST_POST) +ifeq (,$(EPACKAGES)) +INSTALL_PACKAGES = +else +INSTALL_PACKAGES = \ + $(BATCH) \ + $(package-define-refresh-mark) $(foreach package,$(EPACKAGES),$(package-need-refresh-mark)) $(package-refresh-maybe) \ + $(foreach package,$(EPACKAGES),$(package-install-maybe)) +endif + BTEST = $(BATCH) $(BTEST_INIT) \ -l org-batch-test-init \ --eval '(setq \ @@ -116,7 +141,11 @@ REPRO = $(NOBATCH) $(REPRO_INIT) $(REPRO_ARGS) # start Emacs with no user and site configuration # EMACSQ = -vanilla # XEmacs -EMACSQ = $(EMACS) -Q +EMACSQ = $(EMACS) -Q \ + $(EMACSFLAGS) \ + --eval '(setq vc-handled-backends nil org-startup-folded nil org-element-cache-persistent nil)' \ + --eval '(make-directory "$(pkgdir)" t)' \ + --eval '(setq package-user-dir "$(pkgdir)")' --eval '(package-initialize)' # Using emacs in batch mode. BATCH = $(EMACSQ) -batch \ diff --git a/mk/targets.mk b/mk/targets.mk index 06016561c..18140c5c0 100644 --- a/mk/targets.mk +++ b/mk/targets.mk @@ -27,21 +27,21 @@ ifneq ($(GITSTATUS),) GITVERSION := $(GITVERSION:.dirty=).dirty endif -.PHONY: all oldorg update update2 up0 up1 up2 single $(SUBDIRS) \ +.PHONY: all oldorg update update2 up0 up1 up2 uppkg single $(SUBDIRS) \ check test install $(INSTSUB) \ info html pdf card refcard doc docs \ autoloads cleanall clean $(CLEANDIRS:%=clean%) \ clean-install cleanelc cleandirs \ - cleanlisp cleandoc cleandocs cleantest \ + cleanlisp cleandoc cleandocs cleantest cleanpkg \ compile compile-dirty uncompiled \ config config-test config-exe config-all config-eol config-version \ vanilla repro -CONF_BASE = EMACS DESTDIR ORGCM ORG_MAKE_DOC -CONF_DEST = lispdir infodir datadir testdir +CONF_BASE = EMACS DESTDIR ORGCM ORG_MAKE_DOC EPACKAGES +CONF_DEST = lispdir infodir datadir testdir pkgdir CONF_TEST = BTEST_PRE BTEST_POST BTEST_OB_LANGUAGES BTEST_EXTRA BTEST_RE CONF_EXEC = CP MKDIR RM RMR FIND CHMOD SUDO PDFTEX TEXI2PDF TEXI2HTML MAKEINFO INSTALL_INFO -CONF_CALL = BATCH BATCHL ELC ELCDIR NOBATCH BTEST MAKE_LOCAL_MK MAKE_ORG_INSTALL MAKE_ORG_VERSION +CONF_CALL = BATCH BATCHL ELC ELCDIR NOBATCH INSTALL_PACKAGES BTEST MAKE_LOCAL_MK MAKE_ORG_INSTALL MAKE_ORG_VERSION config-eol:: EOL = \# config-eol:: config-all config config-all:: @@ -86,7 +86,7 @@ local.mk: all compile:: $(foreach dir, doc lisp, $(MAKE) -C $(dir) clean;) -compile compile-dirty:: +compile compile-dirty:: uppkg $(MAKE) -C lisp $@ all clean-install:: $(foreach dir, $(SUBDIRS), $(MAKE) -C $(dir) $@;) @@ -94,7 +94,7 @@ all clean-install:: vanilla: -@$(NOBATCH) & -check test:: compile +check test:: uppkg compile check test test-dirty:: -$(MKDIR) $(testdir) TMPDIR=$(testdir) $(BTEST) @@ -102,6 +102,10 @@ ifeq ($(TEST_NO_AUTOCLEAN),) # define this variable to leave $(testdir) around f $(MAKE) cleantest endif +uppkg:: + @$(MKDIR) -p $(pkgdir) + -@$(INSTALL_PACKAGES) + up0 up1 up2:: git checkout $(GIT_BRANCH) git remote update @@ -126,7 +130,7 @@ $(INSTSUB): autoloads: lisp $(MAKE) -C $< $@ -repro: cleanall autoloads +repro: cleanall uppkg autoloads -@$(REPRO) & cleandirs: @@ -134,7 +138,7 @@ cleandirs: clean: cleanlisp cleandoc -cleanall: cleandirs cleantest +cleanall: cleandirs cleantest cleanpkg -$(FIND) . \( -name \*~ -o -name \*# -o -name .#\* \) -exec $(RM) {} + -$(FIND) $(CLEANDIRS) \( -name \*~ -o -name \*.elc \) -exec $(RM) {} + @@ -159,3 +163,6 @@ cleantest: $(FIND) $(testdir) -type d -exec $(CHMOD) u+w {} + && \ $(RMR) $(testdir) ; \ } + +cleanpkg: + -$(RMR) $(pkgdir_top) -- 2.40.0