From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mp0 ([2001:41d0:2:4a6f::]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)) by ms11 with LMTPS id AMf3NjpCgV/iIwAA0tVLHw (envelope-from ) for ; Sat, 10 Oct 2020 05:10:18 +0000 Received: from aspmx1.migadu.com ([2001:41d0:2:4a6f::]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)) by mp0 with LMTPS id YCu2MjpCgV8COgAA1q6Kng (envelope-from ) for ; Sat, 10 Oct 2020 05:10:18 +0000 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 42AB0940105 for ; Sat, 10 Oct 2020 05:10:18 +0000 (UTC) Received: from localhost ([::1]:48088 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1kR797-000539-6W for larch@yhetil.org; Sat, 10 Oct 2020 01:10:17 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:48818) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1kR78s-00052p-RP for bug-guix@gnu.org; Sat, 10 Oct 2020 01:10:03 -0400 Received: from debbugs.gnu.org ([209.51.188.43]:53467) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1kR78s-0001bI-Hn for bug-guix@gnu.org; Sat, 10 Oct 2020 01:10:02 -0400 Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1kR78s-0006Ph-Cp for bug-guix@gnu.org; Sat, 10 Oct 2020 01:10:02 -0400 X-Loop: help-debbugs@gnu.org Subject: bug#43893: [PATCH] maint: update-guix-package: Ensure sources are clean. References: <87eem7qcxc.fsf@gmail.com> In-Reply-To: <87eem7qcxc.fsf@gmail.com> Resent-From: Maxim Cournoyer Original-Sender: "Debbugs-submit" Resent-CC: bug-guix@gnu.org Resent-Date: Sat, 10 Oct 2020 05:10:02 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: followup 43893 X-GNU-PR-Package: guix X-GNU-PR-Keywords: To: 43893@debbugs.gnu.org Received: via spool by 43893-submit@debbugs.gnu.org id=B43893.160230657724607 (code B ref 43893); Sat, 10 Oct 2020 05:10:02 +0000 Received: (at 43893) by debbugs.gnu.org; 10 Oct 2020 05:09:37 +0000 Received: from localhost ([127.0.0.1]:36780 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1kR78T-0006Op-BO for submit@debbugs.gnu.org; Sat, 10 Oct 2020 01:09:37 -0400 Received: from mail-qk1-f181.google.com ([209.85.222.181]:33841) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1kR78Q-0006OZ-NW for 43893@debbugs.gnu.org; Sat, 10 Oct 2020 01:09:35 -0400 Received: by mail-qk1-f181.google.com with SMTP id x20so5904006qkn.1 for <43893@debbugs.gnu.org>; Fri, 09 Oct 2020 22:09:34 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:mime-version :content-transfer-encoding; bh=zoUo5lWBoSaqckErFru2+iG+WN65NMr6BV3I83e0GbI=; b=cp/HNy4LqhgOQ1A+QYK9uKtIF2zvdqLs6r8MMtHUPpg+TCXSUINycACWvt+9LVGg7j QhWAF4hHRa52vdrM2mnFZxN4raUp9Km4ycQ5LJa50+ASWFXpshZaCnaq4s1le6uLw6Gb DekwI5PRGKTThyv2tJAVYylaJBPNNyhTte5COK6zFqDmBEEiF+/zeXH5Cj830XQjIEdU QUFfO2VqL7fBx1IkE+spAAgT+CrM3VuD+vU7yWmsJVohjEcdxcQBUAKYv4NARAYGNwWr gmc5MOGoWug50UBEkKnbsSW9DWMbffqKxZ6G7uvU6cATp79/abU7zcvyBYmYR1EjdOVw AVsQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:mime-version :content-transfer-encoding; bh=zoUo5lWBoSaqckErFru2+iG+WN65NMr6BV3I83e0GbI=; b=owKi0VDyJ+dzyQV0iUyM4+ydLf0MO6mKgT6btTNERmrL3U9GQKEfXpvLkiCoJMpH6V kWoQeJJ+vZskLd8JKWaoRYrf/0ibkN3/AoFKxzYriRXky+qxA/wVG85McDPztshGF94J g+QIzGcORPMGRLw78zHKtoDhKR4V0PzDQKTYmlHfMvCrmV6CW40eFzuap/CdDczIbSTf 8ECvzo24zqIFFBiJRsiGbYGVkjnhFW05xkV9Rgw7B3ODR6DPbzM3+c0eC8Cwg8cdkZbl JejdAoVGSwPb24c+udmO6hmhbszHgwfvAOfuPwrN6bD29Z4COJp3t/9E27pQUKaH0VID YBdA== X-Gm-Message-State: AOAM5325+hwD/Lk2Uf9/VkllBKOJonsQxG3jcPksWGstvd9L30dGcyhV i/sGINz6O7l7G5m42VMxfI2DIEiQ8Cd/LA== X-Google-Smtp-Source: ABdhPJwxw4kFqFFB33VjFKSIKJv+Mj5kKGe/XuYDTqV8TLbYt0YC+xHFimYzSTH6y5piNGdVQvhfBQ== X-Received: by 2002:a37:7385:: with SMTP id o127mr1140391qkc.235.1602306569018; Fri, 09 Oct 2020 22:09:29 -0700 (PDT) Received: from localhost.localdomain (dsl-10-148-10.b2b2c.ca. [72.10.148.10]) by smtp.gmail.com with ESMTPSA id w4sm8204162qtb.0.2020.10.09.22.09.28 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 09 Oct 2020 22:09:28 -0700 (PDT) From: Maxim Cournoyer Date: Sat, 10 Oct 2020 01:08:52 -0400 Message-Id: <20201010050852.19975-1-maxim.cournoyer@gmail.com> X-Mailer: git-send-email 2.28.0 MIME-Version: 1.0 Content-Type: text/plain; charset=yes Content-Transfer-Encoding: 8bit X-Spam-Score: 0.0 (/) X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list X-Spam-Score: -1.0 (-) X-BeenThere: bug-guix@gnu.org List-Id: Bug reports for GNU Guix List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Maxim Cournoyer Errors-To: bug-guix-bounces+larch=yhetil.org@gnu.org Sender: "bug-Guix" X-Scanner: scn0 Authentication-Results: aspmx1.migadu.com; dkim=fail (body hash did not verify) header.d=gmail.com header.s=20161025 header.b=cp/HNy4L; dmarc=fail reason="SPF not aligned (relaxed)" header.from=gmail.com (policy=none); spf=pass (aspmx1.migadu.com: domain of bug-guix-bounces@gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=bug-guix-bounces@gnu.org X-Spam-Score: 0.09 X-TUID: anQbh65tSSG2 By using a fresh copy of the last commit, we ensure the computed hash is stable in the face of local edits. This change also computes the hash externally from the store, which allows to verify that the hashes are valid using, e.g.: #FIXME: This doesn't work (recursion?) ./pre-inst-env guix build guix --with-git-url=guix=file://$PWD * build-aux/update-guix-package.scm (git-add-worktree): New procedure. (main): Use it to checkout a clean copy of the used commit, and compute the hash from it. Print a user warning after completion. --- build-aux/update-guix-package.scm | 59 +++++++++++++------------------ 1 file changed, 25 insertions(+), 34 deletions(-) diff --git a/build-aux/update-guix-package.scm b/build-aux/update-guix-package.scm index f695e91cfd..b609e57b8f 100644 --- a/build-aux/update-guix-package.scm +++ b/build-aux/update-guix-package.scm @@ -1,5 +1,6 @@ ;;; GNU Guix --- Functional package management for GNU ;;; Copyright © 2017, 2018 Ludovic Courtès +;;; Copyright © 2020 Maxim Cournoyer ;;; ;;; This file is part of GNU Guix. ;;; @@ -29,6 +30,7 @@ (guix utils) (guix base32) (guix build utils) + (guix scripts hash) (gnu packages package-management) (ice-9 match)) @@ -101,44 +103,33 @@ COMMIT." (exp (error "'guix' package definition is not as expected" exp))))) +(define (git-add-worktree directory commit-ish) + "Create a new git worktree at DIRECTORY, detached on commit COMMIT-ISH." + (invoke "git" "worktree" "add" "--detach" directory commit-ish)) + (define (main . args) (match args ((commit version) - (with-store store - (let* ((source (add-to-store store - "guix-checkout" ;dummy name - #t "sha256" %top-srcdir - #:select? version-controlled?)) - (hash (query-path-hash store source)) - (location (package-definition-location)) - (old-hash (content-hash-value - (origin-hash (package-source guix))))) - (edit-expression location - (update-definition commit hash - #:old-hash old-hash - #:version version)) - - ;; Re-add SOURCE to the store, but this time under the real name used - ;; in the 'origin'. This allows us to build the package without - ;; having to make a real checkout; thus, it also works when working - ;; on a private branch. - (reload-module - (resolve-module '(gnu packages package-management))) - - (let* ((source (add-to-store store - (origin-file-name (package-source guix)) - #t "sha256" source)) - (root (store-path-package-name source))) - - ;; Add an indirect GC root for SOURCE in the current directory. - (false-if-exception (delete-file root)) - (symlink source root) - (add-indirect-root store - (string-append (getcwd) "/" root)) - - (format #t "source code for commit ~a: ~a (GC root: ~a)~%" - commit source root))))) + (with-directory-excursion %top-srcdir + (call-with-temporary-directory + (lambda (tmp-directory) + (let* ((dummy (git-add-worktree tmp-directory commit)) + (hash (nix-base32-string->bytevector + (string-trim-both + (with-output-to-string + (lambda () + (guix-hash "-rx" tmp-directory)))))) + (location (package-definition-location)) + (old-hash (content-hash-value + (origin-hash (package-source guix))))) + (edit-expression location + (update-definition commit hash + #:old-hash old-hash + #:version version)) + (format #t "Updated Guix to commit ~s. You must ensure this +commit hash exists in the public repository, else 'guix pull' will break. +Beware of 'git rebase'~%" commit)))))) ((commit) ;; Automatically deduce the version and revision numbers. (main commit #f)))) -- 2.28.0