From patchwork Thu Apr 21 16:46:18 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Olivier Dion X-Patchwork-Id: 38729 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 353AB27BBEA; Thu, 21 Apr 2022 18:15:33 +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=-2.7 required=5.0 tests=BAYES_00,DKIM_INVALID, DKIM_SIGNED,MAILING_LIST_MULTI,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 D665D27BBE9 for ; Thu, 21 Apr 2022 18:15:32 +0100 (BST) Received: from localhost ([::1]:57752 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1nhaOx-0006vQ-V0 for patchwork@mira.cbaines.net; Thu, 21 Apr 2022 13:15:31 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:36714) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1nhZxO-0007cb-C8 for guix-patches@gnu.org; Thu, 21 Apr 2022 12:47:02 -0400 Received: from debbugs.gnu.org ([209.51.188.43]:56977) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1nhZxO-00045g-1v for guix-patches@gnu.org; Thu, 21 Apr 2022 12:47:02 -0400 Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1nhZxO-0006c6-0Z for guix-patches@gnu.org; Thu, 21 Apr 2022 12:47:02 -0400 X-Loop: help-debbugs@gnu.org Subject: [bug#54780] [PATCH v3 1/2] guix: build: Add absolute-inclusions.scm. Resent-From: Olivier Dion Original-Sender: "Debbugs-submit" Resent-CC: guix-patches@gnu.org Resent-Date: Thu, 21 Apr 2022 16:47:01 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: followup 54780 X-GNU-PR-Package: guix-patches X-GNU-PR-Keywords: patch To: Olivier Dion , Maxime Devos , 54780@debbugs.gnu.org Received: via spool by 54780-submit@debbugs.gnu.org id=B54780.165055960025383 (code B ref 54780); Thu, 21 Apr 2022 16:47:01 +0000 Received: (at 54780) by debbugs.gnu.org; 21 Apr 2022 16:46:40 +0000 Received: from localhost ([127.0.0.1]:50873 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1nhZx2-0006bF-5l for submit@debbugs.gnu.org; Thu, 21 Apr 2022 12:46:40 -0400 Received: from smtp.polymtl.ca ([132.207.4.11]:45305) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1nhZwz-0006an-Tw for 54780@debbugs.gnu.org; Thu, 21 Apr 2022 12:46:38 -0400 Received: from laura.hitronhub.home (modemcable094.169-200-24.mc.videotron.ca [24.200.169.94]) (authenticated bits=0) by smtp.polymtl.ca (8.14.7/8.14.7) with ESMTP id 23LGkKu2010843 (version=TLSv1/SSLv3 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128 verify=NOT); Thu, 21 Apr 2022 12:46:31 -0400 DKIM-Filter: OpenDKIM Filter v2.11.0 smtp.polymtl.ca 23LGkKu2010843 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=polymtl.ca; s=default; t=1650559591; bh=DD9Q7m+L/u10NxJnCR8H9+eVgEJL4wwdYTJimOPhWt0=; h=From:To:Subject:Date:In-Reply-To:References:From; b=ngtsyiBbSK1153aB4MtvHgY4hxUgKQavR+47iNqCjpjPNwPUphjn4TePuzkYqZqFq Kxs58RfGNQ4vI0WbIrBeNjf0GAVf8naWpSWom8J9GfS83SGJKBdNXno9j4rj7xJG9y UoY2kLECDoEaNKN7JiJlg0H/eT4ipbXlMN80dHac= Date: Thu, 21 Apr 2022 12:46:18 -0400 Message-Id: X-Mailer: git-send-email 2.35.1 In-Reply-To: <4b19827ee0d266ecd80dc7c5d776f3ffd764a575.1649459701.git.olivier.dion@polymtl.ca> References: <4b19827ee0d266ecd80dc7c5d776f3ffd764a575.1649459701.git.olivier.dion@polymtl.ca> MIME-Version: 1.0 X-Poly-FromMTA: (modemcable094.169-200-24.mc.videotron.ca [24.200.169.94]) at Thu, 21 Apr 2022 16:46:20 +0000 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" Reply-to: Olivier Dion X-ACL-Warn: , Olivier Dion via Guix-patches X-Patchwork-Original-From: Olivier Dion via Guix-patches via From: Olivier Dion X-getmail-retrieved-from-mailbox: Patches * guix/build/absolute-inclusions.scm: New file. * Makefile.am (MODULES): Add it here. --- Makefile.am | 1 + guix/build/absolute-inclusions.scm | 59 ++++++++++++++++++++++++++++++ 2 files changed, 60 insertions(+) create mode 100644 guix/build/absolute-inclusions.scm diff --git a/Makefile.am b/Makefile.am index fecce7c6f7..394df67016 100644 --- a/Makefile.am +++ b/Makefile.am @@ -181,6 +181,7 @@ MODULES = \ guix/diagnostics.scm \ guix/ui.scm \ guix/status.scm \ + guix/build/absolute-inclusions.scm \ guix/build/android-ndk-build-system.scm \ guix/build/ant-build-system.scm \ guix/build/download.scm \ diff --git a/guix/build/absolute-inclusions.scm b/guix/build/absolute-inclusions.scm new file mode 100644 index 0000000000..34aecf198a --- /dev/null +++ b/guix/build/absolute-inclusions.scm @@ -0,0 +1,59 @@ +;;; GNU Guix --- Functional package management for GNU +;;; Copyright © 2022 Maxime Devos +;;; Copyright © 2022 Olivier Dion +;;; +;;; This file is part of GNU Guix. +;;; +;;; GNU Guix is free software; you can redistribute it and/or modify it +;;; under the terms of the GNU General Public License as published by +;;; the Free Software Foundation; either version 3 of the License, or (at +;;; your option) any later version. +;;; +;;; GNU Guix is distributed in the hope that it will be useful, but +;;; WITHOUT ANY WARRANTY; without even the implied warranty of +;;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +;;; GNU General Public License for more details. +;;; +;;; You should have received a copy of the GNU General Public License +;;; along with GNU Guix. If not, see . + +(define-module (guix build absolute-inclusions) + #:use-module (guix build utils) + #:use-module (ice-9 match) + #:use-module (rnrs exceptions) + #:export (absolute-inclusions patch-header-inclusions)) + +(define (absolute-inclusions files header-locations) + (substitute* files + (("^[ \t]*#[ \t]*include[ \t]*<(.*)>[ \t]*" original header-name) + (guard (c ((search-error? c) original)) + (format #f "#include <~a>" + (search-input-file header-locations + (string-append "include/" header-name))))))) + +(define header-file? + ;; See gcc(1) for the list of suffixes. + (let ((suffixes (list "h" "hh" "H" "hp" "hxx" "hpp" "HPP" "h++" "tcc"))) + (file-name-predicate + (format #f "\\.(~a)$" (string-join suffixes "|" 'infix))))) + +(define (excluded-input? input) + ;; Exclude glibc to avoid increasing the closure size when a + ;; static library + binary is build. Likewise, exclude + ;; linux-libre-headers. + (match input + ((_ . store-item) + (or (file-exists? (string-append store-item "/include/stdlib.h")) + (directory-exists? (string-append store-item "/include/linux")))))) + +(define* (patch-header-inclusions #:key inputs outputs #:allow-other-keys) + "Patch inclusions in C headers in OUTPUTS to use absolute file names." + (define header-locations + (filter (negate excluded-input?) (append outputs inputs))) + (for-each (match-lambda + ((_ . output) + (absolute-inclusions + (find-files (string-append output "/include") + header-file?) + header-locations))) + outputs))