From patchwork Sun Jan 9 19:10:12 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: M X-Patchwork-Id: 36195 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 96E2627BBEA; Sun, 9 Jan 2022 19:13:11 +0000 (GMT) X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on mira.cbaines.net X-Spam-Level: X-Spam-Status: No, score=-2.7 required=5.0 tests=BAYES_00,DKIM_INVALID, DKIM_SIGNED,FREEMAIL_FROM,MAILING_LIST_MULTI,RCVD_IN_MSPIKE_H3, RCVD_IN_MSPIKE_WL,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 E042527BBE9 for ; Sun, 9 Jan 2022 19:13:10 +0000 (GMT) Received: from localhost ([::1]:42256 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1n6dcs-0003w5-3p for patchwork@mira.cbaines.net; Sun, 09 Jan 2022 14:13:10 -0500 Received: from eggs.gnu.org ([209.51.188.92]:54334) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1n6dar-0001av-8C for guix-patches@gnu.org; Sun, 09 Jan 2022 14:11:06 -0500 Received: from debbugs.gnu.org ([209.51.188.43]:58437) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1n6dar-000693-05 for guix-patches@gnu.org; Sun, 09 Jan 2022 14:11:05 -0500 Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1n6daq-0007mq-Rn for guix-patches@gnu.org; Sun, 09 Jan 2022 14:11:04 -0500 X-Loop: help-debbugs@gnu.org Subject: [bug#53144] [PATCH 10/13] upstream: Support incrementing the revision of 'git-version'. Resent-From: Maxime Devos Original-Sender: "Debbugs-submit" Resent-CC: guix-patches@gnu.org Resent-Date: Sun, 09 Jan 2022 19:11:04 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: followup 53144 X-GNU-PR-Package: guix-patches X-GNU-PR-Keywords: patch To: 53144@debbugs.gnu.org Cc: Maxime Devos Received: via spool by 53144-submit@debbugs.gnu.org id=B53144.164175543329812 (code B ref 53144); Sun, 09 Jan 2022 19:11:04 +0000 Received: (at 53144) by debbugs.gnu.org; 9 Jan 2022 19:10:33 +0000 Received: from localhost ([127.0.0.1]:51324 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1n6daK-0007kk-Cd for submit@debbugs.gnu.org; Sun, 09 Jan 2022 14:10:32 -0500 Received: from xavier.telenet-ops.be ([195.130.132.52]:49162) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1n6daA-0007iS-BC for 53144@debbugs.gnu.org; Sun, 09 Jan 2022 14:10:24 -0500 Received: from localhost.localdomain ([188.188.180.65]) by xavier.telenet-ops.be with bizsmtp id gjAG2600J1R3YAc01jAMsP; Sun, 09 Jan 2022 20:10:22 +0100 From: Maxime Devos Date: Sun, 9 Jan 2022 19:10:12 +0000 Message-Id: <20220109191015.33058-10-maximedevos@telenet.be> X-Mailer: git-send-email 2.34.0 In-Reply-To: <20220109191015.33058-1-maximedevos@telenet.be> References: <20220109191015.33058-1-maximedevos@telenet.be> MIME-Version: 1.0 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=telenet.be; s=r22; t=1641755422; bh=v1TrHB2SStczDDlPbBh4hKVcK72fHybe/vEEVbeutjk=; h=From:To:Cc:Subject:Date:In-Reply-To:References; b=Ppx3QnbhxysRsjkl5xpd4ULQrxSurSlyiwZiMysW7ZmE5cxN6QsMqlBn6R2d+AlTO 0iNxR45adqn0UNpv71uP/T17obMtXA3XosMq1YefpKrAzYrgd0hMEFPez173yEn5/Y AshmW1P1REYgbML9QTHMLNwBQPDk7o2zTkt4DxE1nA3GvXMu5v4YCvcXFKnPtAvnKY WZyVBMGzmcY6YZEecRhRcwVpx2vnpOnuovc1/Upxy91LSQ4pRbDTDHX2ZhnR1TglCG YtmnS5yKZN4jKKogLdHBsvdhnQsokb0QctPNR3E0EYhXNnUCPD4jNuzjLMMQHwMRUj KcnvzjdVM3NNw== 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" X-getmail-retrieved-from-mailbox: Patches This is currently pointless, because no updater returns such versions. A future patch will introduce an updater returning such versions. * guix/upstream.scm (git-version-regexp): New variable. (maybe-git-version, maybe-git-version->revision) (maybe-git-versions->revision-replacements): New procedures. (update-package-source): Use 'package-definition-location' instead of 'package-location'. Also replace the revision. --- guix/upstream.scm | 61 +++++++++++++++++++++++++++++++++++++++++++++- tests/upstream.scm | 37 ++++++++++++++++++++++++++++ 2 files changed, 97 insertions(+), 1 deletion(-) diff --git a/guix/upstream.scm b/guix/upstream.scm index 6666803a92..6b65147356 100644 --- a/guix/upstream.scm +++ b/guix/upstream.scm @@ -61,6 +61,10 @@ (define-module (guix upstream) url-prefix-predicate coalesce-sources + decompose-git-version + maybe-git-version->revision + maybe-git-versions->revision-replacements ; for tests + upstream-updater upstream-updater? upstream-updater-name @@ -230,6 +234,55 @@ (define (release>? r1 r2) (sort sources release>?))) + + +;;; +;;; Manipulating results of 'git-version'. +;;; TODO: also supporting Mercurial ('hg-version') would be nice. +;;; + +;; A regexp matching versions constructed by 'git-version'. +(define git-version-regexp + (delay (make-regexp "^(.+)-([0123456789]+).([0123456789abcdefg]{7})$"))) + +(define (decompose-git-version git-version-string) + "Split the version string GIT-VERSION-STRING constructed by 'git-version' +in three parts: the version it was based on, the revision (as a string) +and the abbreviated commit. If GIT-VERSION-STRING does not correspond +to a result of 'git-version', return #false (three times) instead." + (define m (regexp-exec (force git-version-regexp) git-version-string)) + (if m + (values (match:substring m 1) + (match:substring m 2) + (match:substring m 3)) + (values #false #false #false))) + +(define (maybe-git-version->revision maybe-git-version) ; string | #false + "If the string MAYBE-GIT-VERSION appears to be the result of a call to +'git-version', return the revision (as a string). Otherwise, return #false." + (let-values (((version-base revision abbreviated-commit) + (decompose-git-version maybe-git-version))) + revision)) + +(define (maybe-git-versions->revision-replacements old new) + "If the two strings OLD and NEW appear to be the result of a call +to 'git-version', return a list of replacements as expected by +'update-expression' in 'update-package-source' for updating the revision. +Otherwise, return the empty list." + (let* ((old-revision (maybe-git-version->revision old)) + (new-revision (maybe-git-version->revision new))) + (if (and old-revision new-revision) + ;; Simply returning ((old-revision . new-revision)) would work. + ;; However, revision numbers are usually quite small, + ;; e.g. "0" or "1", so that would have a high risk of replacing + ;; something unrelated. Instead, target the (revision ...) form + ;; in (let ((commit ...) (revision ...)) (package ...)). + `((,(object->string `(revision ,old-revision)) + . ,(object->string `(revision ,new-revision)))) + '()))) + + + ;;; ;;; Auto-update. ;;; @@ -535,7 +588,11 @@ (define (update-expression expr replacements) (version (upstream-source-version source)) (version-loc (package-field-location package 'version))) (if version-loc - (let* ((loc (package-location package)) + ;; Use 'package-definition-location' instead of 'package-location' + ;; such that the commit and revision in + ;; (let ((commit ...) (revision ...)) (package ...)) forms can + ;; be updated. + (let* ((loc (package-definition-location package)) (old-version (package-version package)) (old-hash (content-hash-value (origin-hash (package-source package)))) @@ -570,6 +627,8 @@ (define (update-expression expr replacements) 'filename file)) (replacements `((,old-version . ,version) (,old-hash . ,hash) + ,@(maybe-git-versions->revision-replacements + old-version version) ,@(if (and old-commit new-commit) `((,old-commit . ,new-commit)) '()) diff --git a/tests/upstream.scm b/tests/upstream.scm index 9aacb77229..0b14b9867f 100644 --- a/tests/upstream.scm +++ b/tests/upstream.scm @@ -1,6 +1,7 @@ ;;; GNU Guix --- Functional package management for GNU ;;; Copyright © 2016 Ludovic Courtès ;;; Copyright © 2022 Ricardo Wurmus +;;; Copyright © 2022 Maxime Devos ;;; ;;; This file is part of GNU Guix. ;;; @@ -22,6 +23,7 @@ (define-module (test-upstream) #:use-module (guix download) #:use-module (guix packages) #:use-module (guix build-system gnu) + #:use-module (guix git-download) #:use-module (guix import print) #:use-module ((guix licenses) #:prefix license:) #:use-module (guix upstream) @@ -210,4 +212,39 @@ (define test-new-package-sexp '("hello" "sed" "tar" "grep")))) (else (pk else #false))))) +(define (decompose-git-version* str) + (call-with-values (lambda () (decompose-git-version str)) list)) + +(test-equal "decompose-git-version returns arguments if commit is short" + '("1.2.3" "900" "cabba9e") + (decompose-git-version* "1.2.3-900.cabba9e")) + +(test-equal "decompose-git-version handles - in versions" + '("1.2.3-rc0" "123" "ba99a9e") + (decompose-git-version* "1.2.3-rc0-123.ba99a9e")) + +(test-equal "decompose-git-version returns #false if not a git-version result" + '(#false #false #false) + (decompose-git-version* "1.2.3-rc0.ba99a9e")) + +(test-equal "maybe-git-version->revision returns the revision" + "12" + (maybe-git-version->revision "1.2.3-12.ba99a9e")) + +(test-equal "maybe-git-version->revision returns #false if not a git-version" + #false + (maybe-git-version->revision "1.2.3-12.nope")) + +(test-equal "maybe-git-version->revision-replacement can return ()" + '(() () ()) + (map maybe-git-versions->revision-replacements + '("1.2.3" "1.2.3" "1.2.3-21.cabba9e") + '("1.2.3" "1.2.3-21.cabba9e" "1.2.3"))) + +(test-equal "maybe-git-version->revision-replacement with git-version" + '(("(revision \"0\")" . "(revision \"1\")")) + (maybe-git-versions->revision-replacements + (git-version "1.2.3" "0" "cabba9e") + (git-version "1.2.3" "1" "ba99age"))) + (test-end)