Print test timings unconditionally
[emacs.git] / lisp / cedet / semantic / dep.el
blob640884d014b37a997c50c4cbe4e7e2b86f77b078
1 ;;; semantic/dep.el --- Methods for tracking dependencies (include files)
3 ;; Copyright (C) 2006-2018 Free Software Foundation, Inc.
5 ;; Author: Eric M. Ludlam <zappo@gnu.org>
6 ;; Keywords: syntax
8 ;; This file is part of GNU Emacs.
10 ;; GNU Emacs is free software: you can redistribute it and/or modify
11 ;; it under the terms of the GNU General Public License as published by
12 ;; the Free Software Foundation, either version 3 of the License, or
13 ;; (at your option) any later version.
15 ;; GNU Emacs is distributed in the hope that it will be useful,
16 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
17 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 ;; GNU General Public License for more details.
20 ;; You should have received a copy of the GNU General Public License
21 ;; along with GNU Emacs. If not, see <https://www.gnu.org/licenses/>.
23 ;;; Commentary:
25 ;; Include tags (dependencies for a given source file) usually have
26 ;; some short name. The target file that it is dependent on is
27 ;; generally found on some sort of path controlled by the compiler or
28 ;; project.
30 ;; EDE or even ECB can control our project dependencies, and help us
31 ;; find file within the setting of a given project. For system
32 ;; dependencies, we need to depend on user supplied lists, which can
33 ;; manifest themselves in the form of system databases (from
34 ;; semanticdb.)
36 ;; Provide ways to track these different files here.
38 (require 'semantic/tag)
40 ;;; Code:
42 (defvar semantic-dependency-include-path nil
43 "Defines the include path used when searching for files.
44 This should be a list of directories to search which is specific
45 to the file being included.
47 If `semantic-dependency-tag-file' is overridden for a given
48 language, this path is most likely ignored.
50 The above function, regardless of being overridden, caches the
51 located dependency file location in the tag property
52 `dependency-file'. If you override this function, you do not
53 need to implement your own cache. Each time the buffer is fully
54 reparsed, the cache will be reset.
56 TODO: use ffap.el to locate such items?
58 NOTE: Obsolete this, or use as special user")
59 (make-variable-buffer-local `semantic-dependency-include-path)
61 (defvar semantic-dependency-system-include-path nil
62 "Defines the system include path.
63 This should be set with either `defvar-mode-local', or with
64 `semantic-add-system-include'.
66 For mode authors, use
67 `defcustom-mode-local-semantic-dependency-system-include-path'
68 to create a mode-specific variable to control this.
70 When searching for a file associated with a name found in a tag of
71 class include, this path will be inspected for includes of type
72 `system'. Some include tags are agnostic to this setting and will
73 check both the project and system directories.")
74 (make-variable-buffer-local `semantic-dependency-system-include-path)
76 (defmacro defcustom-mode-local-semantic-dependency-system-include-path
77 (mode name value &optional docstring)
78 "Create a mode-local value of the system-dependency include path.
79 MODE is the `major-mode' this name/value pairs is for.
80 NAME is the name of the customizable value users will use.
81 VALUE is the path (a list of strings) to add.
82 DOCSTRING is a documentation string applied to the variable NAME
83 users will customize.
85 Creates a customizable variable users can customize that will
86 keep semantic data structures up to date."
87 `(progn
88 ;; Create a variable users can customize.
89 (defcustom ,name ,value
90 ,docstring
91 :group (quote ,(intern (car (split-string (symbol-name mode) "-"))))
92 :group 'semantic
93 :type '(repeat (directory :tag "Directory"))
94 :set (lambda (sym val)
95 (set-default sym val)
96 (setq-mode-local ,mode
97 semantic-dependency-system-include-path
98 val)
99 (when (fboundp
100 'semantic-decoration-unparsed-include-do-reset)
101 (mode-local-map-mode-buffers
102 'semantic-decoration-unparsed-include-do-reset
103 (quote ,mode))))
105 ;; Set the variable to the default value.
106 (defvar-mode-local ,mode semantic-dependency-system-include-path
107 ,name
108 "System path to search for include files.")
109 ;; Bind NAME onto our variable so tools can customize it
110 ;; without knowing about it.
111 (put 'semantic-dependency-system-include-path
112 (quote ,mode) (quote ,name))
115 ;;; PATH MANAGEMENT
117 ;; Some fcns to manage paths for a give mode.
118 ;;;###autoload
119 (defun semantic-add-system-include (dir &optional mode)
120 "Add a system include DIR to path for MODE.
121 Modifies a mode-local version of `semantic-dependency-system-include-path'.
123 Changes made by this function are not persistent."
124 (interactive "DNew Include Directory: ")
125 (if (not mode) (setq mode major-mode))
126 (let ((dirtmp (file-name-as-directory dir))
127 (value
128 (mode-local-value mode 'semantic-dependency-system-include-path))
130 (add-to-list 'value dirtmp t)
131 (eval `(setq-mode-local ,mode
132 semantic-dependency-system-include-path value))
135 ;;;###autoload
136 (defun semantic-remove-system-include (dir &optional mode)
137 "Add a system include DIR to path for MODE.
138 Modifies a mode-local version of`semantic-dependency-system-include-path'.
140 Changes made by this function are not persistent."
141 (interactive (list
142 (completing-read
143 "Include Directory to Remove: "
144 semantic-dependency-system-include-path))
146 (if (not mode) (setq mode major-mode))
147 (let ((dirtmp (file-name-as-directory dir))
148 (value
149 (mode-local-value mode 'semantic-dependency-system-include-path))
151 (setq value (delete dirtmp value))
152 (eval `(setq-mode-local ,mode semantic-dependency-system-include-path
153 value))
156 ;;;###autoload
157 (defun semantic-reset-system-include (&optional mode)
158 "Reset the system include list to empty for MODE.
159 Modifies a mode-local version of
160 `semantic-dependency-system-include-path'."
161 (interactive)
162 (if (not mode) (setq mode major-mode))
163 (eval `(setq-mode-local ,mode semantic-dependency-system-include-path
164 nil))
167 ;;;###autoload
168 (defun semantic-customize-system-include-path (&optional mode)
169 "Customize the include path for this `major-mode'.
170 To create a customizable include path for a major MODE, use the
171 macro `defcustom-mode-local-semantic-dependency-system-include-path'."
172 (interactive)
173 (let ((ips (get 'semantic-dependency-system-include-path
174 (or mode major-mode))))
175 ;; Do we have one?
176 (when (not ips)
177 (error "There is no customizable includepath variable for %s"
178 (or mode major-mode)))
179 ;; Customize it.
180 (customize-variable ips)))
182 ;;; PATH SEARCH
184 ;; methods for finding files on a provided path.
185 (defmacro semantic--dependency-find-file-on-path (file path)
186 (if (fboundp 'locate-file)
187 `(locate-file ,file ,path)
188 `(let ((p ,path)
189 (found nil))
190 (while (and p (not found))
191 (let ((f (expand-file-name ,file (car p))))
192 (if (file-exists-p f)
193 (setq found f)))
194 (setq p (cdr p)))
195 found)))
197 (defvar ede-minor-mode)
198 (defvar ede-object)
199 (declare-function ede-system-include-path "ede")
201 (defun semantic-dependency-find-file-on-path (file systemp &optional mode)
202 "Return an expanded file name for FILE on available paths.
203 If SYSTEMP is true, then only search system paths.
204 If optional argument MODE is non-nil, then derive paths from the
205 provided mode, not from the current major mode."
206 (if (not mode) (setq mode major-mode))
207 (let ((sysp (mode-local-value
208 mode 'semantic-dependency-system-include-path))
209 (edesys (when (and (featurep 'ede) ede-minor-mode
210 ede-object)
211 (ede-system-include-path
212 (if (listp ede-object) (car ede-object) ede-object))))
213 (locp (mode-local-value
214 mode 'semantic-dependency-include-path))
215 (found nil))
216 (when (file-exists-p file)
217 (setq found file))
218 (when (and (not found) (not systemp))
219 (setq found (semantic--dependency-find-file-on-path file locp)))
220 (when (and (not found) edesys)
221 (setq found (semantic--dependency-find-file-on-path file edesys)))
222 (when (not found)
223 (setq found (semantic--dependency-find-file-on-path file sysp)))
224 (if found (expand-file-name found))))
227 (provide 'semantic/dep)
229 ;; Local variables:
230 ;; generated-autoload-file: "loaddefs.el"
231 ;; generated-autoload-load-name: "semantic/dep"
232 ;; End:
234 ;;; semantic/dep.el ends here