/
flycheck-objc-clang.el
319 lines (257 loc) · 11.6 KB
/
flycheck-objc-clang.el
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
;;; flycheck-objc-clang.el --- Flycheck: Objective-C support using Clang -*- lexical-binding: t; -*-
;; Copyright (c) 2016-2021 GyazSquare Inc.
;; Author: Goichi Hirakawa <gooichi@gyazsquare.com>
;; URL: https://github.com/GyazSquare/flycheck-objc-clang
;; Version: 4.0.2
;; Keywords: convenience, languages, tools
;; Package-Requires: ((emacs "24.4") (flycheck "26"))
;; This file is not part of GNU Emacs.
;; MIT License
;; Permission is hereby granted, free of charge, to any person obtaining
;; a copy of this software and associated documentation files (the
;; "Software"), to deal in the Software without restriction, including
;; without limitation the rights to use, copy, modify, merge, publish,
;; distribute, sublicense, and/or sell copies of the Software, and to
;; permit persons to whom the Software is furnished to do so, subject to
;; the following conditions:
;; The above copyright notice and this permission notice shall be
;; included in all copies or substantial portions of the Software.
;; THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
;; EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
;; MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
;; NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
;; BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
;; ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
;; CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
;; SOFTWARE.
;;; Commentary:
;; Add Objective-C support to Flycheck using Clang.
;;
;; Usage:
;;
;; (with-eval-after-load 'flycheck
;; (add-hook 'flycheck-mode-hook #'flycheck-objc-clang-setup))
;;; Code:
(require 'flycheck)
(flycheck-def-option-var flycheck-objc-clang-xcrun-sdk nil objc-clang
"Specify which SDK to search for tools.
When non-nil, set the SDK name to find the tools, via `--sdk'.
The option is available only on macOS.
Use `xcodebuild -showsdks' to list the available SDK names."
:type 'string
:safe #'stringp)
(flycheck-def-option-var flycheck-objc-clang-xcrun-toolchain nil objc-clang
"Specify which toolchain to use to perform the lookup.
When non-nil, set the toolchain identifier or name to use to
perform the lookup, via `--toolchain'.
The option is available only on macOS."
:type 'string
:safe #'stringp)
(flycheck-def-option-var flycheck-objc-clang-language-standard nil objc-clang
"Specify the language standard to compile for.
When non-nil, set the language standard via `-std'."
:type '(choice (const :tag "Default standard" nil)
(string :tag "Language standard"))
:safe #'stringp)
(flycheck-def-option-var flycheck-objc-clang-arc nil objc-clang
"Enable Objective-C Automatic Reference Counting (ARC).
When non-nil, enable ARC via `-fobjc-arc'. It is disabled by
default.
See URL
`http://clang.llvm.org/docs/AutomaticReferenceCounting.html' for
more information about ARC."
:type 'boolean
:safe #'booleanp)
(flycheck-def-option-var flycheck-objc-clang-runtime nil objc-clang
"Specify the target Objective-C runtime kind and version.
When non-nil, set the Objective-C runtime kind and version, via
`-fobjc-runtime'."
:type 'string
:safe #'stringp)
(flycheck-def-option-var flycheck-objc-clang-weak nil objc-clang
"Enable weak references in Manual Reference Counting (MRC).
When non-nil, enable ARC-stype weak references via
`-fobjc-weak'. It is disabled by default."
:type 'boolean
:safe #'booleanp)
(flycheck-def-option-var flycheck-objc-clang-modules nil objc-clang
"Enable the modules feature.
When non-nil, enable the modules feature via `-fmodules'. It is
disabled by default.
See URL `http://clang.llvm.org/docs/Modules.html' for more
information about modules."
:type 'boolean
:safe #'booleanp)
(flycheck-def-option-var flycheck-objc-clang-archs nil objc-clang
"Specify the architecture to build for.
When non-nil, add the architectures via `-arch'."
:type '(repeat (string :tag "Architecture name"))
:safe #'flycheck-string-list-p)
(flycheck-def-option-var flycheck-objc-clang-ios-version-min nil objc-clang
"Specifies iOS deployment target.
When non-nil, set iOS deployment target via
`-mios-version-min'."
:type 'string
:safe #'stringp)
(flycheck-def-option-var flycheck-objc-clang-macosx-version-min nil objc-clang
"Specify Mac OS X deployment target.
When non-nil, set Mac OS X deployment target via
`-mmacosx-version-min'."
:type 'string
:safe #'stringp)
(flycheck-def-option-var flycheck-objc-clang-tvos-version-min nil objc-clang
"Specify tvOS deployment target.
When non-nil, set tvOS deployment target via
`-mtvos-version-min'."
:type 'string
:safe #'stringp)
(flycheck-def-option-var flycheck-objc-clang-watchos-version-min nil objc-clang
"Specify watchOS deployment target.
When non-nil, set watchOS deployment target via
`-mwatchos-version-min'."
:type 'string
:safe #'stringp)
(flycheck-def-option-var flycheck-objc-clang-warnings
'("all"
"extra"
"error=non-modular-include-in-framework-module"
"no-unused-parameter"
"error=deprecated-objc-isa-usage"
"duplicate-method-match"
"undeclared-selector"
"error=objc-root-class")
objc-clang
"Enable the specified warnings.
By default, all recommended warnings and some extra warnings are
enabled.
See URL `http://clang.llvm.org/docs/UsersManual.html' for more
information about warnings."
:type '(choice (const :tag "Recommended warnings" nil)
(repeat :tag "Warnings" (string :tag "Warning name")))
:safe #'flycheck-string-list-p)
(flycheck-def-option-var flycheck-objc-clang-definitions nil objc-clang
"Define preprocessor macros.
When non-nil, add an implicit #define into the predefines buffer
which is read before the source file is preprocessed, via `-D'."
:type '(repeat (string :tag "Definition"))
:safe #'flycheck-string-list-p)
(flycheck-def-option-var flycheck-objc-clang-system-framework-search-paths nil
objc-clang
"Add directory to SYSTEM framework search path, absolute paths
are relative to -isysroot.
When non-nil, add the specified directory to the search path for
system framework include files, via `-iframeworkwithsysroot'.
The option is available in Clang 5 or later."
:type '(repeat (directory :tag "System framework directory"))
:safe #'flycheck-string-list-p)
(flycheck-def-option-var flycheck-objc-clang-includes nil objc-clang
"Include files before parsing.
When non-nil, add an implicit #include into the predefines buffer
which is read before the source file is preprocessed, via
`-include'."
:type '(repeat (file :tag "Include file"))
:safe #'flycheck-string-list-p)
(flycheck-def-option-var flycheck-objc-clang-sysroot nil objc-clang
"Set the system root directory (usually /).
When non-nil, set the system root directory via `-isysroot'."
:type '(choice (const :tag "Default sysroot" nil)
(string :tag "Sysroot"))
:safe #'stringp)
(flycheck-def-option-var flycheck-objc-clang-quote-include-paths nil objc-clang
"Add directory to QUOTE include search paths.
When non-nil, add the specified directory to the search path for
QUOTE include files, via `-iquote'."
:type '(repeat (directory :tag "QUOTE include directory"))
:safe #'flycheck-string-list-p)
(flycheck-def-option-var flycheck-objc-clang-include-paths nil objc-clang
"Add directory to include search paths.
When non-nil, add the specified directory to the search path for
include files, via `-I'."
:type '(repeat (directory :tag "Include directory"))
:safe #'flycheck-string-list-p)
(flycheck-def-option-var flycheck-objc-clang-framework-paths nil objc-clang
"Add directory to framework include search paths.
When non-nil, add the specified directory to the search path for
framework include files, via `-F'."
:type '(repeat (directory :tag "Framework directory"))
:safe #'flycheck-string-list-p)
(defun flycheck-objc-clang--syntax-checking-command ()
"Return the command to run for Objective-C syntax checking using Clang."
(let ((xcrun-path (executable-find "xcrun"))
(command
'("clang"
"-fsyntax-only"
(eval (cond
((eq major-mode 'objc-mode) '("-x" "objective-c"))
((eq major-mode 'c-mode) '("-x" "c"))))
(option "-std=" flycheck-objc-clang-language-standard concat)
(option-flag "-fobjc-arc" flycheck-objc-clang-arc)
(option "-fobjc-runtime=" flycheck-objc-clang-runtime concat)
(option-flag "-fobjc-weak" flycheck-objc-clang-weak)
(option-flag "-fmodules" flycheck-objc-clang-modules)
(option-list "-arch" flycheck-objc-clang-archs)
(option "-mios-version-min="
flycheck-objc-clang-ios-version-min concat)
(option "-mmacosx-version-min="
flycheck-objc-clang-macosx-version-min concat)
(option "-mtvos-version-min="
flycheck-objc-clang-tvos-version-min concat)
(option "-mwatchos-version-min="
flycheck-objc-clang-watchos-version-min concat)
(option-list "-W" flycheck-objc-clang-warnings concat)
"-fno-color-diagnostics"
"-fno-caret-diagnostics"
"-fno-diagnostics-show-option"
(option-list "-D" flycheck-objc-clang-definitions concat)
(option-list "-iframeworkwithsysroot"
flycheck-objc-clang-system-framework-search-paths)
(option-list "-include" flycheck-objc-clang-includes)
(option "-isysroot" flycheck-objc-clang-sysroot)
(option-list "-iquote" flycheck-objc-clang-quote-include-paths)
(option-list "-I" flycheck-objc-clang-include-paths concat)
(option-list "-F" flycheck-objc-clang-framework-paths concat)
;; Read from standard input
"-")))
(if xcrun-path
(let ((xcrun-command
`(,xcrun-path
(option "--sdk" flycheck-objc-clang-xcrun-sdk)
(option "--toolchain" flycheck-objc-clang-xcrun-toolchain))))
(append xcrun-command command))
command)))
(flycheck-define-command-checker 'objc-clang
"An Objective-C syntax checker using Clang.
See URL `http://clang.llvm.org/'."
:command (flycheck-objc-clang--syntax-checking-command)
:standard-input t
:error-patterns
'((error line-start
(message "In file included from") " " (or "<stdin>" (file-name))
":" line ":" line-end)
(info line-start (or "<stdin>" (file-name)) ":" line ":" column
": " (or "note" "remark") ": " (optional (message)) line-end)
(warning line-start (or "<stdin>" (file-name)) ":" line ":" column
": " "warning" ": " (optional (message)) line-end)
(error line-start (or "<stdin>" (file-name)) ":" line ":" column
": " (or "error" "fatal error") ": " (optional (message)) line-end))
:error-filter
(lambda (errors)
(let ((errors (flycheck-sanitize-errors errors)))
(dolist (err errors)
;; Clang will output empty messages for #error / #warning pragmas
;; without messages. We fill these empty errors with a dummy message
;; to get them past our error filtering.
(setf (flycheck-error-message err)
(or (flycheck-error-message err) "no message")))
(flycheck-fold-include-levels errors "In file included from")))
:modes 'objc-mode)
;;;###autoload
(defun flycheck-objc-clang-setup ()
"Set up Flycheck for Objective-C using Clang."
(add-to-list 'flycheck-checkers 'objc-clang))
(provide 'flycheck-objc-clang)
;; Local Variables:
;; coding: utf-8
;; indent-tabs-mode: nil
;; End:
;;; flycheck-objc-clang.el ends here