From 05fe1f8cfb40041d45f4e4c7819c1c41b03f199f Mon Sep 17 00:00:00 2001 From: Jen-Chieh Shen Date: Sat, 23 Nov 2024 00:54:57 +0800 Subject: [PATCH] feat: Add clean dist --- lisp/_prepare.lisp | 13 ++++++++++++- lisp/clean/dist.lisp | 26 ++++++++++++++++++++++++-- lisp/core/package.lisp | 7 +++++-- 3 files changed, 41 insertions(+), 5 deletions(-) diff --git a/lisp/_prepare.lisp b/lisp/_prepare.lisp index 54e8e23..44be141 100644 --- a/lisp/_prepare.lisp +++ b/lisp/_prepare.lisp @@ -494,7 +494,7 @@ to actually set up the systems." ;; NOTE: Use this as project root? (defun qob-primary-root () "Return the primary system path." - (let ((path (car (cdr (qob-primary-system-entry))))) + (let ((path (cdr (qob-primary-system-entry)))) (qob-file-name-directory path))) (defun qob-find-asd-file (name) @@ -608,6 +608,11 @@ Set up the systems; on contrary, you should use the function (defvar qob-dist-path "dist/" "Default path where to place the package artifact.") +(defun qob-dist-path () + "Path to dist path." + (let ((path (or (qob-args 0) qob-dist-path))) + (qob-expand-fn path))) + ;; ;;; Entry @@ -693,4 +698,10 @@ Set up the systems; on contrary, you should use the function (qob-msg "✓ Loading Qob file in ~A... done!" qob-file) (qob-msg "✗ Loading Qob file... missing!"))))) +;; +;;; Commad variables + +(defvar qob-no-cleaning-operation-p nil + "Set to non-nil if there is no cleaning operation done.") + ;;; End of lisp/_prepare.lisp diff --git a/lisp/clean/dist.lisp b/lisp/clean/dist.lisp index 16e67dc..83a9cc2 100644 --- a/lisp/clean/dist.lisp +++ b/lisp/clean/dist.lisp @@ -9,8 +9,30 @@ ;;; Code +(defun qob-clean-dist () + "Clean up the dist files." + (let* ((name (qob-primary-system-name)) + (system (qob-primary-system)) + (version (asdf:component-version system)) + (f-name (qob-format "~A-~A" name version)) + (f-tar (qob-expand-fn (qob-format "~A.tar" f-name) qob-dist-path)) + (deleted 0) + (delete-dir nil)) + (when (probe-file f-tar) + (ignore-errors (delete-file f-tar)) + (incf deleted)) + (setq delete-dir (ignore-errors (uiop:delete-empty-directory qob-dist-path))) + (qob-msg "") + (qob-info "(Total of ~A file~A and ~A directory deleted)" deleted + (qob--sinr deleted "" "s") + (if delete-dir "1" "0")))) + (qob-start - ;; TODO: .. - ) + (let ((qob-dist-path (qob-dist-path))) + (if (probe-file qob-dist-path) + (qob-clean-dist) + (progn + (qob-info "(No dist folder needs to be cleaned)" qob-dist-path) + (setq qob-no-cleaning-operation-p t))))) ;;; End of lisp/clean/dist.lisp diff --git a/lisp/core/package.lisp b/lisp/core/package.lisp index ee2cee2..b144577 100644 --- a/lisp/core/package.lisp +++ b/lisp/core/package.lisp @@ -23,6 +23,7 @@ (ignore-errors (delete-directory f-dir :recursive t)) (ensure-directories-exist f-dir) + ;; Copy files over (dolist (path (qob-system-files)) (let* ((path (qob-2str path)) (rel-path (qob-s-replace root "" path)) @@ -41,12 +42,14 @@ (qob-s-remove-prefix (qob-2str qob-dist-path) tar)))) + ;; Delete cache folder + (ignore-errors (delete-directory f-dir :recursive t)) + (qob-msg "") (qob-info "(Built in ~A.tar)" tar))) (qob-start - (let* ((qob-dist-path (or (qob-args 0) qob-dist-path)) - (qob-dist-path (qob-expand-fn qob-dist-path))) + (let ((qob-dist-path (qob-dist-path))) (ensure-directories-exist qob-dist-path) (let ((name (qob-primary-system-name))