From patchwork Sat Feb 11 10:08:00 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Lars-Dominik Braun X-Patchwork-Id: 46812 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 084271661B; Sat, 11 Feb 2023 10:09:42 +0000 (GMT) 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_INVALID, DKIM_SIGNED,MAILING_LIST_MULTI,RCVD_IN_MSPIKE_H2,SPF_HELO_PASS, URIBL_BLOCKED autolearn=unavailable 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 A4730165B0 for ; Sat, 11 Feb 2023 10:09:40 +0000 (GMT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1pQmoh-0004nv-LX; Sat, 11 Feb 2023 05:09:13 -0500 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 1pQmoZ-0004nN-8c for guix-patches@gnu.org; Sat, 11 Feb 2023 05:09:03 -0500 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 1pQmoZ-00008k-0N for guix-patches@gnu.org; Sat, 11 Feb 2023 05:09:03 -0500 Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1pQmoY-0004By-Sv for guix-patches@gnu.org; Sat, 11 Feb 2023 05:09:02 -0500 X-Loop: help-debbugs@gnu.org Subject: [bug#61420] [PATCH 03/31] build: haskell-build-system: Support multiple libraries. Resent-From: Lars-Dominik Braun Original-Sender: "Debbugs-submit" Resent-CC: guix-patches@gnu.org Resent-Date: Sat, 11 Feb 2023 10:09:02 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: followup 61420 X-GNU-PR-Package: guix-patches X-GNU-PR-Keywords: patch To: 61420@debbugs.gnu.org Cc: Philip Munksgaard , Lars-Dominik Braun , zimoun Received: via spool by 61420-submit@debbugs.gnu.org id=B61420.167611013215938 (code B ref 61420); Sat, 11 Feb 2023 10:09:02 +0000 Received: (at 61420) by debbugs.gnu.org; 11 Feb 2023 10:08:52 +0000 Received: from localhost ([127.0.0.1]:38854 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1pQmoN-00048o-N2 for submit@debbugs.gnu.org; Sat, 11 Feb 2023 05:08:52 -0500 Received: from mout-p-201.mailbox.org ([80.241.56.171]:38634) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1pQmoG-00046M-Fx for 61420@debbugs.gnu.org; Sat, 11 Feb 2023 05:08:45 -0500 Received: from smtp102.mailbox.org (smtp102.mailbox.org [IPv6:2001:67c:2050:b231:465::102]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange ECDHE (P-384) server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by mout-p-201.mailbox.org (Postfix) with ESMTPS id 4PDRBr3DsLz9sbm; Sat, 11 Feb 2023 11:08:36 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=6xq.net; s=MBO0001; t=1676110116; h=from:from: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: in-reply-to:in-reply-to:references:references; bh=i6oKxw7+lmEtPvprwhr1Ir+f7Qn1xh4ofpU8yMdQ2hU=; b=OnecETHYXrnCSKyU/fQYzLt5lpYfleOxRxqgxuXuJtCQrVWm+BWfgY62srai4BnlBOYb61 RukMUOt3MZdFF1SCWsOjVngC/TgbsLZuxOMbw2XUnw9sA3E+tHdEiQ3/4bVGQdBcadd/gc A378B1YsB1eOUrhZ/5ATrmvJD8bORjnOhdG5/I5goFvdn8ErkfFFNtzJPWkcGyBy7I/vzf yd7LMybIlLCa4527+ntnvNjJCk5gsl8F9b8WQb0ibQVZvp/zfJVJcp9iVDeAP/jhq9OCFN 5oGvP5Rw1lhtGzU3rbF4SwrQukiUD/QWIlVvtTiwbxyyRreK4JMggF4PuCw30A== From: Lars-Dominik Braun Date: Sat, 11 Feb 2023 11:08:00 +0100 Message-Id: <20230211100825.47971-3-lars@6xq.net> In-Reply-To: <20230211100825.47971-1-lars@6xq.net> References: <20230211100825.47971-1-lars@6xq.net> MIME-Version: 1.0 X-Rspamd-Queue-Id: 4PDRBr3DsLz9sbm 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 From: Philip Munksgaard Fixes . The patch handles correctly the multiple registration of some package using their own internal sub-libraries. It allows to call 'install-transitive-deps' multiple times and deals with packages requiring a multiple registration. * guix/build/haskell-build-system.scm (register)[install-transitive-deps]: Guard also the destination direction. [install-config-file]: New procedure. Co-Authored-by: zimoun . Signed-off-by: Lars-Dominik Braun --- guix/build/haskell-build-system.scm | 87 ++++++++++++++++------------- 1 file changed, 49 insertions(+), 38 deletions(-) diff --git a/guix/build/haskell-build-system.scm b/guix/build/haskell-build-system.scm index e2e5904dce..fb4aba28ea 100644 --- a/guix/build/haskell-build-system.scm +++ b/guix/build/haskell-build-system.scm @@ -6,6 +6,7 @@ ;;; Copyright © 2018 Alex Vong ;;; Copyright © 2021 John Kehayias ;;; Copyright © 2022 Simon Tournier +;;; Copyright © 2022 Philip Munksgaard ;;; ;;; This file is part of GNU Guix. ;;; @@ -215,13 +216,50 @@ (define (install-transitive-deps conf-file src dest) (if (not (vhash-assoc id seen)) (let ((dep-conf (string-append src "/" id ".conf")) (dep-conf* (string-append dest "/" id ".conf"))) - (when (not (file-exists? dep-conf)) + (unless (file-exists? dep-conf*) + (unless (file-exists? dep-conf) (error (format #f "File ~a does not exist. This usually means the dependency ~a is missing. Was checking conf-file ~a." dep-conf id conf-file))) - (copy-file dep-conf dep-conf*) ;XXX: maybe symlink instead? - (loop (vhash-cons id #t seen) - (append lst (conf-depends dep-conf)))) + (copy-file dep-conf dep-conf*) ;XXX: maybe symlink instead? + (loop (vhash-cons id #t seen) + (append lst (conf-depends dep-conf))))) (loop seen tail)))))) + (define (install-config-file conf-file dest output:doc output:lib) + ;; Copy CONF-FILE to DEST removing reference to OUTPUT:DOC from + ;; OUTPUT:LIB and using install-transitive-deps. + (let* ((contents (call-with-input-file conf-file read-string)) + (id-rx (make-regexp "^id:[ \n\t]+([^ \t\n]+)$" regexp/newline)) + (config-file-name+id + (match:substring (first (list-matches id-rx contents)) 1))) + + (when (or + (and + (string? config-file-name+id) + (string-null? config-file-name+id)) + (not config-file-name+id)) + (error (format #f "The package id for ~a is empty. This is a bug." conf-file))) + + ;; Remove reference to "doc" output from "lib" (or "out") by rewriting the + ;; "haddock-interfaces" field and removing the optional "haddock-html" + ;; field in the generated .conf file. + (when output:doc + (substitute* conf-file + (("^haddock-html: .*") "\n") + (((format #f "^haddock-interfaces: ~a" output:doc)) + (string-append "haddock-interfaces: " output:lib))) + ;; Move the referenced file to the "lib" (or "out") output. + (match (find-files output:doc "\\.haddock$") + ((haddock-file . rest) + (let* ((subdir (string-drop haddock-file (string-length output:doc))) + (new (string-append output:lib subdir))) + (mkdir-p (dirname new)) + (rename-file haddock-file new))) + (_ #f))) + (install-transitive-deps conf-file %tmp-db-dir dest) + (rename-file conf-file + (string-append dest "/" + config-file-name+id ".conf")))) + (let* ((out (assoc-ref outputs "out")) (doc (assoc-ref outputs "doc")) (haskell (assoc-ref inputs "haskell")) @@ -231,7 +269,6 @@ (define (install-transitive-deps conf-file src dest) (config-dir (string-append lib "/ghc-" version "/" name ".conf.d")) - (id-rx (make-regexp "^id:[ \n\t]+([^ \t\n]+)$" regexp/newline)) (config-file (string-append out "/" name ".conf")) (params (list (string-append "--gen-pkg-config=" config-file)))) @@ -239,39 +276,13 @@ (define (install-transitive-deps conf-file src dest) ;; The conf file is created only when there is a library to register. (when (file-exists? config-file) (mkdir-p config-dir) - (let* ((contents (call-with-input-file config-file read-string)) - (config-file-name+id (match:substring (first (list-matches id-rx contents)) 1))) - - (when (or - (and - (string? config-file-name+id) - (string-null? config-file-name+id)) - (not config-file-name+id)) - (error (format #f "The package id for ~a is empty. This is a bug." config-file))) - - ;; Remove reference to "doc" output from "lib" (or "out") by rewriting the - ;; "haddock-interfaces" field and removing the optional "haddock-html" - ;; field in the generated .conf file. - (when doc - (substitute* config-file - (("^haddock-html: .*") "\n") - (((format #f "^haddock-interfaces: ~a" doc)) - (string-append "haddock-interfaces: " lib))) - ;; Move the referenced file to the "lib" (or "out") output. - (match (find-files doc "\\.haddock$") - ((haddock-file . rest) - (let* ((subdir (string-drop haddock-file (string-length doc))) - (new (string-append lib subdir))) - (mkdir-p (dirname new)) - (rename-file haddock-file new))) - (_ #f))) - (install-transitive-deps config-file %tmp-db-dir config-dir) - (rename-file config-file - (string-append config-dir "/" - config-file-name+id ".conf")) - (invoke "ghc-pkg" - (string-append "--package-db=" config-dir) - "recache"))))) + (if (file-is-directory? config-file) + (for-each (cut install-config-file <> config-dir doc lib) + (find-files config-file)) + (install-config-file config-file config-dir doc lib)) + (invoke "ghc-pkg" + (string-append "--package-db=" config-dir) + "recache")))) (define* (check #:key tests? test-target #:allow-other-keys) "Run the test suite of a given Haskell package."