From patchwork Tue Apr 25 12:22:10 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sarthak Shah X-Patchwork-Id: 49502 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 CF15627BBEA; Tue, 25 Apr 2023 13:23:25 +0100 (BST) X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on mira.cbaines.net X-Spam-Level: X-Spam-Status: No, score=-3.7 required=5.0 tests=BAYES_00,DKIM_ADSP_CUSTOM_MED, DKIM_INVALID,DKIM_SIGNED,FREEMAIL_FROM,HTML_MESSAGE,MAILING_LIST_MULTI, RCVD_IN_MSPIKE_H2,SPF_HELO_PASS autolearn=ham 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 2C7B627BBE2 for ; Tue, 25 Apr 2023 13:23:24 +0100 (BST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1prHhI-0000eF-Vl; Tue, 25 Apr 2023 08:23:05 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1prHhH-0000dl-3S for guix-patches@gnu.org; Tue, 25 Apr 2023 08:23:03 -0400 Received: from debbugs.gnu.org ([209.51.188.43]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1prHhG-0004O3-Oj for guix-patches@gnu.org; Tue, 25 Apr 2023 08:23:02 -0400 Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1prHhG-0005Gl-Cc for guix-patches@gnu.org; Tue, 25 Apr 2023 08:23:02 -0400 X-Loop: help-debbugs@gnu.org Subject: [bug#62551] Updated patch - with changes, documentation and tests. References: In-Reply-To: Resent-From: Sarthak Shah Original-Sender: "Debbugs-submit" Resent-CC: guix-patches@gnu.org Resent-Date: Tue, 25 Apr 2023 12:23:02 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: followup 62551 X-GNU-PR-Package: guix-patches X-GNU-PR-Keywords: patch To: 62551@debbugs.gnu.org Received: via spool by 62551-submit@debbugs.gnu.org id=B62551.168242538020237 (code B ref 62551); Tue, 25 Apr 2023 12:23:02 +0000 Received: (at 62551) by debbugs.gnu.org; 25 Apr 2023 12:23:00 +0000 Received: from localhost ([127.0.0.1]:51579 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1prHhD-0005GK-Vs for submit@debbugs.gnu.org; Tue, 25 Apr 2023 08:23:00 -0400 Received: from mail-qk1-f171.google.com ([209.85.222.171]:54577) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1prHhC-0005G6-1S for 62551@debbugs.gnu.org; Tue, 25 Apr 2023 08:22:58 -0400 Received: by mail-qk1-f171.google.com with SMTP id af79cd13be357-74e17099772so498456385a.1 for <62551@debbugs.gnu.org>; Tue, 25 Apr 2023 05:22:58 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20221208; t=1682425372; x=1685017372; h=to:subject:message-id:date:from:mime-version:from:to:cc:subject :date:message-id:reply-to; bh=ERKT9++bwnUku9gwYRrOCP66Cw+0yj3S4LlwaHw5SeA=; b=pG2Usxo/DwX3RoAVUHAfuo6jpzpJiNwFFQQ6cwIFn7piGGt+Eokf7QdL6PQal/Pm6F r814X0iNkNjl5EUcMkblXM8vH4wjErfLeJsgi2XTpVmik0kTXZQ8l48g4fye6mXcTfHm QocnHPyRVRdSk0de1Hz+1vUcAWmz44KCRnTBs9GYruucloJhvJ8aIbRhSYfR0kvoHznc 92Y2v69ps3viTJStMdUdDjvnGntCHl8g2Il33W2+6b2WDQRjNT9gFt5Noxb3zeCm62ud vU+zkI/wlXTNaByFsMsDDCPxnBggQPG36iYkwYBZKbSZ/dk7poTIQIWOgW8jPAqGZTHe h6jw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1682425372; x=1685017372; h=to:subject:message-id:date:from:mime-version:x-gm-message-state :from:to:cc:subject:date:message-id:reply-to; bh=ERKT9++bwnUku9gwYRrOCP66Cw+0yj3S4LlwaHw5SeA=; b=WCcwoiWr/BvXZwJx+Zck6Fj1IJXXEqK2ErPMh55HYYC1OWLUOriID1m5h02oWOilOX E3tGKgiLsVs1tcAU+HTkUaoTCbk/eII5Gk4Qi3Uj0DdExf9YHdS3GlxPxEIRyNsaH0md HSDLmEhiRgKEd5p5/Hg6CG6JR7yEUQcfs2YYUIjY8PAOQqN9kB5xXeYEMc+rUMoklZXt l3XucLk/TH8NJqXO2KDksBMNn1qhCcGUQLqEsfFv2k01ZXvs7i5xnGRlwl1Sto6iAya+ rvaXKL6rjMo6xlF4FCaWxPuOww2nrws5qGQABBMbw0AO1WLdJcF9fR/NEsxmqMmIuqY6 u07g== X-Gm-Message-State: AAQBX9fbV0df7kbyBT34gFraN29I20C2UD08JesVrDvhzYXjYnmaQrJi j8D15v+9znAop+zCD+cJkxbcaNpLxHLGA8okzn6bHcc14mW+lA== X-Google-Smtp-Source: AKy350Y5aAQfijjGczpcs3JjVmgCZg7vhJD+qF5t510owXR7EjC7gHhJs2PbMTQmZNYsq+AkRNp9r85XYchW3GE4d60= X-Received: by 2002:a05:6214:21a1:b0:5e9:5602:3af0 with SMTP id t1-20020a05621421a100b005e956023af0mr27505856qvc.46.1682425372073; Tue, 25 Apr 2023 05:22:52 -0700 (PDT) MIME-Version: 1.0 From: Sarthak Shah Date: Tue, 25 Apr 2023 17:52:10 +0530 Message-ID: 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-bounces+patchwork=mira.cbaines.net@gnu.org X-getmail-retrieved-from-mailbox: Patches * doc/guix.texi (--with-configure-flag): Added documentation for --with-configure-flag * guix/transformations.scm (transform-package-configure-flag): New function, changes to %transformations and show-transformation-options-help/detailed * tests/transformations.scm (test-equal "options-transformation, with-configure-flag"): Added a test for --with-configure-flag --- doc/guix.texi | 19 ++++++++++++++ guix/transformations.scm | 53 +++++++++++++++++++++++++++++++++++++++ tests/transformations.scm | 10 +++++++- 3 files changed, 81 insertions(+), 1 deletion(-) (let* ((dep (dummy-package "dep")) (p (dummy-package "foo" diff --git a/doc/guix.texi b/doc/guix.texi index c49e51b72e..627a468b62 100644 --- a/doc/guix.texi +++ b/doc/guix.texi @@ -12859,6 +12859,25 @@ guix build coreutils --with-patch=glibc=./glibc-frob.patch In this example, glibc itself as well as everything that leads to Coreutils in the dependency graph is rebuilt. +@item --with-configure-flag=@var{package}=@var{configure-flag} +Add @var{configure-flag} to the list of configure-flags applied to +the arguments of @var{package}, where @var{package} is a spec such as +@code{guile@@3.1} or @code{glibc}. The build system of @var{package} +must support the argument @code{#:configure-flags}. + +For example, the command below builds GNU Hello with the +configure-flag @code{--disable-nls}: + +@example +guix build hello --with-configure-flag=hello=--disable-nls +@end example + +@quotation Warning +Currently, there is a primitive check for whether the build system +supports the argument @code{#:configure-flags} or not, however +users should not rely on it. +@end quotation + @cindex upstream, latest version @item --with-latest=@var{package} @itemx --with-version=@var{package}=@var{version} diff --git a/guix/transformations.scm b/guix/transformations.scm index 8ff472ad21..27fb0cb646 100644 --- a/guix/transformations.scm +++ b/guix/transformations.scm @@ -676,6 +676,53 @@ (define rewrite (rewrite obj) obj))) +(define (transform-package-configure-flag specs) + "Return a procedure that, when passed a package and a flag, adds the flag to #:configure-flags in the package's +'arguments' field." + (define (package-with-configure-flag p extra-flag) + (package/inherit p + (arguments + (substitute-keyword-arguments (package-arguments p) + ((#:configure-flags list-of-flags (quote '())) + #~(cons* #$extra-flag #$list-of-flags)))))) + + + (define %BUILD-SYSTEMS-WITHOUT-CONFIGURE-FLAGS + ;; These build systems do not have a #:configure-flags parameter +'(android-ndk asdf/sbcl asdf/ecl asdf/source cargo channel chicken clojure copy dub dune elm emacs go guile julia linux-module maven minetest-mod minify node perl rakudo rebar ruby scons texlive tree-sitter trivial)) + + (define (build-system-supports-flags? spec) + ;; XXX: a more sophisticated approach could be added that checks the given build system for a configure-flags option + ;; if a new build system is added, it needs to be added to the %BUILD-SYSTEMS-WITHOUT-CONFIGURE-FLAGS list manually + (not (member (build-system-name (package-build-system spec)) + %BUILD-SYSTEMS-WITHOUT-CONFIGURE-FLAGS))) + + (define cflags + ;; Spec/flag alist. + (map (lambda (spec) + (match (string-tokenize spec %not-equal) + ((spec flag) + (cons spec flag)) + (_ + (raise (formatted-message + (G_ "~a: invalid package configure-flags specification") + spec))))) + specs)) + + (define rewrite + (package-input-rewriting/spec + (map (match-lambda + ((spec . flags) + (cons spec (cut package-with-configure-flag <> flags)))) + cflags))) + + (lambda (obj) + (if (and + (package? obj) + (build-system-supports-flags? obj)) + (rewrite obj) + obj))) + (define (patched-source name source patches) "Return a file-like object with the given NAME that applies PATCHES to SOURCE. SOURCE must itself be a file-like object of any type, including @@ -845,6 +892,7 @@ (define %transformations (tune . ,transform-package-tuning) (with-debug-info . ,transform-package-with-debug-info) (without-tests . ,transform-package-tests) + (with-configure-flag . ,transform-package-configure-flag) (with-patch . ,transform-package-patches) (with-latest . ,transform-package-latest) (with-version . ,transform-package-version))) @@ -915,6 +963,8 @@ (define micro-architecture (parser 'with-debug-info)) (option '("without-tests") #t #f (parser 'without-tests)) + (option '("with-configure-flag") #t #f + (parser 'with-configure-flag)) (option '("with-patch") #t #f (parser 'with-patch)) (option '("with-latest") #t #f @@ -952,6 +1002,9 @@ (define (show-transformation-options-help/detailed) (display (G_ " --with-patch=PACKAGE=FILE add FILE to the list of patches of PACKAGE")) + (display (G_ " + --with-configure-flag=PACKAGE=FLAG + add FLAG to the list of #:configure-flags of PACKAGE")) (display (G_ " --with-latest=PACKAGE use the latest upstream release of PACKAGE")) diff --git a/tests/transformations.scm b/tests/transformations.scm index 1fa2c0bba8..31fd042d31 100644 --- a/tests/transformations.scm +++ b/tests/transformations.scm @@ -33,7 +33,7 @@ (define-module (test-transformations) #:use-module ((guix gexp) #:select (local-file? local-file-file computed-file? computed-file-gexp - gexp-input-thing)) + gexp-input-thing gexp->approximate-sexp)) #:use-module (guix ui) #:use-module (guix utils) #:use-module (guix git) @@ -408,6 +408,14 @@ (define (package-name* obj) (package-full-name grep)) (package-arguments (package-replacement dep0)))))))) +(test-equal "options->transformation, with-configure-flag" + '(cons* "--flag" '()) + (let* ((p (dummy-package "foo" + (build-system gnu-build-system))) + (t (options->transformation '((with-configure-flag . "foo=--flag"))))) + (let ((new (t p))) + (gexp->approximate-sexp (cadr (memq #:configure-flags (package-arguments new))))))) + (test-assert "options->transformation, without-tests"