Merge pull request #607 from milkypostman/create-recipe-helpers

Helpers for recipe authors
This commit is contained in:
Steve Purcell 2013-03-26 01:10:04 -07:00
commit da15f0e6c7
2 changed files with 55 additions and 6 deletions

View file

@ -45,17 +45,19 @@
(require 'package) (require 'package)
(require 'lisp-mnt) (require 'lisp-mnt)
(defcustom package-build-working-dir (expand-file-name "working/") (defconst pb/this-dir (file-name-directory (or load-file-name (buffer-file-name))))
(defcustom package-build-working-dir (expand-file-name "working/" pb/this-dir)
"Directory in which to keep checkouts." "Directory in which to keep checkouts."
:group 'package-build :group 'package-build
:type 'string) :type 'string)
(defcustom package-build-archive-dir (expand-file-name "packages/") (defcustom package-build-archive-dir (expand-file-name "packages/" pb/this-dir)
"Directory in which to keep compiled archives." "Directory in which to keep compiled archives."
:group 'package-build :group 'package-build
:type 'string) :type 'string)
(defcustom package-build-recipes-dir (expand-file-name "recipes/") (defcustom package-build-recipes-dir (expand-file-name "recipes/" pb/this-dir)
"Directory containing recipe files." "Directory containing recipe files."
:group 'package-build :group 'package-build
:type 'string) :type 'string)
@ -759,6 +761,47 @@ FILES is a list of (SOURCE . DEST) relative filepath pairs."
(current-time-string)) (current-time-string))
file-name))) file-name)))
;;; Helpers for recipe authors
(defvar package-build-minor-mode-map
(let ((m (make-sparse-keymap)))
(define-key m (kbd "C-c C-c") 'package-build-current-recipe)
m)
"Keymap for `package-build-minor-mode'.")
(define-minor-mode package-build-minor-mode
"Helpful functionality for building packages."
nil
" PBuild"
package-build-minor-mode-map)
;;;###autoload
(defun package-build-create-recipe (name fetcher)
"Create a new recipe for package NAME using FETCHER."
(interactive
(list (intern (read-string "Package name: "))
(intern
(let ((fetcher-types (mapcar #'symbol-name '(github git wiki bzr hg cvs svn))))
(completing-read
"Fetcher: "
fetcher-types
nil t nil nil (car fetcher-types))))))
(let ((recipe-file (expand-file-name (symbol-name name) package-build-recipes-dir)))
(when (file-exists-p recipe-file)
(error "Recipe already exists"))
(find-file recipe-file)
(let* ((extra-params
(cond
((eq 'github fetcher) '(:repo "USER/REPO"))
((eq 'wiki fetcher) '())
(t '(:url "SCM_URL_HERE"))))
(template `(,name :fetcher ,fetcher ,@extra-params)))
(insert (pp-to-string template))
(emacs-lisp-mode)
(package-build-minor-mode)
(beginning-of-buffer))))
;;;###autoload ;;;###autoload
(defun package-build-current-recipe () (defun package-build-current-recipe ()
"Build archive for the recipe defined in the current buffer." "Build archive for the recipe defined in the current buffer."
@ -793,6 +836,8 @@ FILES is a list of (SOURCE . DEST) relative filepath pairs."
(message "%s" (error-message-string err)) (message "%s" (error-message-string err))
nil)))) nil))))
;;;###autoload ;;;###autoload
(defun package-build-all () (defun package-build-all ()
"Build all packages in the `package-build-recipe-alist'." "Build all packages in the `package-build-recipe-alist'."
@ -844,8 +889,8 @@ FILES is a list of (SOURCE . DEST) relative filepath pairs."
;; Utility functions ;; Utility functions
(autoload 'json-encode "json") (require 'json)
(eval-after-load 'json '(load (expand-file-name "json-fix"))) (load (expand-file-name "json-fix" pb/this-dir))
(defun package-build-recipe-alist-as-json (fn) (defun package-build-recipe-alist-as-json (fn)
(interactive) (interactive)

View file

@ -1,4 +1,8 @@
((nil . ((eval . (when (and (buffer-file-name) ((nil . ((eval . (when (and (buffer-file-name)
(file-regular-p (buffer-file-name)) (file-regular-p (buffer-file-name))
(string-match-p "^[^.]" (buffer-file-name))) (string-match-p "^[^.]" (buffer-file-name)))
(emacs-lisp-mode)))))) (emacs-lisp-mode)
(unless (featurep 'package-build)
(let ((load-path (cons ".." load-path)))
(require 'package-build)))
(package-build-minor-mode))))))