Subject: Re: bug#15108: [Patch] Updated package dependencies

From: Tom Willemse <[email-masked]>
Date: Thu, 12 Dec 2013 20:23:58 +0100

Stefan Monnier <[email-masked]> writes:

>> I've tested it most recently bzr trunk revision 115470. All the ways to
>> specify dependencies work as described before:
>
> Looks good, just one nitpick:
>
>> ;; Package-Requires: foo
>> ;; Package-Requires: (foo bar)
>> ;; Package-Requires: (foo (baz "1.1.0") bar)
>> ;; Package-Requires: (baz "1.1.0")
>
> Please don't support the first form nor the last form, since it
> otherwise gives the impression that
>
>    ;; Package-Requires: foo bar baz
> or
>    ;; Package-Requires: (foo "0.1") (bar "2.0")
>
> will also work and we don't want to go that way.

Taken care of in attached patch. I was unsure of how to deal with these
situations, so I explicitly signal a (hopefully) clear error. Just
letting it crash on trying to get the cdr of a symbol seemed messy.
Please let me know what you think.

=== modified file 'lisp/emacs-lisp/package.el'
*** lisp/emacs-lisp/package.el	2013-12-11 21:15:12 +0000
--- lisp/emacs-lisp/package.el	2013-12-12 19:13:00 +0000
***************
*** 1104,1109 ****
--- 1104,1128 ----

  (declare-function lm-homepage "lisp-mnt" (&optional file))

+ (defun package--prepare-dependencies (deps)
+   "Turn DEPS into an acceptable list of dependencies.
+
+ Any parts missing a version string get a default version string
+ of \"0\" (meaning any version) and an appropriate level of lists
+ is wrapped around any parts requiring it."
+   (cond
+    ((null deps) nil)
+    ((or (symbolp deps)
+         (and (listp deps)
+              (symbolp (car deps))
+              (stringp (cadr deps))))
+     (error "Invalid requirement specifier: %s" deps))
+    ((stringp (cadr deps)) `(,deps))
+    ((and (listp deps) (listp (car deps))
+          (null (cdar deps)))
+     `((,(caar deps) "0")))
+    (t (mapcar (lambda (dep) (if (symbolp dep) `(,dep "0") dep)) deps))))
+
  (defun package-buffer-info ()
    "Return a `package-desc' describing the package in the current buffer.

***************
*** 1135,1141 ****
  	 "Package lacks a \"Version\" or \"Package-Version\" header"))
        (package-desc-from-define
         file-name pkg-version desc
!        (if requires-str (package-read-from-string requires-str))
         :kind 'single
         :url homepage))))

--- 1154,1162 ----
  	 "Package lacks a \"Version\" or \"Package-Version\" header"))
        (package-desc-from-define
         file-name pkg-version desc
!        (if requires-str
!            (package--prepare-dependencies
!             (package-read-from-string requires-str)))
         :kind 'single
         :url homepage))))