From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mp12.migadu.com ([2001:41d0:8:6d80::]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)) by ms0.migadu.com with LMTPS id GFP4Mle80GGeeAEAgWs5BA (envelope-from ) for ; Sat, 01 Jan 2022 21:40:55 +0100 Received: from aspmx1.migadu.com ([2001:41d0:8:6d80::]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)) by mp12.migadu.com with LMTPS id 2IaUL1e80GFetwAAauVa8A (envelope-from ) for ; Sat, 01 Jan 2022 21:40:55 +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 692C72275E for ; Sat, 1 Jan 2022 21:40:53 +0100 (CET) Received: from localhost ([::1]:57220 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1n3lBM-0007br-K7 for larch@yhetil.org; Sat, 01 Jan 2022 15:40:52 -0500 Received: from eggs.gnu.org ([209.51.188.92]:45618) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1n3lAZ-0007ZI-Km for guix-patches@gnu.org; Sat, 01 Jan 2022 15:40:04 -0500 Received: from debbugs.gnu.org ([209.51.188.43]:47925) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1n3lAZ-0003zS-Aa for guix-patches@gnu.org; Sat, 01 Jan 2022 15:40:03 -0500 Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1n3lAZ-0003CR-9K for guix-patches@gnu.org; Sat, 01 Jan 2022 15:40:03 -0500 X-Loop: help-debbugs@gnu.org Subject: [bug#50072] [PATCH v2 2/4] import: Factorize file hashing. Resent-From: Maxime Devos Original-Sender: "Debbugs-submit" Resent-CC: guix-patches@gnu.org Resent-Date: Sat, 01 Jan 2022 20:40:03 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: followup 50072 X-GNU-PR-Package: guix-patches X-GNU-PR-Keywords: patch To: 50072@debbugs.gnu.org Cc: Ludovic =?UTF-8?Q?Court=C3=A8s?= , Sarah Morgensen Received: via spool by 50072-submit@debbugs.gnu.org id=B50072.164106959712257 (code B ref 50072); Sat, 01 Jan 2022 20:40:03 +0000 Received: (at 50072) by debbugs.gnu.org; 1 Jan 2022 20:39:57 +0000 Received: from localhost ([127.0.0.1]:59465 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1n3lAO-0003BL-8s for submit@debbugs.gnu.org; Sat, 01 Jan 2022 15:39:57 -0500 Received: from michel.telenet-ops.be ([195.130.137.88]:42632) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1n3lAL-0003Ag-36 for 50072@debbugs.gnu.org; Sat, 01 Jan 2022 15:39:51 -0500 Received: from localhost.localdomain ([IPv6:2a02:1811:8c09:9d00:3c5f:2eff:feb0:ba5a]) by michel.telenet-ops.be with bizsmtp id dYfm2600C4UW6Th06YfnkE; Sat, 01 Jan 2022 21:39:47 +0100 From: Maxime Devos Date: Sat, 1 Jan 2022 20:39:38 +0000 Message-Id: <20220101203940.149517-3-maximedevos@telenet.be> X-Mailer: git-send-email 2.30.2 In-Reply-To: <20220101203940.149517-1-maximedevos@telenet.be> References: <20220101203940.149517-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=r21; t=1641069587; bh=RXKwd85pZUV2ji75cmi30gVSGgIyuezvD1aR1EKaga0=; h=From:To:Cc:Subject:Date:In-Reply-To:References; b=rkOfIVf9LAppzXL8v/zvbIhdASN6azn64KMuewVRMoxJttuFMHt/XK2XKYiInjd4L dZxbSjPZzTnVszI+sY+VpTJ2LWSEmNO992UiSKKZN7SWhvHx3cx3/FifUyKsA5SK1W 6WFBcsn3D8WObLW+w3EBIrsnWqHzFEtzI+sIaza0iwZyeHEgZU/hvl8dXN5xA8Z1kM a7iHJKp84sA8FXphRakwxtzEcczXHB4M4ur01OK4ul5KHvhx3qj3dSRLNCp48Y1hDr IoXtazPdGzPkKBNXjv1PdZlNleAk7N2CtpcKFGnKMFqS/L3GJtHctcQhDXbofidTWI N0Sk8q9xdAvQg== 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=1641069653; 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=RXKwd85pZUV2ji75cmi30gVSGgIyuezvD1aR1EKaga0=; b=BDKOQ+BJx6BPlBdtHLc01mvX6RB1wAB9DQLdc7cQJKwHf7RmDkg1OgDFZWeF0mCK2TsvfC YEeAGLqVuA+145JzHgPSxwBOMGRe8yj59WU8f9FJ+1++Rr3ndKkkN24oZbiPyUB225jtFT Za+GjYtSOJtSTlPjzEv8WKhetfDEX/kiof96qjBwdrt6hNCF9DLTX8nPmAQ0IDZJFpQv2l TPeYnEML4R8js4COBuVzDnIaVQpN6rpqscvpeoML8g6xjfBIM7O07E9ezygIRx7CjRhaac TuDLPheIXJx/3DmrF8qVK4B8KYUOnivPOhSo7XNGhlaYZHIeZmc94D37mq/1Fw== ARC-Seal: i=1; s=key1; d=yhetil.org; t=1641069653; a=rsa-sha256; cv=none; b=QYhRXT3IHlTMUVFWeqzmnyM5ouCKoy0CUTIxCUikLa3n5bMiWhNLJUCD8cYxsJCiQiA26j zOxxz+NGj5TOLqRf8KpoFh/92R0BVK5N3nyeXHHxI7iDkGiy1Ma9EOGkceqKEngcz4NrCW flBmAAQYZ1KBy7X+cg4qulZT9aO8nNiYr2268igkV4SNwHlmxkDWLFOSSSDfIZksnfNuPz IGzP5IzR58dLfKhuOC128bIwL959+7XrJBtkQUa/FJI6EnD27nn2l/G5TUEd9zK3QW4+LP 5ut+/ea1KiPaZZwguX912XlY/qXm+Rb9i7X/47DJrxmDvhZ9hTxALD1p/3lfVQ== ARC-Authentication-Results: i=1; aspmx1.migadu.com; dkim=fail ("headers rsa verify failed") header.d=telenet.be header.s=r21 header.b=rkOfIVf9; 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.08 Authentication-Results: aspmx1.migadu.com; dkim=fail ("headers rsa verify failed") header.d=telenet.be header.s=r21 header.b=rkOfIVf9; 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: 692C72275E X-Spam-Score: -1.08 X-Migadu-Scanner: scn1.migadu.com X-TUID: AfZTkK5OV6UL From: Sarah Morgensen * guix/import/cran.scm (vcs-file?, file-hash): Remove procedures. (description->package): Use 'file-hash*' instead. * guix/import/elpa.scm (vcs-file?, file-hash): Remove procedures. (git-repository->origin, elpa-package->sexp): Use 'file-hash* instead'. * guix/import/go.scm (vcs-file?, file-hash): Remove procedures. (git-checkout-hash): Use 'file-hash*' instead. * guix/import/minetest.scm (file-hash): Remove procedure. (make-minetest-sexp): Use 'file-hash*' instead. --- guix/import/cran.scm | 32 +++----------------------------- guix/import/elpa.scm | 29 ++++------------------------- guix/import/go.scm | 25 +++---------------------- guix/import/minetest.scm | 18 +++++++----------- 4 files changed, 17 insertions(+), 87 deletions(-) diff --git a/guix/import/cran.scm b/guix/import/cran.scm index 1389576cad..69f4533da7 100644 --- a/guix/import/cran.scm +++ b/guix/import/cran.scm @@ -3,6 +3,7 @@ ;;; Copyright © 2015, 2016, 2017, 2019, 2020, 2021 Ludovic Courtès ;;; Copyright © 2017 Mathieu Othacehe ;;; Copyright © 2020 Martin Becze +;;; Copyright © 2021 Sarah Morgensen ;;; ;;; This file is part of GNU Guix. ;;; @@ -35,10 +36,9 @@ #:use-module (guix memoization) #:use-module (guix http-client) #:use-module (guix diagnostics) + #:use-module (guix hash) #:use-module (guix i18n) - #:use-module (gcrypt hash) #:use-module (guix store) - #:use-module ((guix serialization) #:select (write-file)) #:use-module (guix base32) #:use-module ((guix download) #:select (download-to-store)) #:use-module (guix import utils) @@ -196,17 +196,6 @@ bioconductor package NAME, or #F if the package is unknown." (bioconductor-packages-list type)) (cut assoc-ref <> "Version"))) -;; XXX taken from (guix scripts hash) -(define (vcs-file? file stat) - (case (stat:type stat) - ((directory) - (member (basename file) '(".bzr" ".git" ".hg" ".svn" "CVS"))) - ((regular) - ;; Git sub-modules have a '.git' file that is a regular text file. - (string=? (basename file) ".git")) - (else - #f))) - ;; Little helper to download URLs only once. (define download (memoize @@ -464,16 +453,6 @@ reference the pkg-config tool." (define (needs-knitr? meta) (member "knitr" (listify meta "VignetteBuilder"))) -;; XXX adapted from (guix scripts hash) -(define (file-hash file select? recursive?) - ;; Compute the hash of FILE. - (if recursive? - (let-values (((port get-hash) (open-sha256-port))) - (write-file file port #:select? select?) - (force-output port) - (get-hash)) - (call-with-input-file file port-sha256))) - (define (description->package repository meta) "Return the `package' s-expression for an R package published on REPOSITORY from the alist META, which was derived from the R package's DESCRIPTION file." @@ -571,12 +550,7 @@ from the alist META, which was derived from the R package's DESCRIPTION file." (sha256 (base32 ,(bytevector->nix-base32-string - (case repository - ((git) - (file-hash source (negate vcs-file?) #t)) - ((hg) - (file-hash source (negate vcs-file?) #t)) - (else (file-sha256 source)))))))) + (file-hash* source)))))) ,@(if (not (and git? hg? (equal? (string-append "r-" name) (cran-guix-name name)))) diff --git a/guix/import/elpa.scm b/guix/import/elpa.scm index edabb88b7a..c1f40ed915 100644 --- a/guix/import/elpa.scm +++ b/guix/import/elpa.scm @@ -5,6 +5,7 @@ ;;; Copyright © 2020 Martin Becze ;;; Copyright © 2020 Ricardo Wurmus ;;; Copyright © 2021 Xinglu Chen +;;; Copyright © 2021 Sarah Morgensen ;;; ;;; This file is part of GNU Guix. ;;; @@ -37,10 +38,10 @@ #:use-module (guix import utils) #:use-module (guix http-client) #:use-module (guix git) + #:use-module (guix hash) #:use-module ((guix serialization) #:select (write-file)) #:use-module (guix store) #:use-module (guix ui) - #:use-module (gcrypt hash) #:use-module (guix base32) #:use-module (guix upstream) #:use-module (guix packages) @@ -229,27 +230,6 @@ keywords to values." (close-port port) (data->recipe (cons ':name data)))) -;; XXX adapted from (guix scripts hash) -(define (file-hash file select? recursive?) - ;; Compute the hash of FILE. - (if recursive? - (let-values (((port get-hash) (open-sha256-port))) - (write-file file port #:select? select?) - (force-output port) - (get-hash)) - (call-with-input-file file port-sha256))) - -;; XXX taken from (guix scripts hash) -(define (vcs-file? file stat) - (case (stat:type stat) - ((directory) - (member (basename file) '(".bzr" ".git" ".hg" ".svn" "CVS"))) - ((regular) - ;; Git sub-modules have a '.git' file that is a regular text file. - (string=? (basename file) ".git")) - (else - #f))) - (define (git-repository->origin recipe url) "Fetch origin details from the Git repository at URL for the provided MELPA RECIPE." @@ -270,8 +250,7 @@ RECIPE." (commit ,commit))) (sha256 (base32 - ,(bytevector->nix-base32-string - (file-hash directory (negate vcs-file?) #t))))))) + ,(bytevector->nix-base32-string (file-hash* directory))))))) (define* (melpa-recipe->origin recipe) "Fetch origin details from the MELPA recipe and associated repository for @@ -380,7 +359,7 @@ type ''." (sha256 (base32 ,(if tarball - (bytevector->nix-base32-string (file-sha256 tarball)) + (bytevector->nix-base32-string (file-hash* tarball)) "failed to download package"))))))) (build-system emacs-build-system) ,@(maybe-inputs 'propagated-inputs dependencies) diff --git a/guix/import/go.scm b/guix/import/go.scm index 26dbc34b63..ea999d290c 100644 --- a/guix/import/go.scm +++ b/guix/import/go.scm @@ -26,6 +26,7 @@ (define-module (guix import go) #:use-module (guix build-system go) #:use-module (guix git) + #:use-module (guix hash) #:use-module (guix i18n) #:use-module (guix diagnostics) #:use-module (guix import utils) @@ -36,11 +37,10 @@ #:use-module ((guix licenses) #:prefix license:) #:use-module (guix memoization) #:autoload (htmlprag) (html->sxml) ;from Guile-Lib - #:autoload (guix git) (update-cached-checkout) - #:autoload (gcrypt hash) (open-hash-port hash-algorithm sha256) #:autoload (guix serialization) (write-file) #:autoload (guix base32) (bytevector->nix-base32-string) #:autoload (guix build utils) (mkdir-p) + #:autoload (gcrypt hash) (hash-algorithm sha256) #:use-module (ice-9 match) #:use-module (ice-9 peg) #:use-module (ice-9 rdelim) @@ -499,25 +499,6 @@ source." goproxy (module-meta-repo-root meta-data))) -;; XXX: Copied from (guix scripts hash). -(define (vcs-file? file stat) - (case (stat:type stat) - ((directory) - (member (basename file) '(".bzr" ".git" ".hg" ".svn" "CVS"))) - ((regular) - ;; Git sub-modules have a '.git' file that is a regular text file. - (string=? (basename file) ".git")) - (else - #f))) - -;; XXX: Adapted from 'file-hash' in (guix scripts hash). -(define* (file-hash file #:optional (algorithm (hash-algorithm sha256))) - ;; Compute the hash of FILE. - (let-values (((port get-hash) (open-hash-port algorithm))) - (write-file file port #:select? (negate vcs-file?)) - (force-output port) - (get-hash))) - (define* (git-checkout-hash url reference algorithm) "Return the ALGORITHM hash of the checkout of URL at REFERENCE, a commit or tag." @@ -536,7 +517,7 @@ tag." (update-cached-checkout url #:ref `(tag-or-commit . ,reference))))) - (file-hash checkout algorithm))) + (file-hash* checkout #:algorithm algorithm))) (define (vcs->origin vcs-type vcs-repo-url version) "Generate the `origin' block of a package depending on what type of source diff --git a/guix/import/minetest.scm b/guix/import/minetest.scm index abddd885ee..44671d8480 100644 --- a/guix/import/minetest.scm +++ b/guix/import/minetest.scm @@ -1,5 +1,5 @@ ;;; GNU Guix --- Functional package management for GNU -;;; Copyright © 2021 Maxime Devos +;;; Copyright © 2021, 2022 Maxime Devos ;;; ;;; This file is part of GNU Guix. ;;; @@ -39,6 +39,7 @@ #:use-module (guix base32) #:use-module (guix git) #:use-module ((guix git-download) #:prefix download:) + #:use-module (guix hash) #:use-module (guix store) #:export (%default-sort-key %contentdb-api @@ -286,14 +287,6 @@ results. The return value is a list of records." (with-store store (latest-repository-commit store url #:ref ref))) -;; XXX adapted from (guix scripts hash) -(define (file-hash file) - "Compute the hash of FILE." - (let-values (((port get-hash) (open-sha256-port))) - (write-file file port) - (force-output port) - (get-hash))) - (define (make-minetest-sexp author/name version repository commit inputs home-page synopsis description media-license license) @@ -314,9 +307,12 @@ MEDIA-LICENSE and LICENSE." ;; The git commit is not always available. ,(and commit (bytevector->nix-base32-string - (file-hash + (file-hash* (download-git-repository repository - `(commit . ,commit))))))) + `(commit . ,commit)) + ;; 'download-git-repository' already filtered out the '.git' + ;; directory. + #:select? (const #true)))))) (file-name (git-file-name name version)))) (build-system minetest-mod-build-system) ,@(maybe-propagated-inputs (map contentdb->package-name inputs)) -- 2.30.2