Test against init.el with all module flags enabled

Detect module flags by walking package.el files.

This still does not build all dependencies, because some are enabled
only if some flag or other module is disabled. But this should be close.
This commit is contained in:
Marien Zwart 2024-05-26 17:20:24 +10:00
parent 78ad78072d
commit f48edf8b34
No known key found for this signature in database
3 changed files with 46 additions and 6 deletions

View file

@ -15,9 +15,21 @@
;; See the License for the specific language governing permissions and
;; limitations under the License.
;; Simple recursive walk of packages.el to extract (modulep! +flag)
;;
;; Does not cover (modulep! :cat mod +flag). That is: assumes each flag is
;; referenced at least once by shortened form in the module itself.
;;
;; No attempt at efficiency, but package.el files are small...
(defun walk-package-exp (l)
(cond ((not (consp l)) nil)
((and (= 2 (length l)) (eq 'modulep! (car l))) (cdr l))
(t (mapcan #'walk-package-exp l))))
(defcli! full-init
((output-directory ("-o" dir) "Directory to write init.el into.")
(&flag full? ("--full")))
(&flag flags? ("--flags")))
"Write init.el with all modules."
(with-temp-buffer
(insert ";;; init.el -*- no-byte-compile: t; -*-
@ -30,8 +42,18 @@
(let ((cat (car kp))
(name (cdr kp)))
(when name
(if full?
(error "unimplemented")
(if-let ((flags?)
(packages-path (doom-module-locate-path
cat name doom-module-packages-file))
(tree (with-temp-buffer
(insert "(\n")
(insert-file-contents packages-path)
(goto-char (point-max))
(insert ")\n")
(goto-char (point-min))
(read (current-buffer))))
(flags (walk-package-exp tree)))
(insert (format " %s %s\n" cat (cons name flags)))
(insert (format " %s %s\n" cat name))))))
(insert ")\n")
(write-region nil nil (expand-file-name "init.el" output-directory))))

View file

@ -37,7 +37,8 @@ let
mkDoom = args: (makeDoomPackages (common // args)).doomEmacs;
mkDoomDir = args: writeTextDir "init.el" (toInit args);
minimalDoomDir = mkDoomDir { config = [ "default" ]; };
fullDoomDir = (makeDoomPackages (common // { doomDir = emptyDirectory; })).doomDirWithAllModules;
allModsDoomDir = (makeDoomPackages (common // { doomDir = emptyDirectory; })).doomDirWithAllModules;
allFlagsDoomDir = (makeDoomPackages (common // { doomDir = emptyDirectory; })).doomDirWithAllModulesAndFlags;
doomTest = name: init: doomArgs: testers.testEqualContents {
assertion = "name = ${name}; modules = ${toPretty {} init}; args = ${toPretty {} doomArgs};";
expected = writeText "doom-expected" "Doom functions";
@ -66,7 +67,8 @@ in {
minimalEmacs = (makeDoomPackages (common // {
doomDir = minimalDoomDir;
})).emacsWithDoom;
full = mkDoom { doomDir = fullDoomDir; };
allModules = mkDoom { doomDir = allModsDoomDir; };
allModulesAndFlags = mkDoom { doomDir = allFlagsDoomDir; };
example = mkDoom { doomDir = ./doomdirs/example; };
example-without-loader = mkDoom {
doomDir = ./doomdirs/example;

View file

@ -71,6 +71,22 @@ let
${runtimeShell} ${doomSource}/bin/doomscript ${./build-helpers/full-init} -o $out
'';
doomDirWithAllModulesAndFlags = runCommandLocal "doom-full-init"
{
env = {
EMACS = lib.getExe emacs;
# Enable this to troubleshoot failures at this step.
#DEBUG = "1";
};
# We set DOOMLOCALDIR somewhere harmless below to stop Doom from trying to
# create it somewhere read-only.
} ''
mkdir $out
export DOOMLOCALDIR=$(mktemp -d)
${runtimeShell} ${doomSource}/bin/doomscript ${./build-helpers/full-init} --flags -o $out
'';
# Step 1: determine which Emacs packages to pull in.
#
# Inputs: Doom, original DOOMDIR (only init.el and packages.el are used).
@ -426,5 +442,5 @@ let
'';
in
{
inherit doomDirWithAllModules doomEmacs emacsWithDoom;
inherit doomDirWithAllModules doomDirWithAllModulesAndFlags doomEmacs emacsWithDoom;
}