2011-10-05 05:49:38 +00:00
|
|
|
;;; package-build.el --- Tools for curating the package archive
|
|
|
|
|
|
|
|
;; Copyright (C) 2011 Donald Ephraim Curtis <dcurtis@milkbox.net>
|
|
|
|
;; Copyright (C) 2009 Phil Hagelberg <technomancy@gmail.com>
|
|
|
|
|
|
|
|
;; Author: Donald Ephraim Curtis <dcurtis@milkbox.net>
|
|
|
|
;; Created: 2011-09-30
|
|
|
|
;; Version: 0.1
|
|
|
|
;; Keywords: tools
|
|
|
|
|
2012-01-29 00:17:45 +00:00
|
|
|
;;
|
|
|
|
;; Credits:
|
|
|
|
;; Steve Purcell
|
|
|
|
;;
|
|
|
|
|
2011-10-05 05:49:38 +00:00
|
|
|
;; This file is not (yet) part of GNU Emacs.
|
|
|
|
;; However, it is distributed under the same license.
|
|
|
|
|
|
|
|
;; GNU Emacs is free software; you can redistribute it and/or modify
|
|
|
|
;; it under the terms of the GNU General Public License as published by
|
|
|
|
;; the Free Software Foundation; either version 3, or (at your option)
|
|
|
|
;; any later version.
|
|
|
|
|
|
|
|
;; GNU Emacs is distributed in the hope that it will be useful,
|
|
|
|
;; but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
;; GNU General Public License for more details.
|
|
|
|
|
|
|
|
;; You should have received a copy of the GNU General Public License
|
|
|
|
;; along with GNU Emacs; see the file COPYING. If not, write to the
|
|
|
|
;; Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
|
|
|
|
;; Boston, MA 02110-1301, USA.
|
|
|
|
|
|
|
|
;;; Commentary:
|
|
|
|
|
|
|
|
;; This file allows a curator to publish an archive of Emacs packages.
|
|
|
|
|
|
|
|
;; The archive is generated from an index, which contains a list of
|
|
|
|
;; projects and repositories from which to get them. The term
|
|
|
|
;; "package" here is used to mean a specific version of a project that
|
|
|
|
;; is prepared for download and installation.
|
|
|
|
|
|
|
|
;;; Code:
|
|
|
|
|
|
|
|
;; Since this library is not meant to be loaded by users
|
|
|
|
;; at runtime, use of cl functions should not be a problem.
|
|
|
|
(require 'cl)
|
|
|
|
|
|
|
|
(require 'package)
|
|
|
|
|
2012-01-22 05:13:19 +00:00
|
|
|
(defcustom package-build-working-dir (expand-file-name "working/")
|
|
|
|
"Directory in which to keep checkouts."
|
|
|
|
:group 'package-build
|
|
|
|
:type 'string)
|
2011-10-05 05:49:38 +00:00
|
|
|
|
2012-01-22 05:13:19 +00:00
|
|
|
(defcustom package-build-archive-dir (expand-file-name "packages/")
|
|
|
|
"Directory in which to keep compiled archives."
|
|
|
|
:group 'package-build
|
|
|
|
:type 'string)
|
2011-10-05 05:49:38 +00:00
|
|
|
|
2012-04-06 19:49:39 +00:00
|
|
|
(defcustom package-build-recipes-dir (expand-file-name "recipes/")
|
|
|
|
"Directory containing recipe files."
|
2012-01-22 05:13:19 +00:00
|
|
|
:group 'package-build
|
|
|
|
:type 'string)
|
2011-10-05 05:49:38 +00:00
|
|
|
|
2012-02-03 14:46:55 +00:00
|
|
|
(defvar package-build-alist nil
|
|
|
|
"List of package build specs.")
|
|
|
|
|
|
|
|
(defvar package-build-archive-alist nil
|
|
|
|
"List of already-built packages, in the standard package.el format.")
|
|
|
|
|
2012-02-11 11:49:02 +00:00
|
|
|
;;; Internal functions
|
2012-02-03 14:46:55 +00:00
|
|
|
|
2012-02-09 21:34:32 +00:00
|
|
|
(defun pb/find-parse-time (regex)
|
2012-01-29 02:10:55 +00:00
|
|
|
"Find REGEX in current buffer and format as a proper time version."
|
|
|
|
(format-time-string
|
|
|
|
"%Y%m%d"
|
|
|
|
(date-to-time
|
|
|
|
(print (progn (re-search-backward regex)
|
|
|
|
(match-string-no-properties 1))))))
|
2012-01-29 01:26:20 +00:00
|
|
|
|
2012-02-09 21:34:32 +00:00
|
|
|
(defun pb/run-process (dir prog &rest args)
|
2012-01-31 10:49:49 +00:00
|
|
|
"In DIR (or `default-directory' if unset) run command PROG with ARGS.
|
|
|
|
Output is written to the current buffer."
|
2012-01-29 13:09:07 +00:00
|
|
|
(let ((default-directory (or dir default-directory)))
|
2012-03-16 14:30:13 +00:00
|
|
|
(let ((exit-code (apply 'process-file prog nil (current-buffer) t args)))
|
|
|
|
(unless (zerop exit-code)
|
|
|
|
(error "Program '%s' with args '%s' exited with non-zero status %d"
|
|
|
|
prog args exit-code)))))
|
2012-01-29 13:09:07 +00:00
|
|
|
|
2012-01-30 12:46:44 +00:00
|
|
|
|
2012-02-09 21:34:32 +00:00
|
|
|
(defun pb/checkout (name config cwd)
|
2012-01-31 10:49:49 +00:00
|
|
|
"Check out source for package NAME with CONFIG under working dir CWD.
|
|
|
|
In turn, this function uses the :fetcher option in the config to
|
|
|
|
choose a source-specific fetcher function, which it calls with
|
|
|
|
the same arguments."
|
2012-01-30 12:46:44 +00:00
|
|
|
(let ((repo-type (plist-get config :fetcher)))
|
|
|
|
(print repo-type)
|
2012-02-09 21:34:32 +00:00
|
|
|
(funcall (intern (format "pb/checkout-%s" repo-type))
|
2012-01-30 12:46:44 +00:00
|
|
|
name config cwd)))
|
|
|
|
|
2012-03-19 12:50:51 +00:00
|
|
|
(defvar pb/last-wiki-fetch-time 0
|
|
|
|
"The time at which an emacswiki URL was last requested.
|
|
|
|
This is used to avoid exceeding the rate limit of 1 request per 2
|
|
|
|
seconds; the server cuts off after 10 requests in 20 seconds.")
|
|
|
|
|
2012-03-19 14:17:16 +00:00
|
|
|
(defvar pb/wiki-min-request-interval 2
|
2012-03-19 12:50:51 +00:00
|
|
|
"The shortest permissible interval between successive requests for Emacswiki URLs.")
|
|
|
|
|
2012-03-19 14:17:16 +00:00
|
|
|
(defmacro pb/with-wiki-rate-limit (&rest body)
|
2012-03-19 12:50:51 +00:00
|
|
|
"Rate-limit BODY code passed to this macro to match EmacsWiki's rate limiting."
|
|
|
|
(let ((now (gensym))
|
|
|
|
(elapsed (gensym)))
|
|
|
|
`(let* ((,now (float-time))
|
|
|
|
(,elapsed (- ,now pb/last-wiki-fetch-time)))
|
2012-03-19 14:17:16 +00:00
|
|
|
(when (< ,elapsed pb/wiki-min-request-interval)
|
|
|
|
(let ((wait (- pb/wiki-min-request-interval ,elapsed)))
|
2012-03-19 12:50:51 +00:00
|
|
|
(message "Waiting %s secs before hitting Emacswiki again" wait)
|
|
|
|
(sleep-for wait)))
|
|
|
|
(unwind-protect
|
|
|
|
(progn ,@body)
|
|
|
|
(setq pb/last-wiki-fetch-time (float-time))))))
|
|
|
|
|
|
|
|
(defun pb/grab-wiki-file (filename)
|
|
|
|
"Download FILENAME from emacswiki, returning its last-modified time."
|
|
|
|
(let* ((download-url (format "http://www.emacswiki.org/emacs/download/%s" filename))
|
|
|
|
(wiki-url (format "http://www.emacswiki.org/emacs/%s" filename)))
|
2012-03-19 14:17:16 +00:00
|
|
|
(pb/with-wiki-rate-limit
|
2012-03-19 12:50:51 +00:00
|
|
|
(url-copy-file download-url filename t))
|
2012-03-19 14:17:16 +00:00
|
|
|
(with-current-buffer (pb/with-wiki-rate-limit
|
2012-03-19 12:50:51 +00:00
|
|
|
(url-retrieve-synchronously wiki-url))
|
|
|
|
(pb/find-parse-time
|
|
|
|
"Last edited \\([0-9]\\{4\\}-[0-9]\\{2\\}-[0-9]\\{2\\} [0-9]\\{2\\}:[0-9]\\{2\\} [A-Z]\\{3\\}\\)"))))
|
|
|
|
|
2012-02-09 21:34:32 +00:00
|
|
|
(defun pb/checkout-wiki (name config dir)
|
2012-01-31 10:49:49 +00:00
|
|
|
"Checkout package NAME with config CONFIG from the EmacsWiki into DIR."
|
2012-01-30 13:56:23 +00:00
|
|
|
(with-current-buffer (get-buffer-create "*package-build-checkout*")
|
|
|
|
(message dir)
|
|
|
|
(unless (file-exists-p dir)
|
|
|
|
(make-directory dir))
|
2012-03-19 12:50:51 +00:00
|
|
|
(let ((files (or (plist-get config :files)
|
|
|
|
(list (format "%s.el" name))))
|
|
|
|
(default-directory dir))
|
|
|
|
(car (nreverse (sort (mapcar 'pb/grab-wiki-file files) 'string-lessp))))))
|
2012-01-30 13:56:23 +00:00
|
|
|
|
2012-03-17 18:45:55 +00:00
|
|
|
(defun pb/darcs-repo (dir)
|
|
|
|
"Get the current darcs repo for DIR."
|
|
|
|
(with-temp-buffer
|
|
|
|
(pb/run-process dir "darcs" "show" "repo")
|
|
|
|
(goto-char (point-min))
|
|
|
|
(re-search-forward "Default Remote: \\(.*\\)")
|
|
|
|
(match-string-no-properties 1)))
|
|
|
|
|
2012-02-09 21:34:32 +00:00
|
|
|
(defun pb/checkout-darcs (name config dir)
|
2012-01-31 10:49:49 +00:00
|
|
|
"Check package NAME with config CONFIG out of darcs into DIR."
|
2012-01-30 12:46:44 +00:00
|
|
|
(let ((repo (plist-get config :url)))
|
|
|
|
(with-current-buffer (get-buffer-create "*package-build-checkout*")
|
|
|
|
(cond
|
2012-03-17 18:45:55 +00:00
|
|
|
((and (file-exists-p (expand-file-name "_darcs" dir))
|
|
|
|
(string-equal (pb/darcs-repo dir) repo))
|
2012-01-30 12:46:44 +00:00
|
|
|
(print "checkout directory exists, updating...")
|
2012-02-09 21:34:32 +00:00
|
|
|
(pb/run-process dir "darcs" "pull"))
|
2012-01-30 12:46:44 +00:00
|
|
|
(t
|
2012-03-17 18:39:26 +00:00
|
|
|
(when (file-exists-p dir)
|
|
|
|
(delete-directory dir t nil))
|
2012-01-30 12:46:44 +00:00
|
|
|
(print "cloning repository")
|
2012-02-09 21:34:32 +00:00
|
|
|
(pb/run-process nil "darcs" "get" repo dir)))
|
|
|
|
(pb/run-process dir "darcs" "changes" "--last" "1")
|
|
|
|
(pb/find-parse-time
|
2012-01-30 12:46:44 +00:00
|
|
|
"\\([a-zA-Z]\\{3\\} [a-zA-Z]\\{3\\} \\( \\|[0-9]\\)[0-9] [0-9]\\{2\\}:[0-9]\\{2\\}:[0-9]\\{2\\} [A-Za-z]\\{3\\} [0-9]\\{4\\}\\)"))))
|
|
|
|
|
2012-03-17 18:45:55 +00:00
|
|
|
(defun pb/svn-repo (dir)
|
|
|
|
"Get the current svn repo for DIR."
|
|
|
|
(with-temp-buffer
|
|
|
|
(pb/run-process dir "svn" "info")
|
|
|
|
(goto-char (point-min))
|
|
|
|
(re-search-forward "URL: \\(.*\\)")
|
|
|
|
(match-string-no-properties 1)))
|
|
|
|
|
2012-02-09 21:34:32 +00:00
|
|
|
(defun pb/checkout-svn (name config dir)
|
2012-01-31 10:49:49 +00:00
|
|
|
"Check package NAME with config CONFIG out of svn into DIR."
|
2012-01-30 12:46:44 +00:00
|
|
|
(let ((repo (plist-get config :url)))
|
|
|
|
(with-current-buffer (get-buffer-create "*package-build-checkout*")
|
|
|
|
(goto-char (point-max))
|
|
|
|
(cond
|
2012-03-17 18:45:55 +00:00
|
|
|
((and (file-exists-p (expand-file-name ".svn" dir))
|
|
|
|
(string-equal (pb/svn-repo dir) repo))
|
2012-01-30 12:46:44 +00:00
|
|
|
(print "checkout directory exists, updating...")
|
2012-02-09 21:34:32 +00:00
|
|
|
(pb/run-process dir "svn" "up"))
|
2012-01-30 12:46:44 +00:00
|
|
|
(t
|
2012-03-17 18:39:26 +00:00
|
|
|
(when (file-exists-p dir)
|
|
|
|
(delete-directory dir t nil))
|
2012-01-30 12:46:44 +00:00
|
|
|
(print "cloning repository")
|
2012-02-09 21:34:32 +00:00
|
|
|
(pb/run-process nil "svn" "checkout" repo dir)))
|
|
|
|
(pb/run-process dir "svn" "info")
|
|
|
|
(pb/find-parse-time
|
2012-01-30 12:46:44 +00:00
|
|
|
"\\([0-9]\\{4\\}-[0-9]\\{2\\}-[0-9]\\{2\\} [0-9]\\{2\\}:[0-9]\\{2\\}:[0-9]\\{2\\}\\)"))))
|
|
|
|
|
2012-03-17 18:45:55 +00:00
|
|
|
(defun pb/git-repo (dir)
|
|
|
|
"Get the current git repo for DIR."
|
|
|
|
(with-temp-buffer
|
|
|
|
(pb/run-process dir "git" "remote" "show" "origin")
|
|
|
|
(goto-char (point-min))
|
|
|
|
(re-search-forward "Fetch URL: \\(.*\\)")
|
|
|
|
(match-string-no-properties 1)))
|
|
|
|
|
2012-02-09 21:34:32 +00:00
|
|
|
(defun pb/checkout-git (name config dir)
|
2012-01-31 10:49:49 +00:00
|
|
|
"Check package NAME with config CONFIG out of git into DIR."
|
2012-01-30 12:46:44 +00:00
|
|
|
(let ((repo (plist-get config :url))
|
|
|
|
(commit (plist-get config :commit)))
|
|
|
|
(with-current-buffer (get-buffer-create "*package-build-checkout*")
|
|
|
|
(goto-char (point-max))
|
|
|
|
(cond
|
2012-03-17 18:45:55 +00:00
|
|
|
((and (file-exists-p (expand-file-name ".git" dir))
|
|
|
|
(string-equal (pb/git-repo dir) repo))
|
2012-01-30 12:46:44 +00:00
|
|
|
(print "checkout directory exists, updating...")
|
2012-02-09 21:34:32 +00:00
|
|
|
(pb/run-process dir "git" "pull"))
|
2012-01-30 12:46:44 +00:00
|
|
|
(t
|
2012-03-17 18:39:26 +00:00
|
|
|
(when (file-exists-p dir)
|
|
|
|
(delete-directory dir t nil))
|
2012-01-30 12:46:44 +00:00
|
|
|
(print (format "cloning %s to %s" repo dir))
|
2012-02-09 21:34:32 +00:00
|
|
|
(pb/run-process nil "git" "clone" repo dir)))
|
2012-01-30 12:46:44 +00:00
|
|
|
(when commit
|
2012-02-09 21:34:32 +00:00
|
|
|
(pb/run-process dir "git" "checkout" commit))
|
|
|
|
(pb/run-process dir "git" "show" "-s" "--format='\%ci'" "HEAD")
|
|
|
|
(pb/find-parse-time
|
2012-01-30 12:46:44 +00:00
|
|
|
"\\([0-9]\\{4\\}-[0-9]\\{2\\}-[0-9]\\{2\\} [0-9]\\{2\\}:[0-9]\\{2\\}:[0-9]\\{2\\}\\)"))))
|
2011-10-05 05:49:38 +00:00
|
|
|
|
2012-04-09 19:37:45 +00:00
|
|
|
(defun pb/checkout-github (name config dir)
|
|
|
|
"Check package NAME with config CONFIG out of github into DIR."
|
|
|
|
(let* ((url (format "git://github.com/%s.git" (plist-get config :repo))))
|
|
|
|
(pb/checkout-git name (plist-put (copy-sequence config) :url url) dir)))
|
|
|
|
|
2012-04-11 11:21:57 +00:00
|
|
|
(defun pb/bzr-repo (dir)
|
|
|
|
"Get the current bzr repo for DIR."
|
|
|
|
(with-temp-buffer
|
|
|
|
(pb/run-process dir "bzr" "info")
|
|
|
|
(goto-char (point-min))
|
|
|
|
(re-search-forward "parent branch: \\(.*\\)")
|
|
|
|
(match-string-no-properties 1)))
|
|
|
|
|
|
|
|
(defun pb/checkout-bzr (name config dir)
|
|
|
|
"Check package NAME with config CONFIG out of bzr into DIR."
|
|
|
|
(let ((repo (plist-get config :url)))
|
|
|
|
(with-current-buffer (get-buffer-create "*package-build-checkout*")
|
|
|
|
(goto-char (point-max))
|
|
|
|
(cond
|
|
|
|
((and (file-exists-p (expand-file-name ".bzr" dir))
|
|
|
|
(string-equal (pb/bzr-repo dir) repo))
|
|
|
|
(print "checkout directory exists, updating...")
|
|
|
|
(pb/run-process dir "bzr" "merge"))
|
|
|
|
(t
|
|
|
|
(when (file-exists-p dir)
|
|
|
|
(delete-directory dir t nil))
|
|
|
|
(print "cloning repository")
|
|
|
|
(pb/run-process nil "bzr" "branch" repo dir)))
|
|
|
|
(pb/run-process dir "bzr" "info" "-vv")
|
|
|
|
(pb/find-parse-time
|
|
|
|
"\\([0-9]\\{4\\}-[0-9]\\{2\\}-[0-9]\\{2\\} [0-9]\\{2\\}:[0-9]\\{2\\}:[0-9]\\{2\\}\\)"))))
|
|
|
|
|
2012-04-11 11:56:29 +00:00
|
|
|
(defun pb/hg-repo (dir)
|
|
|
|
"Get the current hg repo for DIR."
|
|
|
|
(with-temp-buffer
|
|
|
|
(pb/run-process dir "hg" "paths")
|
|
|
|
(goto-char (point-min))
|
|
|
|
(re-search-forward "default = \\(.*\\)")
|
|
|
|
(match-string-no-properties 1)))
|
|
|
|
|
|
|
|
(defun pb/checkout-hg (name config dir)
|
|
|
|
"Check package NAME with config CONFIG out of hg into DIR."
|
|
|
|
(let ((repo (plist-get config :url)))
|
|
|
|
(with-current-buffer (get-buffer-create "*package-build-checkout*")
|
|
|
|
(goto-char (point-max))
|
|
|
|
(cond
|
|
|
|
((and (file-exists-p (expand-file-name ".hg" dir))
|
|
|
|
(string-equal (pb/hg-repo dir) repo))
|
|
|
|
(print "checkout directory exists, updating...")
|
|
|
|
(pb/run-process dir "hg" "pull")
|
|
|
|
(pb/run-process dir "hg" "update"))
|
|
|
|
(t
|
|
|
|
(when (file-exists-p dir)
|
|
|
|
(delete-directory dir t nil))
|
|
|
|
(print "cloning repository")
|
|
|
|
(pb/run-process nil "hg" "clone" repo dir)))
|
|
|
|
(pb/run-process dir "hg" "tip" "--style" "compact")
|
|
|
|
(pb/find-parse-time
|
|
|
|
"\\([0-9]\\{4\\}-[0-9]\\{2\\}-[0-9]\\{2\\} [0-9]\\{2\\}:[0-9]\\{2\\}\\)"))))
|
2012-04-11 11:21:57 +00:00
|
|
|
|
2012-02-09 21:34:32 +00:00
|
|
|
(defun pb/dump (data file)
|
2012-01-31 10:49:49 +00:00
|
|
|
"Write DATA to FILE as a pretty-printed Lisp sexp."
|
2012-02-11 11:42:19 +00:00
|
|
|
(write-region (concat (pp-to-string data) "\n") nil file))
|
2012-01-30 19:54:04 +00:00
|
|
|
|
2012-02-09 21:34:32 +00:00
|
|
|
(defun pb/write-pkg-file (pkg-file pkg-info)
|
2012-01-31 10:49:49 +00:00
|
|
|
"Write PKG-FILE containing PKG-INFO."
|
2012-02-09 21:34:32 +00:00
|
|
|
(pb/dump
|
2012-01-30 19:54:04 +00:00
|
|
|
`(define-package
|
|
|
|
,(aref pkg-info 0)
|
|
|
|
,(aref pkg-info 3)
|
|
|
|
,(aref pkg-info 2)
|
2012-02-02 19:20:43 +00:00
|
|
|
',(mapcar
|
2012-01-30 19:54:04 +00:00
|
|
|
(lambda (elt)
|
|
|
|
(list (car elt)
|
|
|
|
(package-version-join (cadr elt))))
|
|
|
|
(aref pkg-info 1)))
|
|
|
|
pkg-file))
|
2011-11-14 02:47:03 +00:00
|
|
|
|
2012-02-09 21:34:32 +00:00
|
|
|
(defun pb/read-from-file (file-name)
|
2012-01-31 10:49:49 +00:00
|
|
|
"Read and return the Lisp data stored in FILE-NAME, or nil if no such file exists."
|
2012-01-29 12:01:12 +00:00
|
|
|
(when (file-exists-p file-name)
|
2011-11-14 02:47:03 +00:00
|
|
|
(with-temp-buffer
|
|
|
|
(insert-file-contents-literally file-name)
|
|
|
|
(goto-char (point-min))
|
2012-01-29 12:01:12 +00:00
|
|
|
(read (current-buffer)))))
|
2011-10-05 05:49:38 +00:00
|
|
|
|
2012-02-09 21:34:32 +00:00
|
|
|
(defun pb/get-config (pkg-name)
|
2012-01-31 14:02:42 +00:00
|
|
|
"Get the configuration information for the given PKG-NAME."
|
2012-02-09 21:34:32 +00:00
|
|
|
(pb/read-from-file (format "epkgs/%s/.config" pkg-name)))
|
2011-12-03 06:40:52 +00:00
|
|
|
|
2012-02-09 21:34:32 +00:00
|
|
|
(defun pb/get-master (pkg-name)
|
2012-01-31 14:02:42 +00:00
|
|
|
"Get the configuration information for the given PKG-NAME."
|
2012-02-09 21:34:32 +00:00
|
|
|
(pb/read-from-file (format "epkgs/%s/master" pkg-name)))
|
2011-10-05 05:49:38 +00:00
|
|
|
|
|
|
|
|
2012-02-09 21:34:32 +00:00
|
|
|
(defun pb/create-tar (file dir &optional files)
|
2012-01-31 14:02:42 +00:00
|
|
|
"Create a tar FILE containing the contents of DIR, or just FILES if non-nil.
|
|
|
|
The file is written to `package-build-working-dir'."
|
2012-01-21 19:00:42 +00:00
|
|
|
(let* ((default-directory package-build-working-dir))
|
|
|
|
(apply 'process-file
|
|
|
|
"tar" nil
|
|
|
|
(get-buffer-create "*package-build-checkout*")
|
|
|
|
nil "-cvf"
|
|
|
|
file
|
|
|
|
"--exclude=.svn"
|
|
|
|
"--exclude=.git*"
|
|
|
|
"--exclude=_darcs"
|
2012-04-11 11:21:57 +00:00
|
|
|
"--exclude=.bzr"
|
2012-04-11 11:56:29 +00:00
|
|
|
"--exclude=.hg"
|
2012-02-11 16:14:30 +00:00
|
|
|
(or (mapcar (lambda (fn) (concat dir "/" fn)) files)
|
|
|
|
(list dir)))))
|
2011-10-05 05:49:38 +00:00
|
|
|
|
2012-02-09 21:34:32 +00:00
|
|
|
(defun pb/get-package-info (file-path)
|
2012-01-31 10:49:49 +00:00
|
|
|
"Get a vector of package info from the docstrings in FILE-PATH."
|
2012-01-22 18:19:04 +00:00
|
|
|
(when (file-exists-p file-path)
|
2012-01-22 05:13:19 +00:00
|
|
|
(ignore-errors
|
2012-01-22 17:51:49 +00:00
|
|
|
(save-window-excursion
|
2012-01-22 18:19:04 +00:00
|
|
|
(find-file file-path)
|
|
|
|
;; next two lines are a hack for some packages that aren't
|
|
|
|
;; commented properly.
|
|
|
|
(goto-char (point-max))
|
2012-01-29 00:16:55 +00:00
|
|
|
(insert (concat "\n;;; "
|
|
|
|
(file-name-nondirectory file-path) " ends here"))
|
2012-01-22 17:51:49 +00:00
|
|
|
(flet ((package-strip-rcs-id (str) "0"))
|
|
|
|
(package-buffer-info))))))
|
2012-01-22 05:13:19 +00:00
|
|
|
|
2012-02-09 21:34:32 +00:00
|
|
|
(defun pb/get-pkg-file-info (file-path)
|
2012-01-31 10:49:49 +00:00
|
|
|
"Get a vector of package info from \"-pkg.el\" file FILE-PATH."
|
2012-01-22 18:19:04 +00:00
|
|
|
(when (file-exists-p file-path)
|
2012-02-09 21:34:32 +00:00
|
|
|
(let ((pkgfile-info (cdr (pb/read-from-file file-path))))
|
2012-01-22 03:49:46 +00:00
|
|
|
(vector
|
|
|
|
(nth 0 pkgfile-info)
|
|
|
|
(mapcar
|
|
|
|
(lambda (elt)
|
|
|
|
(list (car elt) (version-to-list (cadr elt))))
|
|
|
|
(eval (nth 3 pkgfile-info)))
|
|
|
|
(nth 2 pkgfile-info)
|
|
|
|
(nth 1 pkgfile-info)))))
|
|
|
|
|
2012-02-09 21:34:32 +00:00
|
|
|
(defun pb/expand-file-list (dir files)
|
2012-01-31 10:49:49 +00:00
|
|
|
"In DIR, expand FILES, some of which may be shell-style wildcards."
|
2012-01-28 20:00:13 +00:00
|
|
|
(let ((default-directory dir))
|
|
|
|
(mapcan 'file-expand-wildcards files)))
|
|
|
|
|
2012-04-12 13:12:40 +00:00
|
|
|
(defun pb/merge-package-info (pkg-info name version config)
|
2012-01-31 14:23:27 +00:00
|
|
|
"Return a version of PKG-INFO updated with NAME and VERSION.
|
|
|
|
If PKG-INFO is nil, an empty one is created."
|
2012-04-11 23:10:01 +00:00
|
|
|
(let* ((merged (or (copy-seq pkg-info)
|
|
|
|
(vector name nil "No description available." version))))
|
2012-01-31 14:23:27 +00:00
|
|
|
(aset merged 0 (downcase name))
|
2012-04-12 11:52:07 +00:00
|
|
|
(aset merged 2 (format "%s [source: %s]"
|
2012-04-11 23:10:01 +00:00
|
|
|
(aref merged 2) (plist-get config :fetcher)))
|
|
|
|
(aset merged 3 version)
|
2012-02-09 21:01:39 +00:00
|
|
|
merged))
|
2012-01-31 14:23:27 +00:00
|
|
|
|
2012-02-11 11:49:02 +00:00
|
|
|
(defun pb/dump-archive-contents ()
|
|
|
|
"Dump the list of built packages back to the archive-contents file."
|
|
|
|
(pb/dump (cons 1 package-build-archive-alist)
|
|
|
|
(expand-file-name "archive-contents"
|
|
|
|
package-build-archive-dir)))
|
|
|
|
|
|
|
|
(defun pb/add-to-archive-contents (pkg-info type)
|
|
|
|
"Add the built archive with info PKG-INFO and TYPE to `package-build-archive-alist'."
|
|
|
|
(let* ((name (intern (aref pkg-info 0)))
|
|
|
|
(requires (aref pkg-info 1))
|
|
|
|
(desc (or (aref pkg-info 2) "No description available."))
|
|
|
|
(version (aref pkg-info 3))
|
|
|
|
(existing (assq name package-build-archive-alist)))
|
|
|
|
(when existing
|
|
|
|
(setq package-build-archive-alist
|
|
|
|
(delq existing package-build-archive-alist)))
|
|
|
|
(add-to-list 'package-build-archive-alist
|
|
|
|
(cons name
|
|
|
|
(vector
|
|
|
|
(version-to-list version)
|
|
|
|
requires
|
|
|
|
desc
|
|
|
|
type)))))
|
|
|
|
|
2012-04-17 11:00:31 +00:00
|
|
|
(defun pb/archive-file-name (archive-entry)
|
|
|
|
"Return the path of the file in which the package for ARCHIVE-ENTRY is stored."
|
|
|
|
(expand-file-name (format "%s-%s.%s"
|
|
|
|
(car archive-entry)
|
|
|
|
(car (aref (cdr archive-entry) 0))
|
|
|
|
(if (eq 'single (aref (cdr archive-entry) 3))
|
|
|
|
"el"
|
|
|
|
"tar"))
|
|
|
|
package-build-archive-dir))
|
|
|
|
|
|
|
|
(defun pb/remove-archive (archive-entry)
|
|
|
|
"Remove ARCHIVE-ENTRY from archive-contents, and delete associated file.
|
|
|
|
Note that the working directory (if present) is not deleted by
|
|
|
|
this function, since the archive list may contain another version
|
|
|
|
of the same-named package which is to be kept."
|
|
|
|
(message "Removing archive: %s" archive-entry)
|
|
|
|
(let ((archive-file (pb/archive-file-name archive-entry)))
|
|
|
|
(when (file-exists-p archive-file)
|
|
|
|
(delete-file archive-file)))
|
|
|
|
(setq package-build-archive-alist
|
|
|
|
(remove archive-entry package-build-archive-alist))
|
|
|
|
(pb/dump-archive-contents))
|
|
|
|
|
2012-04-06 19:49:39 +00:00
|
|
|
(defun pb/read-recipes ()
|
|
|
|
"Return a list of data structures for all recipes in `package-build-recipes-dir'."
|
|
|
|
(mapcar 'pb/read-from-file
|
|
|
|
(directory-files package-build-recipes-dir t "^[^.]")))
|
|
|
|
|
2012-02-11 11:49:02 +00:00
|
|
|
;;; Public interface
|
|
|
|
|
2011-10-05 05:49:38 +00:00
|
|
|
(defun package-build-archive (file-name)
|
2012-01-31 10:49:49 +00:00
|
|
|
"Build a package archive for package FILE-NAME."
|
2012-01-29 00:16:55 +00:00
|
|
|
(interactive (list (completing-read "Package: "
|
|
|
|
(mapc 'car package-build-alist))))
|
2012-01-21 18:04:55 +00:00
|
|
|
|
|
|
|
(let* ((name (intern file-name))
|
2012-02-11 16:12:43 +00:00
|
|
|
(cfg (or (cdr (assoc name package-build-alist))
|
|
|
|
(error "Cannot find package %s" file-name)))
|
2012-01-21 18:04:55 +00:00
|
|
|
(pkg-cwd
|
|
|
|
(file-name-as-directory
|
|
|
|
(expand-file-name file-name package-build-working-dir))))
|
|
|
|
|
2012-02-11 16:12:43 +00:00
|
|
|
(let* ((version (pb/checkout name cfg pkg-cwd))
|
2012-03-20 19:33:09 +00:00
|
|
|
(files (pb/expand-file-list pkg-cwd
|
|
|
|
(or (plist-get cfg :files)
|
|
|
|
(list "*.el"))))
|
2012-02-11 16:12:43 +00:00
|
|
|
(default-directory package-build-working-dir))
|
|
|
|
(cond
|
|
|
|
((not version)
|
|
|
|
(print (format "Unable to check out repository for %s" name)))
|
2012-03-20 19:33:09 +00:00
|
|
|
((= 1 (length files))
|
|
|
|
(let* ((pkgsrc (expand-file-name (car files) pkg-cwd))
|
2012-02-11 16:12:43 +00:00
|
|
|
(pkgdst (expand-file-name
|
|
|
|
(concat file-name "-" version ".el")
|
|
|
|
package-build-archive-dir))
|
|
|
|
(pkg-info (pb/merge-package-info
|
|
|
|
(pb/get-package-info pkgsrc)
|
|
|
|
file-name
|
2012-04-12 13:12:40 +00:00
|
|
|
version
|
|
|
|
cfg)))
|
2012-02-11 16:12:43 +00:00
|
|
|
(print pkg-info)
|
|
|
|
(when (file-exists-p pkgdst)
|
|
|
|
(delete-file pkgdst t))
|
|
|
|
(copy-file pkgsrc pkgdst)
|
|
|
|
(pb/add-to-archive-contents pkg-info 'single)))
|
|
|
|
(t
|
|
|
|
(let* ((pkg-dir (concat file-name "-" version))
|
|
|
|
(pkg-file (concat file-name "-pkg.el"))
|
|
|
|
(pkg-info
|
|
|
|
(pb/merge-package-info
|
|
|
|
(let ((default-directory pkg-cwd))
|
|
|
|
(or (pb/get-pkg-file-info pkg-file)
|
|
|
|
;; some packages (like magit) provide name-pkg.el.in
|
|
|
|
(pb/get-pkg-file-info (concat pkg-file ".in"))
|
|
|
|
(pb/get-package-info (concat file-name ".el"))))
|
2012-04-12 13:12:40 +00:00
|
|
|
file-name
|
|
|
|
version
|
|
|
|
cfg)))
|
2012-02-11 16:12:43 +00:00
|
|
|
|
|
|
|
(print pkg-info)
|
|
|
|
(copy-directory file-name pkg-dir)
|
|
|
|
|
|
|
|
(pb/write-pkg-file (expand-file-name
|
|
|
|
pkg-file
|
|
|
|
(file-name-as-directory
|
|
|
|
(expand-file-name
|
|
|
|
pkg-dir
|
|
|
|
package-build-working-dir)))
|
|
|
|
pkg-info)
|
|
|
|
|
|
|
|
(when files
|
|
|
|
(add-to-list 'files pkg-file))
|
|
|
|
|
|
|
|
(pb/create-tar
|
|
|
|
(expand-file-name
|
|
|
|
(concat file-name "-" version ".tar") package-build-archive-dir)
|
|
|
|
pkg-dir
|
|
|
|
files)
|
|
|
|
|
|
|
|
(delete-directory pkg-dir t nil)
|
|
|
|
(pb/add-to-archive-contents pkg-info 'tar))))
|
|
|
|
(pb/dump-archive-contents))))
|
2012-01-21 18:04:55 +00:00
|
|
|
|
2012-04-17 09:42:51 +00:00
|
|
|
(defun package-build-archive-ignore-errors (pkg)
|
|
|
|
"Build archive for package PKG, ignoring any errors."
|
2012-02-11 11:49:02 +00:00
|
|
|
(interactive)
|
2012-04-17 09:42:51 +00:00
|
|
|
(ignore-errors (package-build-archive pkg)))
|
2012-03-17 17:39:44 +00:00
|
|
|
|
2012-02-11 11:49:02 +00:00
|
|
|
(defun package-build-all ()
|
|
|
|
"Build all packages in the `package-build-alist'."
|
|
|
|
(interactive)
|
2012-04-17 09:42:51 +00:00
|
|
|
(mapc 'package-build-archive-ignore-errors
|
2012-04-17 11:00:31 +00:00
|
|
|
(mapcar 'symbol-name (mapcar 'car package-build-alist)))
|
|
|
|
(package-build-cleanup))
|
|
|
|
|
|
|
|
(defun package-build-cleanup ()
|
|
|
|
"Remove previously-built packages that no longer have recipes."
|
|
|
|
(interactive)
|
|
|
|
(let* ((known-package-names (mapcar 'car package-build-alist))
|
|
|
|
(stale-archives (loop for built in package-build-archive-alist
|
|
|
|
when (not (memq (car built) known-package-names))
|
|
|
|
collect built)))
|
|
|
|
(dolist (stale stale-archives)
|
|
|
|
(pb/remove-archive stale))))
|
2012-01-31 10:49:49 +00:00
|
|
|
|
2012-02-03 14:46:55 +00:00
|
|
|
(defun package-build-initialize ()
|
2012-04-06 19:49:39 +00:00
|
|
|
"Load the recipe and archive-contents files."
|
2012-02-03 14:46:55 +00:00
|
|
|
(interactive)
|
|
|
|
(setq
|
2012-04-06 19:49:39 +00:00
|
|
|
package-build-alist (pb/read-recipes)
|
2012-02-09 21:34:32 +00:00
|
|
|
package-build-archive-alist (cdr (pb/read-from-file
|
2012-02-03 14:46:55 +00:00
|
|
|
(expand-file-name "archive-contents"
|
|
|
|
package-build-archive-dir)))))
|
|
|
|
|
|
|
|
|
|
|
|
(package-build-initialize)
|
|
|
|
|
2012-02-11 16:17:24 +00:00
|
|
|
(provide 'package-build)
|
2012-01-31 10:49:49 +00:00
|
|
|
;;; package-build.el ends here
|