From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mp2 ([2001:41d0:8:6d80::]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)) by ms0.migadu.com with LMTPS id 975FKMcsrWCpRQEAgWs5BA (envelope-from ) for ; Tue, 25 May 2021 18:58:47 +0200 Received: from aspmx1.migadu.com ([2001:41d0:8:6d80::]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)) by mp2 with LMTPS id cD9LI8csrWCJCgAAB5/wlQ (envelope-from ) for ; Tue, 25 May 2021 16:58:47 +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 A961718904 for ; Tue, 25 May 2021 18:58:46 +0200 (CEST) Received: from localhost ([::1]:34424 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1llaOD-0008CF-NA for larch@yhetil.org; Tue, 25 May 2021 12:58:45 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:32988) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1llYg2-0007Fk-8H for bug-guix@gnu.org; Tue, 25 May 2021 11:09:02 -0400 Received: from debbugs.gnu.org ([209.51.188.43]:35011) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1llYg2-0007yU-0e for bug-guix@gnu.org; Tue, 25 May 2021 11:09:02 -0400 Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1llYg1-00013O-Q4 for bug-guix@gnu.org; Tue, 25 May 2021 11:09:01 -0400 X-Loop: help-debbugs@gnu.org Subject: bug#48331: [PATCH draft] build-system: emacs: Generate -pkg.el file in case it is missing Resent-From: Leo Prikler Original-Sender: "Debbugs-submit" Resent-CC: bug-guix@gnu.org Resent-Date: Tue, 25 May 2021 15:09:01 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: followup 48331 X-GNU-PR-Package: guix X-GNU-PR-Keywords: To: Andrew Tropin Received: via spool by 48331-submit@debbugs.gnu.org id=B48331.16219552833984 (code B ref 48331); Tue, 25 May 2021 15:09:01 +0000 Received: (at 48331) by debbugs.gnu.org; 25 May 2021 15:08:03 +0000 Received: from localhost ([127.0.0.1]:46557 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1llYf4-000120-MA for submit@debbugs.gnu.org; Tue, 25 May 2021 11:08:03 -0400 Received: from mailrelay.tugraz.at ([129.27.2.202]:6367) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1llYf1-00011c-8B for 48331@debbugs.gnu.org; Tue, 25 May 2021 11:08:01 -0400 Received: from [10.0.0.4] (91-114-247-246.adsl.highway.telekom.at [91.114.247.246]) by mailrelay.tugraz.at (Postfix) with ESMTPSA id 4FqHWZ0775z3xP9; Tue, 25 May 2021 17:07:53 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=tugraz.at; s=mailrelay; t=1621955274; bh=At0E0qzFCYUqWTQ68PHAqEfCikenyxtNnDKkQWXbSdc=; h=Subject:From:To:Cc:Date:In-Reply-To:References; b=uENmhvuhmn2a+nNGIIJMvT0Qv2Zhjdj8ZcyR2nYyg0ijUntpVare9LSpkOTHy207Z JpztWqQgkXADARJ/gHulbd+UQujxhA7VEHRBhq5dhmAOv1Rfif86b5LpTuYVe7hlTd Tl24qgnlwfd/XuqzmOqlbVF2FkZ20X/0+dJbbT8E= Message-ID: From: Leo Prikler Date: Tue, 25 May 2021 17:07:28 +0200 In-Reply-To: References: <20210522125428.12859-1-leo.prikler@student.tugraz.at> <20210522125428.12859-2-leo.prikler@student.tugraz.at> Content-Type: text/plain; charset="UTF-8" User-Agent: Evolution 3.34.2 MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-TUG-Backscatter-control: bt4lQm5Tva3SBgCuw0EnZw X-Spam-Scanner: SpamAssassin 3.003001 X-Spam-Score-relay: -1.9 X-Scanned-By: MIMEDefang 2.74 on 129.27.10.117 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: 48331@debbugs.gnu.org, Maxim Cournoyer Errors-To: bug-guix-bounces+larch=yhetil.org@gnu.org Sender: "bug-Guix" X-Migadu-Flow: FLOW_IN ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=yhetil.org; s=key1; t=1621961927; h=from:from:sender:sender: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:resent-cc: resent-from:resent-sender:resent-message-id:in-reply-to:in-reply-to: references:references:list-id:list-help:list-unsubscribe: list-subscribe:list-post:dkim-signature; bh=At0E0qzFCYUqWTQ68PHAqEfCikenyxtNnDKkQWXbSdc=; b=fq7hcQloHnjZpP6bWUycuc/xg8jsMt37tQbK5qY4d92ZsCReo8MNEwk0XrOkww2ibHe9Fe JRdzx+Vtg0Gr0xIMpdBYEugqtfMCgEcXzXu+T18BWgEkL4NU2KB2zpLaW2sJubNdTDikC6 86W6/CQeZ6Jkcfu9duwbRuNtIqqOctcaJ2LnsZta7wX26Dv8HMHQEqgh/iOPdekaXSVbAO 37yvFmfUgR321RvW+TCfFhqhtc3znEXvUfn1UWh9jxUz5sA2uTOS6S9nAIQNFiJ23B4pdT Djan+GpFBWPtbrlSXL4p6oS1JH7RDKXV4QPUwwEe17+ahxQfs5CLlsND5/57Yw== ARC-Seal: i=1; s=key1; d=yhetil.org; t=1621961927; a=rsa-sha256; cv=none; b=EELZKvRQlYnGdnft4eFNloz+YI+ZRHy1colkzz3r+H7Tj2UxPa1/JDSf5TMfaC8JPIyHxx wbFP1ps+Qlt9gwlTRuAIDQun2wrftg3DQe7EGdHPgZW4wXEUHSSxSk0PSHcKJ0gF1GAjiC 9JAX3EPm2ySgWRPCktyv4FqVo0MzVdjtvlu356rw6LpGjEUIL/rSQkWCntoI5SGZbSUpMs /orfpQIMcJ3cSR9jtYfJr4vSj0F4umF186FXYyv9uleKJbXyGUB1KJY0d6xBgFSrp54Pho KNkEOECKBOJ8USMerOJgoE/x/optNt+9vk2NVNzEJIYI4ILUvVhPVMaXARn01w== ARC-Authentication-Results: i=1; aspmx1.migadu.com; dkim=fail ("headers rsa verify failed") header.d=tugraz.at header.s=mailrelay header.b=uENmhvuh; dmarc=fail reason="SPF not aligned (relaxed)" header.from=student.tugraz.at (policy=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-Spam-Score: 0.17 Authentication-Results: aspmx1.migadu.com; dkim=fail ("headers rsa verify failed") header.d=tugraz.at header.s=mailrelay header.b=uENmhvuh; dmarc=fail reason="SPF not aligned (relaxed)" header.from=student.tugraz.at (policy=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: A961718904 X-Spam-Score: 0.17 X-Migadu-Scanner: scn0.migadu.com X-TUID: mSc+VZ5sZoN3 Am Dienstag, den 25.05.2021, 16:40 +0300 schrieb Andrew Tropin: > --- > Thank you for the patches, tested, works for me! The solution is > much more precise than mutating package-directory-list variable, good > job. I don't see any major problems in the implementation (but I'm > not very fluent elisp dev and maybe missing something). Don't worry, I can wait for a proper review by some of our experts, since we shouldn't mess with emacs-build-system all too often anyway :P > I drafted a simple build phase, which generates -pkg.el in case it is > missing. > > There are at least a few problems with this implementation: > > 1. There is no information about package record available during > build, which makes it hard to get package name and package > version. I can't use any regexp to obtain this information from name > or elpa-name-ver, because package name and version can have > arbitrary form: comment-dwim-2-1.0, cyberpunk-2019-theme-20191008- > alpha or something like that. > 2. It's also not so easy to extract description of the package from > somewhere, the first option is to pass package record to build phases > somehow, another is to parse PACKAGE-NAME.el file comments section. > 3. This one I consider as a minor flaw: there is no generic solution > for packages built with build systems other than emacs-build-system. 3. is easy -- just have those packages call the phase through emacs- build-system. There already exist packages which do that, and it should be pretty straightforward to do. For 1. and 2. I think you're thinking a little too complicated. We can call Emacs at build time. In particular, we can use all of the lisp- mnt stuff, that I used in emacs-dpd at build time, we just need to write the (define-package ...) form to disk. In order to pick the right file, we can either use package-name (see discussion below) or the name of the pkg-file without -pkg. Come to think about it, we might also provide #:pkg-file-name as a keyword and only generate the package file if it's set to a value other than #f, i.e. let the packager choose whether they want to generate a -pkg.el file. Something along this line is done with the build.xml of ant- build-system. > So, this patch is very dirty and I publish it only for future > reference. > > The intuition says that we should split name and version in build > phase arguments, also it seems that it will be useful to provide > other information about package during build time for cases like this > one. I'll learn this area a bit more and probably will make another > thread someday. IIRC, there's a demand for having package-name and package-version available during build (which might get through next core-updates or might not -- we'll see), but I don't think we can argue for description, especially when the Guix description might not be the thing package.el wants here. > guix/build/emacs-build-system.scm | 60 > ++++++++++++++++++++++++++++++- > 1 file changed, 59 insertions(+), 1 deletion(-) > > diff --git a/guix/build/emacs-build-system.scm > b/guix/build/emacs-build-system.scm > index f13162d6c4..2bb102b4be 100644 > --- a/guix/build/emacs-build-system.scm > +++ b/guix/build/emacs-build-system.scm > @@ -116,6 +116,63 @@ environment variable\n" source-directory)) > (parameterize ((%emacs emacs)) > (emacs-byte-compile-directory (elpa-directory out))))) > > + > +(define* (add-pkg-file-if-missing #:key name outputs #:allow-other- > keys > + #:rest args) > + "Generate simple -pkg.el in case package doesn't have it in source > code." > + (define (file-contains-nul-char? file) > + (call-with-input-file file > + (lambda (in) > + (let loop ((line (read-line in 'concat))) > + (cond > + ((eof-object? line) #f) > + ((string-index line #\nul) #t) > + (else (loop (read-line in 'concat)))))) > + #:binary #t)) > + > + (let* ((out (assoc-ref outputs "out")) > + (el-dir (elpa-directory out)) > + (elpa-name-ver (store-directory->elpa-name-version out)) > + (el-files (remove file-contains-nul-char? > + (find-files (getcwd) "\\.el$"))) > + (el-names (map (lambda (x) (basename x ".el")) el-files)) > + > + (possible-names > + (fold (lambda (x acc) > + (cons > + (string-append > + (if (not (null? acc)) (string-append (first acc) > "-") "") > + x) > + acc)) > + '() > + (string-split elpa-name-ver #\-))) > + > + (package-names (append-map > + (lambda (name) > + (let ((m (member name el-names))) > + (if m (list (car m)) '()))) > + possible-names)) > + > + (package-name (if (null? package-names) "" (car package- > names))) > + (package-version (string-drop elpa-name-ver > + (1+ (string-length package- > name)))) > + (package-description "description should be here") > + (pkg-file (string-append el-dir "/" package-name "- > pkg.el"))) > + > + (when (not (file-exists? pkg-file)) > + (with-output-to-file pkg-file > + (lambda () > + (format > + #t > + "\ > +(define-package > + ~s > + ~s > + ~s > + nil)" > + package-name package-version package-description)))) > + #t)) > + > (define* (patch-el-files #:key outputs #:allow-other-keys) > "Substitute the absolute \"/bin/\" directory with the right > location in the > store in '.el' files." > @@ -293,8 +350,9 @@ for libraries following the ELPA convention." > (add-after 'make-autoloads 'enable-autoloads-compilation > enable-autoloads-compilation) > (add-after 'enable-autoloads-compilation 'patch-el-files patch- > el-files) > + (add-after 'patch-el-files 'add-pkg-file-if-missing > add-pkg-file-if-missing) > ;; The .el files are byte compiled directly in the store. > - (add-after 'patch-el-files 'build build) > + (add-after 'add-pkg-file-if-missing 'build build) > (add-after 'build 'validate-compiled-autoloads validate- > compiled-autoloads) > (add-after 'validate-compiled-autoloads 'move-doc move-doc))) >