From patchwork Thu Mar 30 19:52:41 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sarthak Shah X-Patchwork-Id: 48824 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 A46361723F; Thu, 30 Mar 2023 20:53:31 +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=-1.8 required=5.0 tests=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 1F588171F5 for ; Thu, 30 Mar 2023 20:53:30 +0100 (BST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1phyKW-0004Lf-TJ; Thu, 30 Mar 2023 15:53:04 -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 1phyKV-0004L5-5S for guix-patches@gnu.org; Thu, 30 Mar 2023 15:53: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 1phyKU-0000GL-TX for guix-patches@gnu.org; Thu, 30 Mar 2023 15:53:02 -0400 Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1phyKU-0003Rg-7z for guix-patches@gnu.org; Thu, 30 Mar 2023 15:53:02 -0400 X-Loop: help-debbugs@gnu.org Subject: [bug#62551] Added new transformation option: --with-configure-flag Resent-From: Sarthak Shah Original-Sender: "Debbugs-submit" Resent-CC: guix-patches@gnu.org Resent-Date: Thu, 30 Mar 2023 19:53:02 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: report 62551 X-GNU-PR-Package: guix-patches X-GNU-PR-Keywords: To: 62551@debbugs.gnu.org Cc: Ludovic =?utf-8?q?Court=C3=A8s?= X-Debbugs-Original-To: guix-patches@gnu.org Received: via spool by submit@debbugs.gnu.org id=B.168020598013235 (code B ref -1); Thu, 30 Mar 2023 19:53:02 +0000 Received: (at submit) by debbugs.gnu.org; 30 Mar 2023 19:53:00 +0000 Received: from localhost ([127.0.0.1]:59469 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1phyKS-0003RO-5h for submit@debbugs.gnu.org; Thu, 30 Mar 2023 15:53:00 -0400 Received: from lists.gnu.org ([209.51.188.17]:41834) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1phyKQ-0003RG-5t for submit@debbugs.gnu.org; Thu, 30 Mar 2023 15:52:59 -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 1phyKP-0004Kk-Ne for guix-patches@gnu.org; Thu, 30 Mar 2023 15:52:57 -0400 Received: from mail-qv1-xf2b.google.com ([2607:f8b0:4864:20::f2b]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1phyKN-0000F0-QG; Thu, 30 Mar 2023 15:52:57 -0400 Received: by mail-qv1-xf2b.google.com with SMTP id o44so14980063qvo.4; Thu, 30 Mar 2023 12:52:53 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; t=1680205973; h=cc:to:subject:message-id:date:from:mime-version:from:to:cc:subject :date:message-id:reply-to; bh=iH+1m2TVBNlICFO0MtMvQdfdvY4XRfM7Fyh6XcEcXig=; b=ZdN2mJzGHC/syokgGBGHIz6ukqXP8oqLnio1EAIDjUIHw2uSfPnkCpXDuy/Mn+hRHs RRxyG4mMcrasYFvEsEqh24lz8/V3RbNHemu4dsElXGy3k3mfULMu3ikYHVhlgdXGaJXs b25L2W9llkjnwnTovBEi/1tqhyPLY3sNw/P+RlEfnPkhw9WAv+xcOd4kzAOil0Zr/TVe dLD7GJnicwDYWc+M+husJu6ECuYrfM0Ce59EbXj1Uv2Rc7VdSDHVhZgEUpZQVTpBnyS7 s8gdsqV85XXvMVjGAp+VjxiViyqax8oPsT1fdgf3JEoEVDpZE1rB/5gkjrpo8ofMgIxl SRTA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; t=1680205973; h=cc:to:subject:message-id:date:from:mime-version:x-gm-message-state :from:to:cc:subject:date:message-id:reply-to; bh=iH+1m2TVBNlICFO0MtMvQdfdvY4XRfM7Fyh6XcEcXig=; b=z8acUPX8Iu7fiyYVKd2lbGh73seciniL5PQizxyRZSN5jLKnrtlASZSB0USwfa+kqV R0sV2507m8L6ZV+CXDHRguoAq5dUMnZuxgKht1tNC49EKe/mg89gr1wOlxZovFwVXCpJ VagHmbIswGDYMJkYgoHUkHy9ZdZhEy+ojBJK8m/Y9TiN54zW4weTm4Cn2uD+MzcG7t0s bhVej7tErcNteUdPuqEWBQq2B4EGzZGDAcSke18y2YGzv+jj5k2uhJYdKnv25ipENtzT UE3g+d/Y78nYPGLJh3TXb3UlYvNm752IlDFnHELIWMAVAF0rErXOQ5/GBYnODav8NCCb jNpQ== X-Gm-Message-State: AAQBX9fYGekaPXTLBPcZEMQeTRXqV7O5zmGFpOuea9OkYVHR5dhwUI2E EeQpTskqYGBNxykMhY0e1+3HQrgsnq4DtrfL6zO53rOZLNO6kA== X-Google-Smtp-Source: AKy350as23g4+MvnmWlPwPXcHzTC3CprChmI9gQrSYGGZfAN6xUhUB0t0HFwRWU10CG//69ldxHo9xKZN3Oc7h9zZfI= X-Received: by 2002:ad4:4d4e:0:b0:571:e9d3:24a9 with SMTP id m14-20020ad44d4e000000b00571e9d324a9mr4215918qvm.10.1680205972890; Thu, 30 Mar 2023 12:52:52 -0700 (PDT) MIME-Version: 1.0 From: Sarthak Shah Date: Fri, 31 Mar 2023 01:22:41 +0530 Message-ID: Received-SPF: pass client-ip=2607:f8b0:4864:20::f2b; envelope-from=shahsarthakw@gmail.com; helo=mail-qv1-xf2b.google.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, FREEMAIL_FROM=0.001, HTML_MESSAGE=0.001, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action 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 This patch adds a new transformation option that lets the user specify a package to add an extra #:configure-flags value to. Functionally, it is quite similar to the --with-patch transform. Currently, I've generated a list of build systems that do not support #:configure-flags that this transform checks against, but this could be improved by making the transform check if any given transform has the #:configure-flags keyword in its arguments. Please test this patch if possible; my preliminary testing indicates that it is working, however it could fail for edge cases I have not considered. CCing Ludovic as he might be interested in this. --- guix/transformations.scm | 70 ++++++++++++++++++++++++++++++++++++++++ 1 file changed, 70 insertions(+) + (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 +909,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 +980,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 +1019,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/guix/transformations.scm b/guix/transformations.scm index 8ff472ad21..8f260807dc 100644 --- a/guix/transformations.scm +++ b/guix/transformations.scm @@ -676,6 +676,70 @@ (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 '())) + ;; here extra-flag takes the form (--extra-flag) + ;; hence it must be spliced to avoid eval errors + `(cons* ,@extra-flag ,list-of-flags)))))) + + (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 %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. + (coalesce-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))