From a304cc2342c4cd85a59d38fb61709543d3d39fca Mon Sep 17 00:00:00 2001 From: Jen-Chieh Shen Date: Sat, 26 Mar 2022 22:31:31 +0800 Subject: [PATCH] Done command package --- cmds/compile.js | 2 +- cmds/{build.js => package.js} | 13 ++++++++--- lisp/build.el | 23 ------------------- lisp/extern/package-build.el | 22 ++++++++++++++++++ lisp/extern/package-recipe.el | 16 +++++++++++++ lisp/package.el | 43 +++++++++++++++++++++++++++++++++++ 6 files changed, 92 insertions(+), 27 deletions(-) rename cmds/{build.js => package.js} (74%) delete mode 100644 lisp/build.el create mode 100644 lisp/extern/package-recipe.el create mode 100644 lisp/package.el diff --git a/cmds/compile.js b/cmds/compile.js index 4f6105ce..24d26a2c 100644 --- a/cmds/compile.js +++ b/cmds/compile.js @@ -21,7 +21,7 @@ const util = require("../src/util"); -exports.command = ['compile [names..]']; +exports.command = ['compile [names..]', 'build [names..]']; exports.desc = 'byte compile all Emacs Lisp files in the package'; exports.builder = { names: { diff --git a/cmds/build.js b/cmds/package.js similarity index 74% rename from cmds/build.js rename to cmds/package.js index cc695403..be31b996 100644 --- a/cmds/build.js +++ b/cmds/package.js @@ -21,9 +21,16 @@ const util = require("../src/util"); -exports.command = ['build']; -exports.desc = ''; +exports.command = ['package [dest]']; +exports.desc = 'Build a package artefact, and put it into the given destination'; +exports.builder = { + dest: { + description: 'destination path/folder', + requiresArg: false, + type: 'string', + }, +}; exports.handler = async (argv) => { - await util.e_call(argv, 'build'); + await util.e_call(argv, 'package', argv.dest); }; diff --git a/lisp/build.el b/lisp/build.el deleted file mode 100644 index 958c66d8..00000000 --- a/lisp/build.el +++ /dev/null @@ -1,23 +0,0 @@ -;;; build.el --- Build package into installable tar file -*- lexical-binding: t; -*- - -;;; Commentary: -;; -;; Command use to build package into installable tar file -;; -;; $ eask build -;; - -;;; Code: - -(load-file (expand-file-name - "_prepare.el" - (file-name-directory (nth 1 (member "-scriptload" command-line-args))))) - -(eask-start - (eask-pkg-init) - (eask-package-install 'package-build) - (if (eask-package-multi-p) - () - (message "\n No need to build single file packages"))) - -;;; build.el ends here diff --git a/lisp/extern/package-build.el b/lisp/extern/package-build.el index 009c3ba3..7239b0ac 100644 --- a/lisp/extern/package-build.el +++ b/lisp/extern/package-build.el @@ -2,6 +2,28 @@ ;;; Commentary: ;;; Code: +(defun package-build--create-tar (name version directory) + "Create a tar file containing the contents of VERSION of package NAME." + (let ((tar (expand-file-name (concat name "-" version ".tar") + package-build-archive-dir)) + (dir (concat name "-" version))) + ;; XXX https://github.com/melpa/package-build/pull/34 + ;; (when (eq system-type 'windows-nt) + ;; (setq tar (replace-regexp-in-string "^\\([a-z]\\):" "/\\1" tar))) + (let ((default-directory directory)) + (process-file package-build-tar-executable nil + (get-buffer-create "*package-build-checkout*") nil + "-cvf" tar + "--exclude=.git" + "--exclude=.hg" + dir)) + (when (and package-build-verbose noninteractive) + (message "Created %s containing:" (file-name-nondirectory tar)) + (dolist (line (sort (process-lines package-build-tar-executable + "--list" "--file" tar) + #'string<)) + (message " %s" line))))) + (defun package-build-expand-file-specs (dir specs &optional subdir allow-empty) "In DIR, expand SPECS, optionally under SUBDIR. The result is a list of (SOURCE . DEST), where SOURCE is a source diff --git a/lisp/extern/package-recipe.el b/lisp/extern/package-recipe.el new file mode 100644 index 00000000..b982bd9a --- /dev/null +++ b/lisp/extern/package-recipe.el @@ -0,0 +1,16 @@ +;;; package-recipe.el --- External module `package-recipe' -*- lexical-binding: t; -*- +;;; Commentary: +;;; Code: + +(with-eval-after-load 'package-recipe + ;; Specializations of package-build classes and methods to define a + ;; directory based recipe. + (defclass package-directory-recipe (package-recipe) + ((dir :initarg :dir :initform "."))) + + (cl-defmethod package-recipe--working-tree ((rcp package-directory-recipe)) + (oref rcp dir)) + + (cl-defmethod package-build--get-commit ((_rcp package-directory-recipe)))) + +;;; package-recipe.el ends here diff --git a/lisp/package.el b/lisp/package.el new file mode 100644 index 00000000..585c00ab --- /dev/null +++ b/lisp/package.el @@ -0,0 +1,43 @@ +;;; package.el --- Build a package artefact -*- lexical-binding: t; -*- + +;;; Commentary: +;; +;; Build a package artefact, and put it into the given destination +;; +;; $ eask package [dest] +;; +;; +;; Positional options: +;; +;; [dest] destination path/folder +;; + +;;; Code: + +(load-file (expand-file-name + "_prepare.el" + (file-name-directory (nth 1 (member "-scriptload" command-line-args))))) + +(defconst eask-dist-path "dist" + "Name of default target directory for building packages.") + +(eask-start + (let ((dest (or (eask-argv 0) eask-dist-path))) + (ignore-errors (make-directory (expand-file-name dest) t)) + + (eask-package-install 'package-build) + (require 'package-recipe) + (eask-load "./extern/package-build") ; override + (eask-load "./extern/package-recipe") + + (let* ((name (eask-guess-package-name)) + (patterns (or eask-files package-build-default-files-spec)) + (path default-directory) + (version (eask-package-get :version)) + (rcp (package-directory-recipe name :name name :files patterns :dir path)) + (package-build-working-dir path) + (package-build-archive-dir (expand-file-name dest))) + (package-build--package rcp version)) + (message "\n Done."))) + +;;; package.el ends here