From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.io!.POSTED.blaine.gmane.org!not-for-mail From: Ergus Newsgroups: gmane.emacs.devel Subject: Re: Project out of sources compilation Date: Tue, 19 Mar 2024 19:36:35 +0100 Message-ID: References: <4wwljrdnra3bsloehioa46y24ozxajajmvf2elvskxxq3mhtg2.ref@pyv2z5snot6h> <4wwljrdnra3bsloehioa46y24ozxajajmvf2elvskxxq3mhtg2@pyv2z5snot6h> <87ttl5w0mr.fsf@gmail.com> Mime-Version: 1.0 Content-Type: multipart/mixed; boundary="7seytzmfdcalvzv2" Content-Transfer-Encoding: 8bit Injection-Info: ciao.gmane.io; posting-host="blaine.gmane.org:116.202.254.214"; logging-data="30134"; mail-complaints-to="usenet@ciao.gmane.io" Cc: emacs-devel@gnu.org To: Dmitry Gutov Original-X-From: emacs-devel-bounces+ged-emacs-devel=m.gmane-mx.org@gnu.org Tue Mar 19 19:37:48 2024 Return-path: Envelope-to: ged-emacs-devel@m.gmane-mx.org Original-Received: from lists.gnu.org ([209.51.188.17]) by ciao.gmane.io with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1rmeLM-0007fR-1S for ged-emacs-devel@m.gmane-mx.org; Tue, 19 Mar 2024 19:37:48 +0100 Original-Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1rmeKQ-0007ag-Bj; Tue, 19 Mar 2024 14:36:50 -0400 Original-Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1rmeKO-0007aD-AA for emacs-devel@gnu.org; Tue, 19 Mar 2024 14:36:48 -0400 Original-Received: from sonic306-2.consmr.mail.bf2.yahoo.com ([74.6.132.41]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1rmeKK-000571-KN for emacs-devel@gnu.org; Tue, 19 Mar 2024 14:36:47 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=aol.com; s=a2048; t=1710873401; bh=ol7aA/kOXWPXJJhFEGw/MGZ/BOKajCJS4795sf3GfB4=; h=Date:From:To:Cc:Subject:References:In-Reply-To:From:Subject:Reply-To; b=tl1h0+1YBoNV0jKq3TQ2o/5/pfFDogQSVW9nkmI8OcNHjythnLmi/YECQPmWYT59UTy6CJpTGUaRgfU+6Zk2jyFGDlGoOv9bjXmPc0gMwS/Mz0Ctyp1zOR22S944/kL+f9RSA2L+NmK5I/WZNWKYpi6dUD4H46Tc8iqsebtt8LD1bJ/ktcgzc1BF7ss0cAjHCPTtqghpWLcMF73Eqvmrqf2VyKm0VlWyZy13x9sacADqTMN3ePdLOTlh1pylkUyTxtLsMTBzWAU4zxRKgHyi7CPpxazoYos44KiT3WVtEUuwaTXMh+dtu+KAH/g87GsNDlmJrGVwTHGhZBRVIbPpkw== X-SONIC-DKIM-SIGN: v=1; a=rsa-sha256; c=relaxed/relaxed; d=yahoo.com; s=s2048; t=1710873401; bh=J+eNcNg5zuUUaJzMy/O0C9GyG+GGAyqHUStufJkA9F4=; h=X-Sonic-MF:Date:From:To:Subject:From:Subject; b=NNvfGp1VH9JQzgnxvs+2e5Mimiaynfj1adddtpV97pXQVidyBU9tDXikqV4nNuHXRbUiXBcxh9P6AqSczGfAFkIzhWxDHk3TbtHmKFp+WxaFdoaRzdMTNW19ySEl4V6Hy+iFKBAKSRPIQJyRzrWVPzY5uMl49NdjBSM5YzXOhioS+t9FApc6RU1ZTmbHw0Mo747t0SGxKFZz0SzXdKQ+HUnAHkZrLcCuyPCa0m2s7QPPFGVJN+wd2aojmX/KEcS4Xs+6sj9RnPHq1QueE8zQVEiXx7zlASWfWeVGQ0SMiayiYKiOuyReBkhUxvp91uklJtUMXhV1SRFJVmM9fbJ2WQ== X-YMail-OSG: mZC8B9kVM1kl_ouuDoM7dyC7WAzAzj.C8BIKTMiaBc3XjIWAn7Bods5S7kjL0PZ rrKPABaF1udQYwj3cndft7G5M7c4y1VhfYFAwuTk0ZMtjK9TryKHXA3Gj7RfuFcseznwwEGIYA41 L1QbU_2UtM.0DtWhZE3UQJxU5TrxdCgHLyA6OEsuT70LRT48Zkb1ZfyF.1ccx4fKg6iZbTSNyBhj EvjVJyBTBLo._agVwSGEfPEY.Jxqa7rDT44kvAH630WA5Wx0Atlr2W6UQ6AJXPeGaYvby1zCboSQ Oj3M7_Mx45bcYbGf0wVVIxuq5eMfiqTyKT5Q2h_GnCt7n3Tf6tt_EXAyRNDbW4x.tkmA6Xp9CEed o8YoCTd_6VpMurfxpuO05oL.WtM5drbKRxUCdGyz4wFsF1T18DWJvndgwlbMBuIJ7.NmiLwYwkB3 TzQZw4LLxe7qQsKu13bBi430AB0R8Nl81QAvZLnJC0r4yhNpesuuURojfWdFeQSqRSwHTdKrwS8w GLLd4GoizkxlLHqGsm2q7L97AI2sP_vhgWCH9FCh6o3VW6vlVlnuaoThdYzjWBn3GKH0pHaZrWxl 0iiUsPLPi0K__gCT1SmAVfsvC4SBO8Uqv7sUdtgOhAtMajeddiN_hmPKTTSF11kVJ06PCVuWszDH 5zllSYC_Rhi3ACWu9scF7juFaN6HcgOhCSCw0VQ.v74RiiME.dktu6VvjKzTX2X7AZHMm3AgKIO_ q1YZfYzuNnFYGQB5KydHcoO91LTkm2as269rMBdnP13r6COrKPykH8xrZ6NiflGfEOTLcad5RNFD B_WfpQDd.h3sWbQ8LmZkL2vY9R616SwhTmhlgxCTYF X-Sonic-MF: X-Sonic-ID: e76258f7-d1a4-4763-8a97-091dab24ff8c Original-Received: from sonic.gate.mail.ne1.yahoo.com by sonic306.consmr.mail.bf2.yahoo.com with HTTP; Tue, 19 Mar 2024 18:36:41 +0000 Original-Received: by hermes--production-ir2-7bc88bfc75-pvk5t (Yahoo Inc. Hermes SMTP Server) with ESMTPA ID faf135b623501ea68647543eafe54611; Tue, 19 Mar 2024 18:36:37 +0000 (UTC) Content-Disposition: inline In-Reply-To: X-Mailer: WebService/1.1.22129 mail.backend.jedi.jws.acl:role.jedi.acl.token.atz.jws.hermes.aol Received-SPF: pass client-ip=74.6.132.41; envelope-from=spacibba@aol.com; helo=sonic306-2.consmr.mail.bf2.yahoo.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, FREEMAIL_FROM=0.001, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H2=-0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, T_SCC_BODY_TEXT_LINE=-0.01 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: emacs-devel@gnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: "Emacs development discussions." List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: emacs-devel-bounces+ged-emacs-devel=m.gmane-mx.org@gnu.org Original-Sender: emacs-devel-bounces+ged-emacs-devel=m.gmane-mx.org@gnu.org Xref: news.gmane.io gmane.emacs.devel:317190 Archived-At: --7seytzmfdcalvzv2 Content-Type: text/plain; charset=utf-8; format=flowed Content-Disposition: inline Content-Transfer-Encoding: 8bit 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) > > > > > --7seytzmfdcalvzv2 Content-Type: text/plain; charset=us-ascii Content-Disposition: attachment; filename="project-build-dir.patch" commit cfa10dfeac01ae25a7acd6857fae0b377b625779 Author: Jimmy Aguilar Mena 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))) --7seytzmfdcalvzv2--