emacs-elpa-diffs
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[elpa] externals/beardbolt e18e3ee5ae 289/323: Support compile_commands.


From: ELPA Syncer
Subject: [elpa] externals/beardbolt e18e3ee5ae 289/323: Support compile_commands.json
Date: Thu, 9 Mar 2023 10:58:44 -0500 (EST)

branch: externals/beardbolt
commit e18e3ee5ae6636c624a457934cc4a8606e6e9b5d
Author: João Távora <joaotavora@gmail.com>
Commit: João Távora <joaotavora@gmail.com>

    Support compile_commands.json
    
    * beardbolt.el (bb--split-rm-single, bb--split-rm-double): Rename
    from bb-split-*.
    (bb--c/c++-compile-specs): Use bb--guess-from-ccj.
    (bb--guess-from-ccj): New helper.
---
 beardbolt.el | 24 +++++++++++++++++++++---
 1 file changed, 21 insertions(+), 3 deletions(-)

diff --git a/beardbolt.el b/beardbolt.el
index eedcd5771a..72e035fda9 100644
--- a/beardbolt.el
+++ b/beardbolt.el
@@ -212,14 +212,14 @@ Useful if you have multiple objdumpers and want to select 
between them")
                (:conc-name bb--lang-))
   (base-cmd nil :documentation "") (compile-specs nil :documentation ""))
 
-(defun bb-split-rm-single (cmd flag &optional test)
+(defun bb--split-rm-single (cmd flag &optional test)
   "Remove a single FLAG from CMD.  Test according to TEST."
   (mapconcat #'identity (cl-remove flag (split-string cmd)
                                    :test (or test #'string=))
              " "))
 
-(defun bb-split-rm-double (cmd flag)
-  "Remove a single FLAG and arg from CMD."
+(defun bb--split-rm-double (cmd flag)
+  "Remove a FLAG and subsequent arg from CMD."
   (cl-loop while split with split = (split-string cmd)
            for i from 0
            for probe = (car split)
@@ -247,6 +247,7 @@ Returns a list (SPEC ...) where SPEC looks like (WHAT FN 
CMD)."
     (let* ((direct-asm-out (tmp "beardbolt" "s"))
            (disass-asm-out (tmp "beardbolt" "out"))
            (base-command (ensure-list (or bb-command
+                                          (bb--guess-from-ccj)
                                           (bb--lang-base-cmd (bb--get-lang)))))
            (debug `("-g1"))
            (stdin-process `("-x" ,(if (derived-mode-p 'c++-mode) "c++" "c") 
"-"))
@@ -705,6 +706,23 @@ With prefix argument, choose from starter files in 
`bb-starter-files'."
 (defun bb--on-change-timer ()
   (bb-compile (bb--get-lang)))
 
+(defun bb--guess-from-ccj ()
+  (if-let* ((ccj-basename "compile_commands.json")
+            (ccj-dir (locate-dominating-file default-directory ccj-basename))
+            (ccj-file (expand-file-name ccj-basename ccj-dir))
+            (ccj (with-temp-buffer
+                   (insert-file-contents ccj-file)
+                   (goto-char (point-min))
+                   (json-parse-buffer :object-type 'plist)))
+            (cmd (cl-loop for e across ccj
+                          for file = (plist-get e :file)
+                          when (equal file buffer-file-name)
+                          return (plist-get e :command)))
+            (cmd (bb--split-rm-double cmd "-o"))
+            (cmd (bb--split-rm-double cmd "-c"))
+            (cmd (bb--split-rm-single cmd "-flto" #'string-prefix-p)))
+      cmd))
+
 ;;;; Mode Definition:
 
 ;;;###autoload



reply via email to

[Prev in Thread] Current Thread [Next in Thread]