From 95f7fea814f6b7936aa6158d9c45e8a2b06e7394 Mon Sep 17 00:00:00 2001 From: Sameer Rahmani Date: Sun, 3 Jul 2022 22:50:32 +0100 Subject: [PATCH] Add defproject to the build system to start creating a generic build system --- build.el | 7 +++++-- core/fg42/build/core.el | 36 ++++++++++++++++++++++++++++++++---- core/fg42/build/docs.el | 14 ++++++-------- core/fg42/build/utils.el | 4 ++-- 4 files changed, 45 insertions(+), 16 deletions(-) diff --git a/build.el b/build.el index 54257ff..11672f5 100755 --- a/build.el +++ b/build.el @@ -55,6 +55,11 @@ PARAMS: +(defproject FG42 + project-root (nth 2 command-line-args-left) + fg42/build-docs-actions '(fg42/build-prepare-docs)) + + (defun print-help (command) "Print out a usage instructions and print out the invalid msg for COMMAND." (when command @@ -81,8 +86,6 @@ PARAMS: (set-terminal-coding-system 'utf-8) (set-keyboard-coding-system 'utf-8) - (setq project-root (car command-line-args-left)) - (let* ((fg42-home (car command-line-args-left)) (build-dir (from-root "/build")) (parsed-args (read-args (cdr command-line-args-left))) diff --git a/core/fg42/build/core.el b/core/fg42/build/core.el index 48e2b84..aa24504 100644 --- a/core/fg42/build/core.el +++ b/core/fg42/build/core.el @@ -29,20 +29,48 @@ (require 'seq) -(defvar project-root nil +(defvar fg42/build-project-name "FG42" + "The name to be uesd with in the output as as the project name") + +(defvar fg42/build-project-root nil "Root directory of the website source code.") -(defvar debug-mode nil) +(defvar fg42/build-debug-mode nil) + +(defvar fg42/build-author-name "Sameer Rahmani") +(defvar fg42/build-author-email "lxsameer@gnu.org") + +(defvar fg42/build-docs-actions nil + "Set of actions to run before building the +main docs.") + + +(defmacro defproject (prject-name &rest details) + "Create a project with the given DETAILS. + +The build system will consum these details for various purposes." + (declare (indent defun)) + (cons 'progn + (cons `(setq fg42/bulid-project-name + ,(symbol-name prject-name)) + (seq-reduce + (lambda (forms pair) + (let* ((varname (intern (format "fg42/build-%s" (car pair)))) + (val (cadr pair)) + (form `(setq ,varname ,val))) + (cons form forms))) + (seq-partition details 2) + nil)))) (defun from-root (path) "Return the full path of the given PATH in the project root." - (concat project-root path)) + (concat fg42/build-project-root path)) (defun prod-p () "Return non-nil if debug mode is turned off" - (not debug-mode)) + (not fg42/build-debug-mode)) (defun read-args (args) diff --git a/core/fg42/build/docs.el b/core/fg42/build/docs.el index 6abd011..930bd18 100644 --- a/core/fg42/build/docs.el +++ b/core/fg42/build/docs.el @@ -32,12 +32,8 @@ (require 'fg42/build/utils) (require 'fg42/build/ox-template) - -(defconst cube-template (from-root "/docs/site/templates/cube.org")) -(defconst cubes-index-template (from-root "/docs/site/templates/cubes.org")) - -(defconst author-name "Sameer Rahmani") -(defconst author-email "lxsameer@gnu.org") +(defvar cube-template (from-root "/docs/site/templates/cube.org")) +(defvar cubes-index-template (from-root "/docs/site/templates/cubes.org")) (defun fg42/build-docs-for-cube (build-dir cube) @@ -280,6 +276,8 @@ Not pages." (stage1-dir (expand-file-name "site" build-dir)) (final-dir (expand-file-name "site-build" build-dir))) + (mapc (lambda (f) (apply f build-dir base-url)) fg42/build-docs-actions) + ;; Create org files for the cubes (fg42/build-prepare-docs build-dir base-url) @@ -294,8 +292,8 @@ Not pages." ;;; Discover all the org files (setq org-agenda-files (all-org-files)) - (setf user-full-name author-name) - (setf user-mail-address author-email) + (setf user-full-name fg42/build-author-name) + (setf user-mail-address fg42/build-author-email) ;; Disable default header links (top, next) (setf org-html-home/up-format "") diff --git a/core/fg42/build/utils.el b/core/fg42/build/utils.el index 76f3893..8f2127f 100644 --- a/core/fg42/build/utils.el +++ b/core/fg42/build/utils.el @@ -75,13 +75,13 @@ (defun fg42/git-branch () - (cd project-root) + (cd fg42/build-project-root) (shell-command-to-string "git branch --show-current")) (defun fg42/version () "Returns the current version of FG42." - (cd project-root) + (cd fg42/build-project-root) (shell-command-to-string (format "git describe %s" (fg42/git-branch))))