Re: [CEDET-devel] Clang completion on Linux sources
Brought to you by:
zappo
From: Lluís <xs...@gm...> - 2013-09-30 19:39:16
|
Lluís writes: > Lluís writes: >> David Engster writes: >>> David Engster writes: >>>> Lluís writes: >>>>> Hi! I've been trying semantic/bovine/clang.el and found out that it does not >>>>> return any results. >>>> >>>> I'm afraid the code has bit-rotted. I just tested it with clang 3.3, and >>>> it showed some problems with finding system headers. I'll take a look at >>>> it soon. >>> I've updated the clang.el code to work with newer versions. >> I tried to change it to use the information I added to the linux project (see >> below), but looks like the "call-process" does not return anything at all (tried >> putting the results in a buffer and it's always empty). >> BTW, I did not try your changes. > Well, now it works. See the updated patch which includes clang support for the > linux project (as well as updated linux project suport for ede). > Still, I'm not sure if the "ede/linux.el" changes I did are the way to go. It works for me... anyone objects to committing this? Lluis > === modified file 'lisp/cedet/ede/linux.el' > --- lisp/cedet/ede/linux.el 2013-01-31 20:50:32 +0000 > +++ lisp/cedet/ede/linux.el 2013-09-26 20:46:47 +0000 > @@ -34,6 +34,7 @@ > (require 'ede) > (require 'ede/make) > +(require 'cl) > (declare-function semanticdb-file-table-object "semantic/db") > (declare-function semanticdb-needs-refresh-p "semantic/db") > @@ -46,6 +47,19 @@ > :group 'ede > :version "24.3") > +(defcustom project-linux-build-directory 'ask > + "Build directory." > + :group 'project-linux > + :type '(choice (const :tag "Same as source directory" 'same) > + (const :tag "Ask the user" 'ask))) > + > +(defcustom project-linux-architecture-default 'ask > + "Target architecture to assume when not auto-detected." > + :group 'project-linux > + :type '(choice (string :tag "Architecture name") > + (const :tag "Ask the user" 'ask))) > + > + > (defcustom project-linux-compile-target-command (concat ede-make-command " -k -C %s SUBDIRS=%s") > "*Default command used to compile a target." > :group 'project-linux > @@ -109,10 +123,99 @@ > (defclass ede-linux-project (ede-project eieio-instance-tracker) > ((tracking-symbol :initform 'ede-linux-project-list) > - ) > + (build-directory :initarg :build-directory > + :type string > + :documentation "Build directory.") > + (architecture :initarg :architecture > + :type string > + :documentation "Target architecture.") > + (include-path :initarg :include-path > + :type list > + :documentation "Include directories. > +Contains both common and target architecture-specific directories.")) > "Project Type for the Linux source code." > :method-invocation-order :depth-first) > + > +(defun ede-linux--get-build-directory (dir) > + "Detect build directory for sources in DIR. > +If DIR has not been used as a build directory, fall back to > +`project-linux-build-directory'." > + (or > + ;; detected build on source directory > + (and (file-exists-p (expand-file-name ".config" dir)) dir) > + ;; use configuration > + (case project-linux-build-directory > + (same dir) > + (ask (read-directory-name "Select Linux' build directory: " dir))))) > + > + > +(defun ede-linux--get-archs (dir) > + "Returns a list of architecture names found in DIR." > + (let ((archs-dir (expand-file-name "arch" dir)) > + archs) > + (when (file-directory-p archs-dir) > + (setq archs > + (cl-remove-if-not > + (lambda (elem) > + (and > + (not (string= elem ".")) > + (not (string= elem "..")) > + (not (string= elem "x86_64")) ; has no separate sources > + (file-directory-p > + (expand-file-name elem archs-dir)))) > + (directory-files archs-dir)))))) > + > + > +(defun ede-linux--detect-architecture (dir) > + "Try to auto-detect the architecture as configured in DIR. > +DIR is Linux' build directory. If it cannot be auto-detected, > +returns `project-linux-architecture-default'." > + (let ((archs-dir (expand-file-name "arch" dir)) > + (archs (ede-linux--get-archs dir)) > + arch found) > + (or (and archs > + ;; Look for /arch/<arch>/include/generated > + (progn > + (while (and archs (not found)) > + (setq arch (car archs)) > + (when (file-directory-p > + (expand-file-name (concat arch "/include/generated") > + archs-dir)) > + (setq found arch)) > + (setq archs (cdr archs))) > + found)) > + project-linux-architecture-default))) > + > +(defun ede-linux--get-architecture (dir bdir) > + "Try to auto-detect the architecture as configured in BDIR. > +Uses `ede-linux--detect-architecture' for the auto-detection. If > +the result is `ask', let the user choose from architectures found > +in DIR." > + (let ((arch (ede-linux--detect-architecture bdir))) > + (case arch > + (ask > + (completing-read "Select target architecture: " > + (ede-linux--get-archs dir))) > + (t arch)))) > + > + > +(defun ede-linux--include-path (dir bdir arch) > + "Returns a list with include directories. > +Returned directories might not exist, since they are not created > +until Linux is built for the first time." > + (map 'list > + (lambda (elem) (format (concat (car elem) "/" (cdr elem)) arch)) > + ;; XXX: taken from the output of "make V=1" > + (list (cons dir "arch/%s/include") > + (cons bdir "arch/%s/include/generated") > + (cons dir "include") > + (cons bdir "include") > + (cons dir "arch/%s/include/uapi") > + (cons bdir "arch/%s/include/generated/uapi") > + (cons dir "include/uapi") > + (cons bdir "include/generated/uapi")))) > + > ;;;###autoload > (defun ede-linux-load (dir &optional rootproj) > "Return an Linux Project object if there is a match. > @@ -121,13 +224,19 @@ > ROOTPROJ is nil, since there is only one project." > (or (ede-linux-file-existing dir) > ;; Doesn't already exist, so let's make one. > - (let ((proj (ede-linux-project > - "Linux" > - :name "Linux" > - :version (ede-linux-version dir) > - :directory (file-name-as-directory dir) > - :file (expand-file-name "scripts/ver_linux" > - dir)))) > + (let* ((bdir (ede-linux--get-build-directory dir)) > + (arch (ede-linux--get-architecture dir bdir)) > + (include-path (ede-linux--include-path dir bdir arch)) > + (proj (ede-linux-project > + "Linux" > + :name "Linux" > + :version (ede-linux-version dir) > + :directory (file-name-as-directory dir) > + :file (expand-file-name "scripts/ver_linux" > + dir) > + :build-directory bdir > + :architecture arch > + :include-path include-path))) > (ede-add-project-to-global-list proj)) > )) > @@ -247,12 +356,18 @@ > (let* ((ext (file-name-extension name)) > (root (ede-project-root proj)) > (dir (ede-project-root-directory root)) > + (bdir (oref proj build-directory)) > (F (cond > ((not ext) nil) > ((string-match "h" ext) > - (or (ede-linux-file-exists-name name dir "") > - (ede-linux-file-exists-name name dir "include")) > - ) > + (let ((dirs (oref proj include-path)) > + found) > + (while (and dirs (not found)) > + (setq found > + (or (ede-linux-file-exists-name name bdir (car dirs)) > + (ede-linux-file-exists-name name dir (car dirs)))) > + (setq dirs (cdr dirs))) > + found)) > ((string-match "txt" ext) > (ede-linux-file-exists-name name dir "Documentation")) > (t nil))) > === modified file 'lisp/cedet/semantic/bovine/clang.el' > --- lisp/cedet/semantic/bovine/clang.el 2013-09-25 20:33:41 +0000 > +++ lisp/cedet/semantic/bovine/clang.el 2013-09-26 21:24:30 +0000 > @@ -310,6 +310,18 @@ > (concat "=" (cadr spp))))) > (oref proj spp-table)) > (list (concat "-I" (ede-project-root-directory proj))))) > + ;; Similarly for ede-linux-project > + ((ede-linux-project-child-p proj) > + (let* ((root (ede-project-root-directory proj)) > + (dir (file-name-directory (buffer-file-name))) > + (rel-dir (substring dir (length root)))) > + (append > + (list (format "-include%s/include/linux/kconfig.h" root)) > + (mapcar (lambda (inc) (concat "-I" inc)) > + (oref proj include-path)) > + (list (concat "-I" root rel-dir) > + (concat "-I" (oref proj build-directory) rel-dir) > + "-D__KERNEL__")))) > ;; For more general project types it's a bit more difficult. > ((ede-proj-project-p proj) > ;; Get the local and configuration variables. > -- > "And it's much the same thing with knowledge, for whenever you learn > something new, the whole world becomes that much richer." > -- The Princess of Pure Reason, as told by Norton Juster in The Phantom > Tollbooth > ------------------------------------------------------------------------------ > October Webinars: Code for Performance > Free Intel webinars can help you accelerate application performance. > Explore tips for MPI, OpenMP, advanced profiling, and more. Get the most from > the latest Intel processors and coprocessors. See abstracts and register > > http://pubads.g.doubleclick.net/gampad/clk?id=60133471&iu=/4140/ostg.clktrk > _______________________________________________ > Cedet-devel mailing list > Ced...@li... > https://lists.sourceforge.net/lists/listinfo/cedet-devel -- "And it's much the same thing with knowledge, for whenever you learn something new, the whole world becomes that much richer." -- The Princess of Pure Reason, as told by Norton Juster in The Phantom Tollbooth |