Skip to content

Commit

Permalink
Test against init.el with all module flags enabled
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
marienz committed May 27, 2024
1 parent 78ad780 commit f48edf8
Show file tree
Hide file tree
Showing 3 changed files with 46 additions and 6 deletions.
28 changes: 25 additions & 3 deletions build-helpers/full-init
Original file line number Diff line number Diff line change
Expand Up @@ -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; -*-
Expand All @@ -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))))
Expand Down
6 changes: 4 additions & 2 deletions checks.nix
Original file line number Diff line number Diff line change
Expand Up @@ -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";
Expand Down Expand Up @@ -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;
Expand Down
18 changes: 17 additions & 1 deletion default.nix
Original file line number Diff line number Diff line change
Expand Up @@ -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).
Expand Down Expand Up @@ -426,5 +442,5 @@ let
'';
in
{
inherit doomDirWithAllModules doomEmacs emacsWithDoom;
inherit doomDirWithAllModules doomDirWithAllModulesAndFlags doomEmacs emacsWithDoom;
}

0 comments on commit f48edf8

Please sign in to comment.