From 2ffb028ccd9efe217187a4fcb0a1b7f013d3e795 Mon Sep 17 00:00:00 2001 From: Steve Purcell Date: Wed, 22 Oct 2014 18:58:36 +0100 Subject: [PATCH] Extract code for single and multi-file package builds into helper fns --- package-build.el | 149 ++++++++++++++++++++++++----------------------- 1 file changed, 76 insertions(+), 73 deletions(-) diff --git a/package-build.el b/package-build.el index 2ccbf987..c4e82864 100644 --- a/package-build.el +++ b/package-build.el @@ -1029,82 +1029,85 @@ Returns the archive entry for the package." ((not version) (error "Unable to check out repository for %s" package-name)) ((= 1 (length files)) - (let* ((pkg-source (expand-file-name (caar files) source-dir)) - (pkg-target (expand-file-name - (concat package-name "-" version ".el") - target-dir)) - (pkg-info (pb/merge-package-info - (pb/get-package-info pkg-source) - package-name - version))) - (unless (string-equal (downcase (concat package-name ".el")) - (downcase (file-name-nondirectory pkg-source))) - (error "Single file %s does not match package name %s" - (file-name-nondirectory pkg-source) package-name)) - (when (file-exists-p pkg-target) - (delete-file pkg-target)) - (copy-file pkg-source pkg-target) - (let ((enable-local-variables nil) - (make-backup-files nil)) - (with-current-buffer (find-file pkg-target) - (pb/update-or-insert-version version) - (pb/ensure-ends-here-line pkg-source) - (write-file pkg-target nil) - (condition-case err - (pb/package-buffer-info-vec) - (error - (pb/message "Warning: %S" err))) - (kill-buffer))) - - (pb/write-pkg-readme target-dir - (pb/find-package-commentary pkg-source) - package-name) - (pb/archive-entry pkg-info 'single))) + (pb/build-single-file-package package-name version (caar files) source-dir target-dir)) ((< 1 (length files)) - (let* ((tmp-dir (file-name-as-directory (make-temp-file package-name t))) - (pkg-dir-name (concat package-name "-" version)) - (pkg-tmp-dir (expand-file-name pkg-dir-name tmp-dir)) - (pkg-file (concat package-name "-pkg.el")) - (pkg-file-source (or (pb/find-source-file pkg-file files) - pkg-file)) - (file-source (concat package-name ".el")) - (pkg-source (or (pb/find-source-file file-source files) - file-source)) - (pkg-info (pb/merge-package-info - (let ((default-directory source-dir)) - (or (pb/get-pkg-file-info pkg-file-source) - ;; some packages (like magit) provide name-pkg.el.in - (pb/get-pkg-file-info - (expand-file-name (concat pkg-file ".in") - (file-name-directory pkg-source))) - (pb/get-package-info pkg-source))) - package-name - version))) - - - (pb/copy-package-files files source-dir pkg-tmp-dir) - (pb/write-pkg-file (expand-file-name pkg-file - (file-name-as-directory pkg-tmp-dir)) - pkg-info) - - (pb/generate-info-files files source-dir pkg-tmp-dir) - (pb/generate-dir-file files pkg-tmp-dir) - - (let ((default-directory tmp-dir)) - (pb/create-tar (expand-file-name (concat package-name "-" version ".tar") - target-dir) - pkg-dir-name)) - - (let ((default-directory source-dir)) - (pb/write-pkg-readme target-dir - (pb/find-package-commentary pkg-source) - package-name)) - - (delete-directory pkg-tmp-dir t nil) - (pb/archive-entry pkg-info 'tar))) - + (pb/build-multi-file-package package-name version files source-dir target-dir)) (t (error "Unable to find files matching recipe patterns"))))) +(defun pb/build-single-file-package (package-name version file source-dir target-dir) + (let* ((pkg-source (expand-file-name file source-dir)) + (pkg-target (expand-file-name + (concat package-name "-" version ".el") + target-dir)) + (pkg-info (pb/merge-package-info + (pb/get-package-info pkg-source) + package-name + version))) + (unless (string-equal (downcase (concat package-name ".el")) + (downcase (file-name-nondirectory pkg-source))) + (error "Single file %s does not match package name %s" + (file-name-nondirectory pkg-source) package-name)) + (when (file-exists-p pkg-target) + (delete-file pkg-target)) + (copy-file pkg-source pkg-target) + (let ((enable-local-variables nil) + (make-backup-files nil)) + (with-current-buffer (find-file pkg-target) + (pb/update-or-insert-version version) + (pb/ensure-ends-here-line pkg-source) + (write-file pkg-target nil) + (condition-case err + (pb/package-buffer-info-vec) + (error + (pb/message "Warning: %S" err))) + (kill-buffer))) + + (pb/write-pkg-readme target-dir + (pb/find-package-commentary pkg-source) + package-name) + (pb/archive-entry pkg-info 'single))) + +(defun pb/build-multi-file-package (package-name version files source-dir target-dir) + (let* ((tmp-dir (file-name-as-directory (make-temp-file package-name t))) + (pkg-dir-name (concat package-name "-" version)) + (pkg-tmp-dir (expand-file-name pkg-dir-name tmp-dir)) + (pkg-file (concat package-name "-pkg.el")) + (pkg-file-source (or (pb/find-source-file pkg-file files) + pkg-file)) + (file-source (concat package-name ".el")) + (pkg-source (or (pb/find-source-file file-source files) + file-source)) + (pkg-info (pb/merge-package-info + (let ((default-directory source-dir)) + (or (pb/get-pkg-file-info pkg-file-source) + ;; some packages (like magit) provide name-pkg.el.in + (pb/get-pkg-file-info + (expand-file-name (concat pkg-file ".in") + (file-name-directory pkg-source))) + (pb/get-package-info pkg-source))) + package-name + version))) + (pb/copy-package-files files source-dir pkg-tmp-dir) + (pb/write-pkg-file (expand-file-name pkg-file + (file-name-as-directory pkg-tmp-dir)) + pkg-info) + + (pb/generate-info-files files source-dir pkg-tmp-dir) + (pb/generate-dir-file files pkg-tmp-dir) + + (let ((default-directory tmp-dir)) + (pb/create-tar (expand-file-name (concat package-name "-" version ".tar") + target-dir) + pkg-dir-name)) + + (let ((default-directory source-dir)) + (pb/write-pkg-readme target-dir + (pb/find-package-commentary pkg-source) + package-name)) + + (delete-directory pkg-tmp-dir t nil) + (pb/archive-entry pkg-info 'tar))) + ;; In future we should provide a hook, and perform this step in a separate package. ;; Note also that it would be straightforward to generate the SVG ourselves, which would