From: Ergus <spacibba@aol.com>
To: Dmitry Gutov <dmitry@gutov.dev>
Cc: emacs-devel@gnu.org
Subject: [PATCH] Project out of sources compilation
Date: Wed, 27 Mar 2024 17:38:48 +0100 [thread overview]
Message-ID: <yj4fb4r46rrkmkukeoly467t47itjdok3w7hka523lm5pl324z@5utfgnn5ulf6> (raw)
In-Reply-To: <jhgkhjrhk5x3jxhi33t2hguounlnqxucjpid5m6rogzmpk5a45@nvbsrdlhbnbw>
[-- Attachment #1: Type: text/plain, Size: 6361 bytes --]
Hi:
Here I attach a very simple patch to allow project out of sources
compilation and project build detection.
So far I already implemented a very primitive backend [1] for project.el
using these features to detect and compile autotools and cmake projects;
and, at some point I will propose it for elpa.
But I need to work a bit more on it; and, of course, the functionalities
in the attached patch need to go to vanilla this way or some other
equivalent.
Best,
Ergus
[1] https://github.com/Ergus/project-multi-mode/blob/master/project-multi-mode.el
On Tue, Mar 19, 2024 at 07:36:35PM +0100, Ergus wrote:
>Hi Dmitry:
>
>Here I attach a very simple approach to add support for out of sources
>compilation in project.el
>
>This is just a POC, but to have some starting point to discuss.
>
>Best,
>Ergus
>
>
>
>On Sun, Mar 17, 2024 at 06:47:43PM +0100, Ergus wrote:
>>On Sun, Mar 17, 2024 at 12:36:44PM +0100, Augusto Stoffel wrote:
>>>On Sat, 16 Mar 2024 at 14:12, Ergus wrote:
>>>
>>>>5. Project local variables (a man can dream, a man can dream)
>>>>
>>>>There are some situations where we want to have variables shared among a
>>>>project. (i.e some output directory, logging option when executing,
>>>>flags, environment variables).
>>>>
>>>>At the moment these options work partially by using directory
>>>>variables. If we have the concept of a "project", maybe it is logical to
>>>>have some sort of project scope concept, specially for projects sharing
>>>>a common root.
>>>
>>>For Emacs variables, why you think dir-local variables only works
>>>“partially”?
>>>
>>>As to environment variables, they are generally assumed to be global in
>>>Emacs and it goes a bit against the grain to make them buffer-local /
>>>project dependent. Nonetheless, there are packages for that (one is
>>>buffer-env, which I wrote) and they work fine (at least for me).
>>>
>>They work for one directory, but when the project includes multiple
>>roots (project-external-roots) the variables are somehow missing just
>>when jumping with xref to a definition.
>>
>>However, we can ignore this as I mentioned before.
>>
>>>>For example vs-code adds a subdirectory with project variables that the
>>>>user (but also any plugin) can refer to in the project's scope.
>>>
>>>Is this meant to store editor configuration or environment variables? I
>>>guess turning VSCode configuration variables into Emacs alternatives
>>>would be tricky.
>>
>>No please. No interaction-importing from other editors will be
>>maintainable in the long path.
>>
>>>But if this is about env vars and the directory
>>>organization is sensible, then one could configure buffer-env to
>>>interoperate.
>>
>>This is it. The idea is to extend project.el in order to bring more
>>project-oriented features.
>>
>>Lets say:
>>
>>The user (or project.el backend) could specify the `build` directory and
>>the environment that needs to be set to execute the program from the
>>build or bin directory.
>>
>>So with a simple modification of dir-locals.el the user may be capable
>>to run M-x compile (or project-compile), M-x gud-gdb... or being more
>>ambitious M-x project-generate (to call autogen.sh and ./configure or
>>cmake depending of the project-backend)
>>
>>For sure we wont cover the 100% of the projects, but wuth automake and
>>autotools we will be very close (and in the future someone could add
>>other backends for it)
>>
>>
>>
>>
>>
>commit cfa10dfeac01ae25a7acd6857fae0b377b625779
>Author: Jimmy Aguilar Mena <kratsbinovish@gmail.com>
>Date: Tue Mar 19 17:57:25 2024 +0100
>
> Add basic project-build-dir implementation
>
> This is just a dummy prototype to discuss about alternatives.
>
>diff --git a/lisp/progmodes/project.el b/lisp/progmodes/project.el
>index ac18aceadcf..0ca4ca85566 100644
>--- a/lisp/progmodes/project.el
>+++ b/lisp/progmodes/project.el
>@@ -51,6 +51,9 @@
> ;; files inside the root must not be considered a part of it). It
> ;; should be consistent with `project-files'.
> ;;
>+;; `project-build-dir' can be overridden if the project backend has some
>+;; extra information about the project build directory.
>+;;
> ;; This list can change in future versions.
> ;;
> ;; Transient project:
>@@ -208,6 +211,12 @@ project-prompter
> :group 'project
> :version "30.1")
>
>+(defcustom project-build-dir nil
>+ "Build directory for current project."
>+ :type 'directory
>+ :safe t
>+ :version "30.1")
>+
> ;;;###autoload
> (defun project-current (&optional maybe-prompt directory)
> "Return the project instance in DIRECTORY, defaulting to `default-directory'.
>@@ -289,8 +298,30 @@ project-external-roots
> headers search path, load path, class path, and so on."
> nil)
>
>+(cl-defgeneric project-build-dir (_project)
>+ "Return build directory of the current PROJECT.
>+
>+This function is intended to be defined by the backend when possible.
>+Otherwise this returns nil and the `project-compile' command will be
>+called in the project-root.
>+If the user defines the directory-local variable `project-build-dir' it
>+will have precedence over the result of this function."
>+ nil)
>+
>+(defun project-get-build-dir (project)
>+ "Return build directory of the current PROJECT.
>+If the variable `project-build-dir' is defined, this function returns
>+it, otherwise it returns the project root. If the defined path is
>+relative, this expands it relatively to the project's root"
>+ (let ((dir (or project-build-dir
>+ (project-build-dir project)
>+ (project-root project)))) ;; I assume project-root is absolute
>+ (if (file-name-absolute-p dir)
>+ dir
>+ (expand-file-name dir (project-root project)))))
>+
> (cl-defgeneric project-name (project)
>- "A human-readable name for the project.
>+ "A human-readable name for the PROJECT.
> Nominally unique, but not enforced."
> (file-name-nondirectory (directory-file-name (project-root project))))
>
>@@ -1391,7 +1422,7 @@ project-compile
> "Run `compile' in the project root."
> (declare (interactive-only compile))
> (interactive)
>- (let ((default-directory (project-root (project-current t)))
>+ (let ((default-directory (project-get-build-dir (project-current t)))
> (compilation-buffer-name-function
> (or project-compilation-buffer-name-function
> compilation-buffer-name-function)))
[-- Attachment #2: project-compile.patch --]
[-- Type: text/plain, Size: 4160 bytes --]
diff --git a/lisp/progmodes/project.el b/lisp/progmodes/project.el
index ac18aceadcf..5a4274d6f68 100644
--- a/lisp/progmodes/project.el
+++ b/lisp/progmodes/project.el
@@ -51,6 +51,9 @@
;; files inside the root must not be considered a part of it). It
;; should be consistent with `project-files'.
;;
+;; `project-build-dir' can be overridden if the project backend has some
+;; extra information about the project build directory.
+;;
;; This list can change in future versions.
;;
;; Transient project:
@@ -208,6 +211,22 @@ project-prompter
:group 'project
:version "30.1")
+(defcustom project-build-dir nil
+ "Build directory for current project.
+This is the custom that the user could specify in dir-locals to override
+the option specified by the project's backend."
+ :type 'directory
+ :safe t
+ :version "30.1")
+
+(defcustom project-compile-command nil
+ "Build command for current project.
+This is the custom that the user could specify in dir-locals to override
+the option specified by the project's backend."
+ :type 'directory
+ :safe t
+ :version "30.1")
+
;;;###autoload
(defun project-current (&optional maybe-prompt directory)
"Return the project instance in DIRECTORY, defaulting to `default-directory'.
@@ -289,8 +308,42 @@ project-external-roots
headers search path, load path, class path, and so on."
nil)
+(cl-defgeneric project-build-dir (_project)
+ "Return build directory of the current PROJECT.
+
+This function is intended to be defined by the backend when possible.
+Otherwise this returns nil and the `project-compile' command will be
+called in the project-root.
+If the user defines the directory-local variable `project-build-dir' it
+will have precedence over the result of this function."
+ nil)
+
+(defun project-get-build-dir (project)
+ "Return build directory of the current PROJECT.
+1. If the variable `project-build-dir' is defined, this function returns
+it. 2. Else if the function `project-build-dir' return non-nil.
+3. else it return the project-root.
+If the defined path is relative, this expands it relatively to the
+project's root."
+ (let ((dir (or project-build-dir ;; variable for dir-locals or connection local vars
+ (project-build-dir project) ;; backend function
+ (project-root project)))) ;; I assume project-root is always absolute
+ (if (file-name-absolute-p dir)
+ dir
+ (expand-file-name dir (project-root project)))))
+
+(cl-defgeneric project-compile-command (_project)
+ "Return build command of the current PROJECT.
+
+This function is intended to be defined by the backend when possible.
+Otherwise this returns nil and the `project-compile' command will use
+the default `compile-command' value. If the user defines the
+directory-local variable `project-build-command' it will have preference
+over this function and this will be never called."
+ nil)
+
(cl-defgeneric project-name (project)
- "A human-readable name for the project.
+ "A human-readable name for the PROJECT.
Nominally unique, but not enforced."
(file-name-nondirectory (directory-file-name (project-root project))))
@@ -1391,10 +1444,16 @@ project-compile
"Run `compile' in the project root."
(declare (interactive-only compile))
(interactive)
- (let ((default-directory (project-root (project-current t)))
- (compilation-buffer-name-function
- (or project-compilation-buffer-name-function
- compilation-buffer-name-function)))
+ ;; I am wondering whenever we need to expand connection local
+ ;; variables at this point... maybe before or inside the let.
+ (let* ((project (project-current t))
+ (default-directory (project-get-build-dir project))
+ (compile-command (or project-compile-command
+ (project-compile-command project)
+ compile-command))
+ (compilation-buffer-name-function
+ (or project-compilation-buffer-name-function
+ compilation-buffer-name-function)))
(call-interactively #'compile)))
(defun project-recompile (&optional edit-command)
next prev parent reply other threads:[~2024-03-27 16:38 UTC|newest]
Thread overview: 57+ messages / expand[flat|nested] mbox.gz Atom feed top
[not found] <4wwljrdnra3bsloehioa46y24ozxajajmvf2elvskxxq3mhtg2.ref@pyv2z5snot6h>
2024-03-16 13:12 ` Project out of sources compilation Ergus
2024-03-16 16:50 ` Konstantin Kharlamov
2024-03-16 19:00 ` Ergus
2024-03-16 20:56 ` Konstantin Kharlamov
2024-03-17 2:53 ` Dmitry Gutov
2024-03-17 7:22 ` Ergus
2024-03-17 8:45 ` Eli Zaretskii
2024-03-17 17:33 ` Ergus
2024-03-17 17:38 ` Eli Zaretskii
2024-03-17 17:58 ` Ergus
2024-03-17 11:36 ` Augusto Stoffel
2024-03-17 17:47 ` Ergus
2024-03-19 18:36 ` Ergus
2024-03-27 16:38 ` Ergus [this message]
2024-03-31 2:41 ` [PATCH] " Dmitry Gutov
2024-03-31 21:07 ` Ergus
2024-04-01 7:49 ` Dirk-Jan C. Binnema
2024-04-01 13:52 ` Ergus
2024-04-01 15:09 ` Dirk-Jan C. Binnema
2024-04-01 17:18 ` Ergus
2024-04-02 23:23 ` Dmitry Gutov
2024-04-03 19:47 ` Ergus
2024-04-06 2:05 ` Ergus
2024-04-14 1:44 ` Dmitry Gutov
2024-04-16 14:56 ` Ergus
2024-04-22 17:05 ` Ergus
2024-04-22 18:48 ` Ergus
2024-04-22 21:20 ` Mohsin Kaleem
2024-04-23 15:17 ` Ergus
2024-04-23 19:26 ` Mohsin Kaleem
2024-04-26 0:47 ` Dmitry Gutov
2024-04-02 21:39 ` Richard Stallman
2024-04-02 22:43 ` Dr. Arne Babenhauserheide
2024-04-05 21:40 ` Richard Stallman
2024-04-03 10:40 ` Konstantin Kharlamov
2024-04-03 11:45 ` Eli Zaretskii
2024-04-03 13:31 ` Konstantin Kharlamov
2024-04-03 14:11 ` Eli Zaretskii
2024-04-03 15:00 ` Konstantin Kharlamov
2024-04-03 15:47 ` Eli Zaretskii
2024-04-03 17:27 ` Konstantin Kharlamov
2024-04-03 18:22 ` Eli Zaretskii
2024-04-03 19:08 ` Konstantin Kharlamov
2024-04-03 20:12 ` Ergus
2024-04-04 5:26 ` Eli Zaretskii
2024-04-04 9:59 ` Ergus
2024-04-04 11:59 ` Eli Zaretskii
2024-04-04 12:34 ` Ergus
2024-04-04 13:02 ` Eli Zaretskii
2024-04-04 14:27 ` Ergus
2024-04-04 14:41 ` Eli Zaretskii
2024-04-04 18:15 ` Ergus
2024-04-04 18:56 ` Eli Zaretskii
2024-04-04 20:16 ` Konstantin Kharlamov
2024-04-05 5:11 ` Eli Zaretskii
2024-04-04 5:07 ` Eli Zaretskii
[not found] ` <87jzlefgi9.fsf@dick>
2024-04-03 18:44 ` Konstantin Kharlamov
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=yj4fb4r46rrkmkukeoly467t47itjdok3w7hka523lm5pl324z@5utfgnn5ulf6 \
--to=spacibba@aol.com \
--cc=dmitry@gutov.dev \
--cc=emacs-devel@gnu.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
Code repositories for project(s) associated with this external index
https://git.savannah.gnu.org/cgit/emacs.git
https://git.savannah.gnu.org/cgit/emacs/org-mode.git
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.