all messages for Guix-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
From: 宋文武 <iyzsong@gmail.com>
To: guix-devel@gnu.org
Cc: 宋文武 <iyzsong@gmail.com>
Subject: [PATCH 3/3] gnu-maintenance: update-package-source: Only update the desired package.
Date: Wed,  6 Apr 2016 18:37:26 +0800	[thread overview]
Message-ID: <1459939046-10573-3-git-send-email-iyzsong@gmail.com> (raw)
In-Reply-To: <1459939046-10573-1-git-send-email-iyzsong@gmail.com>

Fixes <http://bugs.gnu.org/22693>.
Suggested by Andy Wingo.

* guix/upstream.scm (update-package-source): Rewrite in terms of 'edit-expression'.
---
 guix/upstream.scm | 68 +++++++++++++++++++------------------------------------
 1 file changed, 23 insertions(+), 45 deletions(-)

diff --git a/guix/upstream.scm b/guix/upstream.scm
index cea23fe..02c50c0 100644
--- a/guix/upstream.scm
+++ b/guix/upstream.scm
@@ -22,8 +22,6 @@
   #:use-module (guix utils)
   #:use-module ((guix download)
                 #:select (download-to-store))
-  #:use-module ((guix build utils)
-                #:select (substitute))
   #:use-module (guix gnupg)
   #:use-module (guix packages)
   #:use-module (guix ui)
@@ -205,52 +203,32 @@ and 'interactive' (default)."
   "Modify the source file that defines PACKAGE to refer to VERSION,
 whose tarball has SHA256 HASH (a bytevector).  Return the new version string
 if an update was made, and #f otherwise."
-  (define (new-line line matches replacement)
-    ;; Iterate over MATCHES and return the modified line based on LINE.
-    ;; Replace each match with REPLACEMENT.
-    (let loop ((m* matches)                       ; matches
-               (o  0)                             ; offset in L
-               (r  '()))                          ; result
-      (match m*
-        (()
-         (let ((r (cons (substring line o) r)))
-           (string-concatenate-reverse r)))
-        ((m . rest)
-         (loop rest
-               (match:end m)
-               (cons* replacement
-                      (substring line o (match:start m))
-                      r))))))
-
-  (define (update-source file old-version version
-                         old-hash hash)
-    ;; Update source file FILE, replacing occurrences OLD-VERSION by VERSION
-    ;; and occurrences of OLD-HASH by HASH (base32 representation thereof).
-
-    ;; TODO: Currently this is a bit of a sledgehammer: if VERSION occurs in
-    ;; different unrelated places, we may modify it more than needed, for
-    ;; instance.  We should try to make changes only within the sexp that
-    ;; corresponds to the definition of PACKAGE.
+  (define (update-expression expr old-version version old-hash hash)
+    ;; Update package expression EXPR, replacing occurrences OLD-VERSION by
+    ;; VERSION and occurrences of OLD-HASH by HASH (base32 representation
+    ;; thereof).
     (let ((old-hash (bytevector->nix-base32-string old-hash))
           (hash     (bytevector->nix-base32-string hash)))
-      (substitute file
-                  `((,(regexp-quote old-version)
-                     . ,(cut new-line <> <> version))
-                    (,(regexp-quote old-hash)
-                     . ,(cut new-line <> <> hash))))
-      version))
-
-  (let ((name (package-name package))
-        (loc  (package-field-location package 'version)))
-    (if loc
-        (let ((old-version (package-version package))
-              (old-hash    (origin-sha256 (package-source package)))
-              (file        (and=> (location-file loc)
-                                  (cut search-path %load-path <>))))
+      (string-replace-substring
+       (string-replace-substring expr old-hash hash)
+       old-version version)))
+
+  (let ((name        (package-name package))
+        (version-loc (package-field-location package 'version)))
+    (if version-loc
+        (let* ((loc         (package-location package))
+               (old-version (package-version package))
+               (old-hash    (origin-sha256 (package-source package)))
+               (file        (and=> (location-file loc)
+                                   (cut search-path %load-path <>))))
           (if file
-              (update-source file
-                             old-version version
-                             old-hash hash)
+              (and (edit-expression
+                    ;; Be sure to use absolute filename.
+                    (assq-set! (location->source-properties loc)
+                               'filename file)
+                    (cut update-expression <>
+                         old-version version old-hash hash))
+                   version)
               (begin
                 (warning (_ "~a: could not locate source file")
                          (location-file loc))
-- 
2.6.3

  parent reply	other threads:[~2016-04-06 10:39 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2016-04-06 10:37 [PATCH 1/3] utils: Add 'edit-expression' 宋文武
2016-04-06 10:37 ` [PATCH 2/3] utils: Add 'location->source-properties' 宋文武
2016-04-06 10:37 ` 宋文武 [this message]
2016-04-06 12:50 ` [PATCH 1/3] utils: Add 'edit-expression' Andy Wingo
2016-04-09  6:12   ` [PATCH][UPDATE] " 宋文武

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1459939046-10573-3-git-send-email-iyzsong@gmail.com \
    --to=iyzsong@gmail.com \
    --cc=guix-devel@gnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this external index

	https://git.savannah.gnu.org/cgit/guix.git

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.