From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mp1 ([2001:41d0:2:4a6f::]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)) by ms11 with LMTPS id WG1nMi6q4F+IRwAA0tVLHw (envelope-from ) for ; Mon, 21 Dec 2020 13:59:10 +0000 Received: from aspmx1.migadu.com ([2001:41d0:2:4a6f::]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)) by mp1 with LMTPS id IDZnLi6q4F+cCAAAbx9fmQ (envelope-from ) for ; Mon, 21 Dec 2020 13:59:10 +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 267F6940485 for ; Mon, 21 Dec 2020 13:59:10 +0000 (UTC) Received: from localhost ([::1]:46836 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1krLiO-0001KT-Rr for larch@yhetil.org; Mon, 21 Dec 2020 08:59:08 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]:32944) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1krLiI-0001KM-GU for bug-guix@gnu.org; Mon, 21 Dec 2020 08:59:02 -0500 Received: from debbugs.gnu.org ([209.51.188.43]:35019) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1krLiI-0008W4-8k for bug-guix@gnu.org; Mon, 21 Dec 2020 08:59:02 -0500 Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1krLiI-0007Yz-8M for bug-guix@gnu.org; Mon, 21 Dec 2020 08:59:02 -0500 X-Loop: help-debbugs@gnu.org Subject: bug#45300: [PATCH] Add option --with-patch Resent-From: Ludovic =?UTF-8?Q?Court=C3=A8s?= Original-Sender: "Debbugs-submit" Resent-CC: bug-guix@gnu.org Resent-Date: Mon, 21 Dec 2020 13:59:02 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: followup 45300 X-GNU-PR-Package: guix X-GNU-PR-Keywords: To: Philippe SWARTVAGHER Received: via spool by 45300-submit@debbugs.gnu.org id=B45300.160855908728844 (code B ref 45300); Mon, 21 Dec 2020 13:59:02 +0000 Received: (at 45300) by debbugs.gnu.org; 21 Dec 2020 13:58:07 +0000 Received: from localhost ([127.0.0.1]:46559 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1krLhO-0007V2-3a for submit@debbugs.gnu.org; Mon, 21 Dec 2020 08:58:07 -0500 Received: from mail2-relais-roc.national.inria.fr ([192.134.164.83]:58675) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1krLhJ-0007U0-9n for 45300@debbugs.gnu.org; Mon, 21 Dec 2020 08:58:05 -0500 X-IronPort-AV: E=Sophos;i="5.78,436,1599516000"; d="scan'208,223";a="484063474" Received: from 91-160-117-201.subs.proxad.net (HELO ribbon) ([91.160.117.201]) by mail2-relais-roc.national.inria.fr with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 21 Dec 2020 14:57:54 +0100 From: Ludovic =?UTF-8?Q?Court=C3=A8s?= References: <603c5016-6eb1-4305-2825-ed0bacf66025@inria.fr> Date: Mon, 21 Dec 2020 14:57:54 +0100 In-Reply-To: <603c5016-6eb1-4305-2825-ed0bacf66025@inria.fr> (Philippe SWARTVAGHER's message of "Thu, 17 Dec 2020 12:42:34 +0100") Message-ID: <87tusf6z31.fsf@gnu.org> User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/27.1 (gnu/linux) MIME-Version: 1.0 Content-Type: multipart/mixed; boundary="=-=-=" X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list X-BeenThere: bug-guix@gnu.org List-Id: Bug reports for GNU Guix List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: 45300@debbugs.gnu.org Errors-To: bug-guix-bounces+larch=yhetil.org@gnu.org Sender: "bug-Guix" X-Migadu-Flow: FLOW_IN X-Migadu-Spam-Score: -2.32 Authentication-Results: aspmx1.migadu.com; dkim=none; dmarc=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-Migadu-Queue-Id: 267F6940485 X-Spam-Score: -2.32 X-Migadu-Scanner: scn1.migadu.com X-TUID: kSyHevXkGSkR --=-=-= Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable Hi Philippe, Philippe SWARTVAGHER skribis: > We already have `--with-branch=3D`, `with-commit=3D`, ... An additional > option could be `--with-patch=3Dpackage=3Dadd-extra-feature.patch` which > would apply the patch file `add-extra-feature.patch` located in the my > current directory to the sources of `package` before Guix starts > building `package`. Good idea! The patch below does that. Feedback welcome. :-) Ludo=E2=80=99. --=-=-= Content-Type: text/x-patch Content-Disposition: inline; filename=0001-transformations-Add-with-patch.patch Content-Description: the patch >From 12c8df7c61537e3834fac4bf0e8e340cbac2d2df Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ludovic=20Court=C3=A8s?= Date: Mon, 21 Dec 2020 14:52:38 +0100 Subject: [PATCH] transformations: Add '--with-patch'. Suggested by Philippe Swartvagher . * guix/transformations.scm (transform-package-patches): New procedure. (%transformations): Add it as 'with-patch'. (%transformation-options, show-transformation-options-help/detailed): Add '--with-patch'. * tests/transformations.scm ("options->transformation, with-patch"): New test. * doc/guix.texi (Package Transformation Options): Document it. --- doc/guix.texi | 18 +++++++++++ guix/transformations.scm | 63 ++++++++++++++++++++++++++++++++++++++- tests/transformations.scm | 24 +++++++++++++++ 3 files changed, 104 insertions(+), 1 deletion(-) diff --git a/doc/guix.texi b/doc/guix.texi index 392baf5910..c172a898cd 100644 --- a/doc/guix.texi +++ b/doc/guix.texi @@ -10357,6 +10357,24 @@ This is similar to @option{--with-branch}, except that it builds from @var{commit} rather than the tip of a branch. @var{commit} must be a valid Git commit SHA1 identifier or a tag. +@item --with-patch=@var{package}=@var{file} +Add @var{file} to the list of patches applied to @var{package}, where +@var{package} is a spec such as @code{python@@3.8} or @code{glibc}. +@var{file} must contain a patch; it is applied with the flags specified +in the @code{origin} of @var{package} (@pxref{origin Reference}), which +by default includes @code{-p1} (@pxref{patch Directories,,, diffutils, +Comparing and Merging Files}). + +As an example, the command below rebuilds Coreutils with the GNU C +Library (glibc) patched with the given patch: + +@example +guix build coreutils --with-patch=glibc=./glibc-frob.patch +@end example + +In this example, glibc itself as well as everything that leads to +Coreutils in the dependency graph is rebuilt. + @cindex test suite, skipping @item --without-tests=@var{package} Build @var{package} without running its tests. This can be useful in diff --git a/guix/transformations.scm b/guix/transformations.scm index d49041cf59..2385d3231e 100644 --- a/guix/transformations.scm +++ b/guix/transformations.scm @@ -41,6 +41,7 @@ #:use-module (srfi srfi-34) #:use-module (srfi srfi-37) #:use-module (ice-9 match) + #:use-module (ice-9 vlist) #:export (options->transformation manifest-entry-with-transformations @@ -456,6 +457,60 @@ to the same package but with #:strip-binaries? #f in its 'arguments' field." (rewrite obj) obj))) +(define (transform-package-patches specs) + "Return a procedure that, when passed a package, returns a package with +additional patches." + (define (package-with-extra-patches p patches) + (if (origin? (package-source p)) + (package/inherit p + (source (origin + (inherit (package-source p)) + (patches (append (map (lambda (file) + (local-file file)) + patches) + (origin-patches (package-source p))))))) + p)) + + (define (coalesce-alist alist) + ;; Coalesce multiple occurrences of the same key in ALIST. + (let loop ((alist alist) + (keys '()) + (mapping vlist-null)) + (match alist + (() + (map (lambda (key) + (cons key (vhash-fold* cons '() key mapping))) + (delete-duplicates (reverse keys)))) + (((key . value) . rest) + (loop rest + (cons key keys) + (vhash-cons key value mapping)))))) + + (define patches + ;; Spec/patch alist. + (coalesce-alist + (map (lambda (spec) + (match (string-tokenize spec %not-equal) + ((spec patch) + (cons spec (canonicalize-path patch))) + (_ + (raise (formatted-message + (G_ "~a: invalid package patch specification") + spec))))) + specs))) + + (define rewrite + (package-input-rewriting/spec + (map (match-lambda + ((spec . patches) + (cons spec (cut package-with-extra-patches <> patches)))) + patches))) + + (lambda (obj) + (if (package? obj) + (rewrite obj) + obj))) + (define %transformations ;; Transformations that can be applied to things to build. The car is the ;; key used in the option alist, and the cdr is the transformation @@ -469,7 +524,8 @@ to the same package but with #:strip-binaries? #f in its 'arguments' field." (with-git-url . ,transform-package-source-git-url) (with-c-toolchain . ,transform-package-toolchain) (with-debug-info . ,transform-package-with-debug-info) - (without-tests . ,transform-package-tests))) + (without-tests . ,transform-package-tests) + (with-patch . ,transform-package-patches))) (define (transformation-procedure key) "Return the transformation procedure associated with KEY, a symbol such as @@ -509,6 +565,8 @@ to the same package but with #:strip-binaries? #f in its 'arguments' field." (parser 'with-debug-info)) (option '("without-tests") #t #f (parser 'without-tests)) + (option '("with-patch") #t #f + (parser 'with-patch)) (option '("help-transform") #f #f (lambda _ @@ -537,6 +595,9 @@ to the same package but with #:strip-binaries? #f in its 'arguments' field." (display (G_ " --with-git-url=PACKAGE=URL build PACKAGE from the repository at URL")) + (display (G_ " + --with-patch=PACKAGE=FILE + add FILE to the list of patches of PACKAGE")) (display (G_ " --with-c-toolchain=PACKAGE=TOOLCHAIN build PACKAGE and its dependents with TOOLCHAIN")) diff --git a/tests/transformations.scm b/tests/transformations.scm index 2d33bed7ae..9053deba41 100644 --- a/tests/transformations.scm +++ b/tests/transformations.scm @@ -26,6 +26,7 @@ #:use-module (guix build-system) #:use-module (guix build-system gnu) #:use-module (guix transformations) + #:use-module ((guix gexp) #:select (local-file? local-file-file)) #:use-module (guix ui) #:use-module (guix utils) #:use-module (guix git) @@ -372,6 +373,29 @@ (match (memq #:tests? (package-arguments tar)) ((#:tests? #f _ ...) #t)))))))) +(test-equal "options->transformation, with-patch" + (search-patches "glibc-locales.patch" "guile-relocatable.patch") + (let* ((dep (dummy-package "dep" + (source (dummy-origin)))) + (p (dummy-package "foo" + (inputs `(("dep" ,dep))))) + (patch1 (search-patch "glibc-locales.patch")) + (patch2 (search-patch "guile-relocatable.patch")) + (t (options->transformation + `((with-patch . ,(string-append "dep=" patch1)) + (with-patch . ,(string-append "dep=" patch2)) + (with-patch . ,(string-append "tar=" patch1)))))) + (let ((new (t p))) + (match (bag-direct-inputs (package->bag new)) + ((("dep" dep) ("tar" tar) _ ...) + (and (member patch1 + (filter-map (lambda (patch) + (and (local-file? patch) + (local-file-file patch))) + (origin-patches (package-source tar)))) + (map local-file-file + (origin-patches (package-source dep))))))))) + (test-end) ;;; Local Variables: -- 2.29.2 --=-=-=--