From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mp12.migadu.com ([2001:41d0:2:bcc0::]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)) by ms0.migadu.com with LMTPS id YMy3DMgz22EpSAEAgWs5BA (envelope-from ) for ; Sun, 09 Jan 2022 20:13:12 +0100 Received: from aspmx1.migadu.com ([2001:41d0:2:bcc0::]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)) by mp12.migadu.com with LMTPS id UMdwCcgz22GFmAAAauVa8A (envelope-from ) for ; Sun, 09 Jan 2022 20:13:12 +0100 Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by aspmx1.migadu.com (Postfix) with ESMTPS id 9D2AA3E0C5 for ; Sun, 9 Jan 2022 20:13:11 +0100 (CET) Received: from localhost ([::1]:42256 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1n6dcs-0003w5-S4 for larch@yhetil.org; 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 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 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+larch=yhetil.org@gnu.org Sender: "Guix-patches" X-Migadu-Flow: FLOW_IN X-Migadu-Country: US ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=yhetil.org; s=key1; t=1641755591; h=from:from:sender:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-type: content-transfer-encoding:content-transfer-encoding:resent-cc: resent-from:resent-sender:resent-message-id:in-reply-to:in-reply-to: references:references:list-id:list-help:list-unsubscribe: list-subscribe:list-post:dkim-signature; bh=v1TrHB2SStczDDlPbBh4hKVcK72fHybe/vEEVbeutjk=; b=dRPBzKGO3BewiS0PHrWHAIORcuJAZp9Rtuyfz1sVBG6C54wgZ9SvNqUGnAFzhOueCQIm2M bYv4ar7CpKf7Ur+dQOHiM19GtuciSp4hxya8eepCuwKCGFZcwixPDtMykgL4fgTewqrrK+ Y9ZGqL47LSfn+K4oyOIZibdhWj9eNS89Y6G7iA/X/zSJcFNgfUweXINvRqJpleySmj8DFJ fNnCzRKZy8o9cSh4mKE9/ACHtIZj0Pnzk5l+6rdU6gr6AWUIiyDe7UGdYx/HWZjBLN01hc 3zwkmD/QeahKUHLssUStq40TNM/IjTcFfokvw53otcaK6hsVewftlKpRiKTIxw== ARC-Seal: i=1; s=key1; d=yhetil.org; t=1641755591; a=rsa-sha256; cv=none; b=p+ItWUBsBlvq8fV/D49k3Y/XVdJhSYlLRZMPd8kV9LMRwQUBy3g2GKSVcAWfmG5W3yjmc7 CVGhMbwogFpKjqBSfIatA8meb9F6FZhDf/d0/I04mkCuvT5YbsOCxPxtKkUz92I4txmnPl reyfGWlzbOPLo/WZHwMxHLsYVwdo1bekBNadYItVVnqVvBS3yyG0p58ovlCh4kpxSkxaEJ nYPB0FpHLiHH8f1D+OXBeUSU+q1EI4NDxC5NRGYKt2cjf8vNETojymanJw4iV5oqnP1CW7 8zGI7civpZpyIBPTf1I6HKd+WMBRA8VHaTe63XC2tuqVpkJm+RcVXd1TUM2fBw== ARC-Authentication-Results: i=1; aspmx1.migadu.com; dkim=fail ("headers rsa verify failed") header.d=telenet.be header.s=r22 header.b=Ppx3Qnbh; dmarc=fail reason="SPF not aligned (relaxed)" header.from=telenet.be (policy=none); spf=pass (aspmx1.migadu.com: domain of "guix-patches-bounces+larch=yhetil.org@gnu.org" designates 209.51.188.17 as permitted sender) smtp.mailfrom="guix-patches-bounces+larch=yhetil.org@gnu.org" X-Migadu-Spam-Score: -1.11 Authentication-Results: aspmx1.migadu.com; dkim=fail ("headers rsa verify failed") header.d=telenet.be header.s=r22 header.b=Ppx3Qnbh; dmarc=fail reason="SPF not aligned (relaxed)" header.from=telenet.be (policy=none); spf=pass (aspmx1.migadu.com: domain of "guix-patches-bounces+larch=yhetil.org@gnu.org" designates 209.51.188.17 as permitted sender) smtp.mailfrom="guix-patches-bounces+larch=yhetil.org@gnu.org" X-Migadu-Queue-Id: 9D2AA3E0C5 X-Spam-Score: -1.11 X-Migadu-Scanner: scn1.migadu.com X-TUID: 3l7wU0pUhulK 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) -- 2.34.0