Skip to content

Commit 5ecef89

Browse files
pytorchbotswolchok
andauthored
Add NOSTDINC and NOTORCHINC lintrunner (#6822)
[ExecuTorch] Add NOSTDINC and NOTORCHINC lintrunner Pull Request resolved: #6693 Prohibit standard C++ container, aten, and torch includes in core, at least pending further review. Note that non-core directories, such as extension/, test/, and any testing_util/ subdirectories, are exempted. ghstack-source-id: 253193810 Differential Revision: [D65541332](https://our.internmc.facebook.com/intern/diff/D65541332/) Co-authored-by: Scott Wolchok <[email protected]>
1 parent eb6d1cb commit 5ecef89

File tree

1 file changed

+88
-0
lines changed

1 file changed

+88
-0
lines changed

.lintrunner.toml

+88
Original file line numberDiff line numberDiff line change
@@ -196,3 +196,91 @@ command = [
196196
'@{{PATHSFILE}}',
197197
]
198198
is_formatter = true
199+
200+
[[linter]]
201+
code = 'NOSTDINC'
202+
include_patterns = [
203+
"**/*.c",
204+
"**/*.cpp",
205+
"**/*.h",
206+
"**/*.hpp",
207+
]
208+
exclude_patterns = [
209+
'**/devtools/**',
210+
'**/test/**',
211+
'**/testing_util/**',
212+
'**/third-party/**',
213+
'backends/**',
214+
'devtools/**',
215+
'examples/**',
216+
'extension/**',
217+
'kernels/optimized/**',
218+
'scripts/**',
219+
'third-party/**',
220+
'util/**',
221+
]
222+
command = [
223+
'python',
224+
'-m',
225+
'lintrunner_adapters',
226+
'run',
227+
'grep_linter',
228+
'--pattern=([^\\S\r\n]*#include\s*<(deque|exception|forward_list|functional|list|map|multimap|multiset|priority_queue|queue|set|stack|string|unordered_map|unordered_multimap|unordered_multiset|unordered_set|vector)>)',
229+
'--linter-name=NOSTDINC',
230+
'--error-name=Standard C++ container include in core',
231+
"""--error-description=\
232+
Standard library containers should not be included in ExecuTorch core \
233+
because they may call malloc, which is not allowed in core. \
234+
""",
235+
'--',
236+
'@{{PATHSFILE}}',
237+
]
238+
239+
[[linter]]
240+
code = 'NOTORCHINC'
241+
include_patterns = [
242+
"**/*.c",
243+
"**/*.cpp",
244+
"**/*.h",
245+
"**/*.hpp",
246+
]
247+
exclude_patterns = [
248+
'**/devtools/**',
249+
'**/fb/**',
250+
'**/test/**',
251+
'**/tests/**',
252+
'**/testing_util/**',
253+
'**/third-party/**',
254+
'backends/**',
255+
'codegen/templates/RegisterDispatchKeyCustomOps.cpp',
256+
'codegen/templates/RegisterSchema.cpp',
257+
'devtools/**',
258+
'examples/**',
259+
'exir/verification/bindings.cpp',
260+
'extension/**',
261+
'kernels/optimized/**',
262+
'runtime/core/exec_aten/**',
263+
'runtime/executor/tensor_parser_aten.cpp',
264+
'scripts/**',
265+
'test/**',
266+
'third-party/**',
267+
'util/**',
268+
]
269+
command = [
270+
'python',
271+
'-m',
272+
'lintrunner_adapters',
273+
'run',
274+
'grep_linter',
275+
'--pattern=#include\s+[<"](aten/|ATen/|torch/)',
276+
'--linter-name=NOTORCHINC',
277+
'--error-name=ATen or torch include',
278+
"""--error-description=\
279+
PyTorch includes in ExecuTorch core are prohibited to prevent \
280+
accidentally breaking core's requirements; please make sure this \
281+
header complies (e.g., no streams/malloc/syscalls) and then include \
282+
a patch to update this linter.\
283+
""",
284+
'--',
285+
'@{{PATHSFILE}}',
286+
]

0 commit comments

Comments
 (0)