From patchwork Thu May 18 15:16:16 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: =?utf-8?q?Ludovic_Court=C3=A8s?= X-Patchwork-Id: 50109 Return-Path: X-Original-To: patchwork@mira.cbaines.net Delivered-To: patchwork@mira.cbaines.net Received: by mira.cbaines.net (Postfix, from userid 113) id B4AA917A9A; Thu, 18 May 2023 16:17:33 +0100 (BST) X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on mira.cbaines.net X-Spam-Level: X-Spam-Status: No, score=-3.7 required=5.0 tests=BAYES_00,DKIM_INVALID, DKIM_SIGNED,MAILING_LIST_MULTI,RCVD_IN_MSPIKE_H2,SPF_HELO_PASS, URIBL_BLOCKED autolearn=unavailable autolearn_force=no version=3.4.6 Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mira.cbaines.net (Postfix) with ESMTPS id 9C36C17A88 for ; Thu, 18 May 2023 16:17:32 +0100 (BST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1pzfNY-0003Zv-Vz; Thu, 18 May 2023 11:17:21 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1pzfNO-0003KT-1l for guix-patches@gnu.org; Thu, 18 May 2023 11:17:11 -0400 Received: from debbugs.gnu.org ([209.51.188.43]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1pzfNK-0001yi-Ce; Thu, 18 May 2023 11:17:07 -0400 Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1pzfNI-0005UE-Dr; Thu, 18 May 2023 11:17:04 -0400 X-Loop: help-debbugs@gnu.org Subject: [bug#63571] [PATCH 08/14] upstream: 'update-package-source' edits input fields. Resent-From: Ludovic =?utf-8?q?Court=C3=A8s?= Original-Sender: "Debbugs-submit" Resent-CC: mail@cbaines.net, dev@jpoiret.xyz, ludo@gnu.org, othacehe@gnu.org, rekado@elephly.net, zimon.toutoune@gmail.com, me@tobias.gr, guix-patches@gnu.org Resent-Date: Thu, 18 May 2023 15:17:04 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: followup 63571 X-GNU-PR-Package: guix-patches X-GNU-PR-Keywords: patch To: 63571@debbugs.gnu.org Cc: Ludovic =?utf-8?q?Court=C3=A8s?= , Christopher Baines , Josselin Poiret , Ludovic =?utf-8?q?Court=C3=A8s?= , Mathieu Othacehe , Ricardo Wurmus , Simon Tournier , Tobias Geerinckx-Rice X-Debbugs-Original-Xcc: Christopher Baines , Josselin Poiret , Ludovic =?utf-8?q?Court=C3=A8s?= , Mathieu Othacehe , Ricardo Wurmus , Simon Tournier , Tobias Geerinckx-Rice Received: via spool by 63571-submit@debbugs.gnu.org id=B63571.168442301521011 (code B ref 63571); Thu, 18 May 2023 15:17:04 +0000 Received: (at 63571) by debbugs.gnu.org; 18 May 2023 15:16:55 +0000 Received: from localhost ([127.0.0.1]:54126 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1pzfN8-0005Si-HJ for submit@debbugs.gnu.org; Thu, 18 May 2023 11:16:55 -0400 Received: from eggs.gnu.org ([209.51.188.92]:55662) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1pzfMz-0005QZ-6V for 63571@debbugs.gnu.org; Thu, 18 May 2023 11:16:46 -0400 Received: from fencepost.gnu.org ([2001:470:142:3::e]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1pzfMu-0001vb-0L; Thu, 18 May 2023 11:16:40 -0400 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=gnu.org; s=fencepost-gnu-org; h=MIME-Version:References:In-Reply-To:Date:Subject:To: From; bh=TLXn+Xhl7b/LOtknN2RpptC2J87JZBjB6dlRrdQOwCA=; b=FMIRVETiBImcQWobl/FH IF6Os8NexHlQPf7iLNO1Iy6bOceE8P0neqPR58fhcefBmQKI5CLtkp5uGXXA6zpX3uC9xuSIsGn99 tnleKNuEsDImGUy7gT5VoEaQxoTSjg9a37o8R2xogGJwmP0jHtkWhKzVlZBC0H38NDWAWfdRoPSQD hDEG4/m4i9RWQkfFUVXSwFCw7AenWZifn0CIFLvzCohuJzZzep/W4i9tVEt+lbYiiOuairbBLPKva 1dAsy/zEOpccj/Fnb/QonwtEPaWfDEsdt25tHzH853bqvrK2sswQwaTUsDDZdV30aYOEZjpLHR0Fk InTfrs032OUErg==; Received: from 91-160-117-201.subs.proxad.net ([91.160.117.201] helo=gnu.org) by fencepost.gnu.org with esmtpsa (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1pzfMt-0007G6-K2; Thu, 18 May 2023 11:16:39 -0400 From: Ludovic =?utf-8?q?Court=C3=A8s?= Date: Thu, 18 May 2023 17:16:16 +0200 Message-Id: X-Mailer: git-send-email 2.40.1 In-Reply-To: References: MIME-Version: 1.0 X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list X-BeenThere: guix-patches@gnu.org List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: guix-patches-bounces+patchwork=mira.cbaines.net@gnu.org Sender: guix-patches-bounces+patchwork=mira.cbaines.net@gnu.org X-getmail-retrieved-from-mailbox: Patches Previously, 'guix refresh r-ggplot2 -u' and similar commands would print of list of input changes that would have to be made manually. With this change, 'guix refresh -u' takes care of updating input fields automatically. * guix/upstream.scm (update-package-inputs): New procedure. (update-package-source): Call it when 'upstream-source-inputs' returns true. * guix/scripts/refresh.scm (update-package): Remove iteration over the result of 'changed-inputs'. * guix/import/test.scm (available-updates): Add support for input lists. * tests/guix-refresh.sh (GUIX_TEST_UPDATER_TARGETS): Add input list for "the-test-package". Make sure 'guix refresh -u' updates 'inputs' accordingly. --- guix/import/test.scm | 13 +++++++++- guix/scripts/refresh.scm | 36 -------------------------- guix/upstream.scm | 56 +++++++++++++++++++++++++++++++++++++--- tests/guix-refresh.sh | 7 +++-- 4 files changed, 69 insertions(+), 43 deletions(-) diff --git a/guix/import/test.scm b/guix/import/test.scm index b1ed0b455d..4bd356bddc 100644 --- a/guix/import/test.scm +++ b/guix/import/test.scm @@ -52,7 +52,18 @@ (define (available-updates package) (upstream-source (package (package-name package)) (version version) - (urls (list url))))) + (urls (list url)))) + ((version url (inputs ...)) + (upstream-source + (package (package-name package)) + (version version) + (urls (list url)) + (inputs + (map (lambda (name) + (upstream-input + (name name) + (downstream-name name))) + inputs))))) updates) result) result)))) diff --git a/guix/scripts/refresh.scm b/guix/scripts/refresh.scm index e9e3eda9eb..7d74729a88 100644 --- a/guix/scripts/refresh.scm +++ b/guix/scripts/refresh.scm @@ -366,42 +366,6 @@ (define* (update-package store package version updaters (G_ "~a: updating from version ~a to version ~a...~%") (package-name package) (package-version package) version) - (for-each - (lambda (change) - (define field - (match (upstream-input-change-type change) - ('native 'native-inputs) - ('propagated 'propagated-inputs) - (_ 'inputs))) - - (define name - (package-name package)) - (define loc - (package-field-location package field)) - (define change-name - (upstream-input-change-name change)) - - (match (list (upstream-input-change-action change) - (upstream-input-change-type change)) - (('add 'regular) - (info loc (G_ "~a: consider adding this input: ~a~%") - name change-name)) - (('add 'native) - (info loc (G_ "~a: consider adding this native input: ~a~%") - name change-name)) - (('add 'propagated) - (info loc (G_ "~a: consider adding this propagated input: ~a~%") - name change-name)) - (('remove 'regular) - (info loc (G_ "~a: consider removing this input: ~a~%") - name change-name)) - (('remove 'native) - (info loc (G_ "~a: consider removing this native input: ~a~%") - name change-name)) - (('remove 'propagated) - (info loc (G_ "~a: consider removing this propagated input: ~a~%") - name change-name)))) - (changed-inputs package source)) (let ((hash (file-hash* output))) (update-package-source package source hash))) (warning (G_ "~a: version ~a could not be \ diff --git a/guix/upstream.scm b/guix/upstream.scm index 29dd923e63..1a90a342ff 100644 --- a/guix/upstream.scm +++ b/guix/upstream.scm @@ -38,6 +38,7 @@ (define-module (guix upstream) #:use-module (guix hash) #:use-module (guix store) #:use-module ((guix derivations) #:select (built-derivations derivation->output-path)) + #:autoload (guix read-print) (object->string*) #:autoload (gcrypt hash) (port-sha256) #:use-module (guix monads) #:use-module (srfi srfi-1) @@ -576,6 +577,52 @@ (define* (package-update store package (package-name package))) (values #f #f #f)))) +(define (update-package-inputs package source) + "Update the input fields of the definition of PACKAGE according to those +specified in SOURCE, an ." + (define (update-field field source-inputs package-inputs) + (define loc + (package-field-location package field)) + + (define new + (map (compose string->symbol upstream-input-downstream-name) + (source-inputs source))) + + (define old + (match (package-inputs package) + (((labels (? package? packages)) ...) + labels) + (_ + '()))) + + (define unchanged? + (equal? new old)) + + (if (and loc (not unchanged?)) + (edit-expression (location->source-properties + (absolute-location loc)) + (lambda (str) + (object->string* `(list ,@new) + (location-column loc)))) + (unless unchanged? + ;; XXX: Bail out when FIELD isn't already present in the source. + ;; TODO: Add the field if it's missing. + (warning (package-location package) + (G_ "~a: '~a' field not found; leaving it unchanged~%") + (package-name package) field) + (warning (package-location package) + (G_ "~a: expected '~a' value: ~s~%") + (package-name package) field new)))) + + (for-each update-field + '(inputs native-inputs propagated-inputs) + (list upstream-source-regular-inputs + upstream-source-native-inputs + upstream-source-propagated-inputs) + (list package-inputs + package-native-inputs + package-propagated-inputs))) + (define* (update-package-source package source hash) "Modify the source file that defines PACKAGE to refer to SOURCE, an whose tarball has SHA256 HASH (a bytevector). Return the @@ -630,9 +677,7 @@ (define* (update-package-source package source hash) ;; function of the person who uploads the package. Note that ;; package definitions usually concatenate fragments of the URL, ;; which is why we only attempt to replace a subset of the URL. - (let ((properties (location->source-properties - (absolute-location loc))) - (replacements `((,old-version . ,version) + (let ((replacements `((,old-version . ,version) (,old-hash . ,hash) ,@(if (and old-commit new-commit) `((,old-commit . ,new-commit)) @@ -641,8 +686,11 @@ (define* (update-package-source package source hash) `((,(dirname old-url) . ,(dirname new-url))) '())))) - (and (edit-expression properties + (and (edit-expression (location->source-properties + (absolute-location loc)) (cut update-expression <> replacements)) + (or (not (upstream-source-inputs source)) + (update-package-inputs package source)) version)) (begin (warning (G_ "~a: could not locate source file") diff --git a/tests/guix-refresh.sh b/tests/guix-refresh.sh index 691020b031..9d7a57a36e 100644 --- a/tests/guix-refresh.sh +++ b/tests/guix-refresh.sh @@ -34,7 +34,8 @@ GUIX_TEST_UPDATER_TARGETS=' ("1.6.4" "file:///dev/null"))) ("libreoffice" "" (("1.0" "file:///dev/null"))) ("idutils" "" (("'$idutils_version'" "file:///dev/null"))) - ("the-test-package" "" (("5.5" "file://'$PWD/$module_dir'/source"))))' + ("the-test-package" "" (("5.5" "file://'$PWD/$module_dir'/source" + ("grep" "sed")))))' # No newer version available. guix refresh -t test idutils # XXX: should return non-zero? @@ -91,13 +92,15 @@ cat > "$module_dir/sample.scm"<