From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mp0 ([2001:41d0:8:6d80::]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)) by ms0.migadu.com with LMTPS id qAfvLjwLrWAb/QAAgWs5BA (envelope-from ) for ; Tue, 25 May 2021 16:35:40 +0200 Received: from aspmx1.migadu.com ([2001:41d0:8:6d80::]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)) by mp0 with LMTPS id 0KafKjwLrWBvKwAA1q6Kng (envelope-from ) for ; Tue, 25 May 2021 14:35:40 +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 0674F15D5A for ; Tue, 25 May 2021 16:35:40 +0200 (CEST) Received: from localhost ([::1]:55568 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1llY9i-00019D-Jh for larch@yhetil.org; Tue, 25 May 2021 10:35:38 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:36200) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1llXJq-0005ng-Q8 for bug-guix@gnu.org; Tue, 25 May 2021 09:42:02 -0400 Received: from debbugs.gnu.org ([209.51.188.43]:33486) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1llXJq-0003yY-Ii for bug-guix@gnu.org; Tue, 25 May 2021 09:42:02 -0400 Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1llXJq-0006oS-EM for bug-guix@gnu.org; Tue, 25 May 2021 09:42:02 -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: Andrew Tropin Original-Sender: "Debbugs-submit" Resent-CC: bug-guix@gnu.org Resent-Date: Tue, 25 May 2021 13:42:02 +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: Leo Prikler Received: via spool by 48331-submit@debbugs.gnu.org id=B48331.162195006926130 (code B ref 48331); Tue, 25 May 2021 13:42:02 +0000 Received: (at 48331) by debbugs.gnu.org; 25 May 2021 13:41:09 +0000 Received: from localhost ([127.0.0.1]:45032 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1llXIx-0006nM-UB for submit@debbugs.gnu.org; Tue, 25 May 2021 09:41:09 -0400 Received: from mail-qk1-f176.google.com ([209.85.222.176]:35340) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1llXIs-0006mg-5d for 48331@debbugs.gnu.org; Tue, 25 May 2021 09:41:06 -0400 Received: by mail-qk1-f176.google.com with SMTP id j189so9571283qkf.2 for <48331@debbugs.gnu.org>; Tue, 25 May 2021 06:41:02 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=trop-in.20150623.gappssmtp.com; s=20150623; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc; bh=IP9zXvyExMGat+L1Fz8jYw+uYo3aND9KVPNuqiPYU/s=; b=aDhzNAgT1IsM8W9O4qQBTP1hFkPfVqgJz/LI8IFnMp/pMFilNHBgYQrCSHn0ldlqlb Gp42TjPHMsfUcGWrxtd5qPmsAis4XOMpJ/vCmZFUn+6squ6TDIVL7xd69pgGCK4qUF30 rX+Xf/nYqsCPAh+ZzBfBgn43lCX/yF7/EwRGDyvuJI0x2Rx4Kngdv/52rKeY9VXiQU5H 3X/zqWUKVvXmr5g6blUX+nG+i57QoyL9SOfNy9vUTZzyVWJCdKBraDrOhdPh0x7MGg5g e2twhSS2amx2NjUSY3GA8evpmV84jiG43/sQfYInSjwqMTeheRCMwqLBPn65upKyDavE Yw4w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc; bh=IP9zXvyExMGat+L1Fz8jYw+uYo3aND9KVPNuqiPYU/s=; b=URDb8XdQ9FiP/hN6nOw+nMKlzVJ3G6EiZ7F4pQshYxIK2UMnmb+bQNZPQEafiVBLWX a3PHUmEr3HeQLPcxLwH8aCNDxew4My9EudaHhVBjrF/U/uNS5JAWYghj1o11rVXS2/cY /h+qMtwitLxZQDwU7rq9eDIVkqfnjAhE/TuMEgfYvdjNW9F18lftTs4Ip4iO6u3oKIaz We5eftQW2KCSAMIP6yt7ZQ7FLWj4Q7KZnP/Yx90K3W/+tL0W6a3FS+Sq5feLWdJ7RvHt w1xDaCTje/Y30FezKrqZXnrTpGzTKXwsmZYMo3/Y9wNoULdxH7cXgswScX/+PjbU30a0 pxVg== X-Gm-Message-State: AOAM530PbjvEe5l2Etw+9VoZTWYq2bKPw7UidnXQopx3ANSHtFlk6ccW LPZCgusz6RVH4m0BgKSlPPrEKkvV93GAqdNJvWozPg== X-Google-Smtp-Source: ABdhPJwHS3WeM1Ia3WH86EcuhCMjq5iL8KULMsvUna/rFmM2r7E+IPH2PHmj3bwg+MPgQQXcLTGtq3jXqzYqjBSp7TE= X-Received: by 2002:a37:6645:: with SMTP id a66mr36588081qkc.314.1621950056405; Tue, 25 May 2021 06:40:56 -0700 (PDT) MIME-Version: 1.0 References: <20210522125428.12859-1-leo.prikler@student.tugraz.at> <20210522125428.12859-2-leo.prikler@student.tugraz.at> In-Reply-To: <20210522125428.12859-2-leo.prikler@student.tugraz.at> From: Andrew Tropin Date: Tue, 25 May 2021 16:40:45 +0300 Message-ID: Content-Type: text/plain; charset="UTF-8" X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list X-Mailman-Approved-At: Tue, 25 May 2021 10:30:43 -0400 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=1621953340; 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: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=IP9zXvyExMGat+L1Fz8jYw+uYo3aND9KVPNuqiPYU/s=; b=HrQ/eOS/2uXddmRbHfxyq85bQ87y7cwRM58AJR9ByEpj3EafqndANjO0cYS0QsDSrC1J9c Zw8sZmgKbHayEPxUk2aUcgAPzw1a05dWDttk1+T/4cIvgTh2dfuUzlXQPB1da0RsIRWT+8 9MIyzOH5QnmDAydVICU0r2KwJlX+qWABNdyqyzTlsoGh1WNPBLd+Y6oi2681Rh+t4ibW0Z 930zodlglaPuZU5Srp+p0WPTq0L7fq3dmdaoSFYkeg/MPJ9psRzzvnP00L9umrpADjyPkC Ki8ik2kIZXCqF7N+KR2O8cxMpPoPb+BJ8QrdsO0oMYpHjN4BytSH6NE6d0n0YA== ARC-Seal: i=1; s=key1; d=yhetil.org; t=1621953340; a=rsa-sha256; cv=none; b=XpQTH5e38tBnPr/iEp1mXAu9bwEancivUd+7wctEG/QcBg6rkhF+74/AzgUbJKDElgUGSp q/5JjY4MELwziTdM22QBdZHa8Zd2Ywna1cetsJUVlj+EvU5jzB5FL7GUNBHhIusTBpfr/W rSs5d1L8ukpXS4GL8UELkBuKOArzbFaECra0I7h3gKg0t+zl8UElE781g3NpEIp+erR7Af FuZjm/TU7S36+ZDkI2b8Ule42Ilz2jeT2pAgjBZD4ZbrZiaMQWnNbR2meIrOCMnesu3VUP 2jAPMij/0LOsQ8i/BfdXv+TyzMRwa3fM4922B3MfHPJYaf2hqdOMvwL2dT34Lw== ARC-Authentication-Results: i=1; aspmx1.migadu.com; dkim=fail ("headers rsa verify failed") header.d=trop-in.20150623.gappssmtp.com header.s=20150623 header.b=aDhzNAgT; 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.07 Authentication-Results: aspmx1.migadu.com; dkim=fail ("headers rsa verify failed") header.d=trop-in.20150623.gappssmtp.com header.s=20150623 header.b=aDhzNAgT; dmarc=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: 0674F15D5A X-Spam-Score: 0.07 X-Migadu-Scanner: scn0.migadu.com X-TUID: 5nM2l0m6gfFe --- 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). 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. 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. 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))) -- 2.31.1