[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[elpa] scratch/pq-compile 55adb18a91: Try and compile `pq-core` automati
From: |
Stefan Monnier |
Subject: |
[elpa] scratch/pq-compile 55adb18a91: Try and compile `pq-core` automatically for the user |
Date: |
Sun, 29 May 2022 17:30:59 -0400 (EDT) |
branch: scratch/pq-compile
commit 55adb18a91fed6cf55c254bf2e9999d13918318a
Author: Stefan Monnier <monnier@iro.umontreal.ca>
Commit: Stefan Monnier <monnier@iro.umontreal.ca>
Try and compile `pq-core` automatically for the user
* pq.el: Activate lexical-binding. Fix Author's email address.
Don't signal an error if `pq-core` cannot be found yet.
Try to compile `pq-core` when this file is compiled or when this file
is loaded.
* pq-compile.el: New file.
* .gitignore: New file.
---
.elpaignore | 1 +
.gitignore | 3 +++
pq-compile.el | 61 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
pq.el | 24 ++++++++++++++++++++---
4 files changed, 86 insertions(+), 3 deletions(-)
diff --git a/.elpaignore b/.elpaignore
new file mode 100644
index 0000000000..98e124b921
--- /dev/null
+++ b/.elpaignore
@@ -0,0 +1 @@
+test.el
diff --git a/.gitignore b/.gitignore
index 9f8c20a9e2..2c16467025 100644
--- a/.gitignore
+++ b/.gitignore
@@ -1,4 +1,7 @@
*.so
#*#
+*.elc
+/pq-autoloads.el
+/pq-pkg.el
diff --git a/pq-compile.el b/pq-compile.el
new file mode 100644
index 0000000000..574aa4c0bc
--- /dev/null
+++ b/pq-compile.el
@@ -0,0 +1,61 @@
+;;; pq-compile.el --- Compile the `pq-core` module -*- lexical-binding: t;
-*-
+
+;; Copyright (C) 2022 Free Software Foundation, Inc.
+
+;; Author: Stefan Monnier <monnier@iro.umontreal.ca>
+;; Keywords:
+
+;; This program 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.
+
+;; This program 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 this program. If not, see <https://www.gnu.org/licenses/>.
+
+;;; Commentary:
+
+;;
+
+;;; Code:
+
+(defvar pq--compile-directory
+ (file-name-directory
+ (or
+ (if (fboundp 'macroexp-file-name) (macroexp-file-name)) ;Emacs≥28
+ load-file-name
+ buffer-file-name
+ (locate-library "pq"))))
+
+(defun pq--compile-module ()
+ "Compile the `pq-core' module."
+ (with-temp-buffer
+ (setq default-directory pq--compile-directory)
+ (let* ((exitcode (call-process "make" nil t)))
+ (if (zerop exitcode)
+ (message "Compilation of `pq-core' succeeded")
+ (let ((out (buffer-string)))
+ (with-current-buffer (get-buffer-create "*pq-compile*")
+ (setq default-directory pq--compile-directory)
+ (let ((inhibit-read-only t))
+ (erase-buffer)
+ (insert out))
+ (compilation-mode)
+ (pop-to-buffer (current-buffer))
+ (error "Compilation of `pq-core' failed")))))))
+
+(defun pq--compile-maybe ()
+ ;; FIXME: Should we first try it silently (i.e. without prompting the user)?
+ (if (not (y-or-n-p "PQ needs to compile the `pq-core' module. Do it now?"))
+ (message "Continuing without `pq-core'; some operations may fail")
+ (pq--compile-module)
+ (require 'pq-core)))
+
+
+(provide 'pq-compile)
+;;; pq-compile.el ends here
diff --git a/pq.el b/pq.el
index b7a943355b..796c09ced7 100644
--- a/pq.el
+++ b/pq.el
@@ -1,8 +1,8 @@
-;;; pq.el --- libpq binding
+;;; pq.el --- libpq binding -*- lexical-binding: t; -*-
;; Copyright (C) 2020-2022 Free Software Foundation, Inc.
-;; Author: Tom Gillespie
+;; Author: Tom Gillespie <tgbugs@gmail.com>
;; URL: https://github.com/anse1/emacs-libpq
;; Version: 0.01
;; Package-Requires: ((emacs "25"))
@@ -26,7 +26,25 @@
;;; Code:
-(if t (require 'pq-core))
+(require 'pq-core nil t) ;Don't signal an error if the module is absent.
+
+;; Try and compile the `pq-core' module when we compile the PQ package.
+(eval-when-compile
+ (unless (or (featurep 'pq-core)
+ ;; Try and avoid running this code when we're just
+ ;; loading the uncompiled `pq.el'.
+ (and (fboundp 'macroexp-compiling-p) ;Emacs≥28
+ (not (macroexp-compiling-p))))
+ (require 'pq-compile)
+ (declare-function pq--compile-module "pq-compile" ())
+ (ignore-errors (pq--compile-module))))
+
+;; Try and compile the `pq-core' module when the PQ package is loaded.
+(unless (featurep 'pq-core)
+ (require 'pq-compile)
+ (declare-function pq--compile-maybe "pq-compile" ())
+ (pq--compile-maybe))
+
(provide 'pq)