Skip to content

Commit 472315c

Browse files
committed
[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: 253169886 Differential Revision: [D65541332](https://our.internmc.facebook.com/intern/diff/D65541332/)
1 parent eb6d1cb commit 472315c

File tree

1 file changed

+84
-0
lines changed

1 file changed

+84
-0
lines changed

.lintrunner.toml

Lines changed: 84 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -196,3 +196,87 @@ 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/mediatek/**',
214+
'backends/vulkan/**',
215+
'backends/xnnpack/**',
216+
'devtools/**',
217+
'examples/**',
218+
'extension/**',
219+
'kernels/optimized/**',
220+
'scripts/**',
221+
'third-party/**',
222+
'util/**',
223+
]
224+
command = [
225+
'python',
226+
'-m',
227+
'lintrunner_adapters',
228+
'run',
229+
'grep_linter',
230+
'--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)>)',
231+
'--linter-name=NOSTDINC',
232+
'--error-name=Standard C++ container include in core',
233+
"""--error-description=\
234+
Standard library containers should not be included in ExecuTorch core \
235+
because they may call malloc, which is not allowed in core. \
236+
""",
237+
'--',
238+
'@{{PATHSFILE}}',
239+
]
240+
241+
[[linter]]
242+
code = 'NOTORCHINC'
243+
include_patterns = [
244+
"**/*.c",
245+
"**/*.cpp",
246+
"**/*.h",
247+
"**/*.hpp",
248+
]
249+
exclude_patterns = [
250+
'**/devtools/**',
251+
'**/testing_util/**',
252+
'**/third-party/**',
253+
'backends/mediatek/**',
254+
'backends/vulkan/**',
255+
'backends/xnnpack/**',
256+
'devtools/**',
257+
'examples/**',
258+
'extension/**',
259+
'kernels/optimized/**',
260+
'scripts/**',
261+
'test/**',
262+
'third-party/**',
263+
'util/**',
264+
]
265+
command = [
266+
'python',
267+
'-m',
268+
'lintrunner_adapters',
269+
'run',
270+
'grep_linter',
271+
'--pattern=#include\s+[<"](aten/|ATen/|torch/)',
272+
'--linter-name=NOTORCHINC',
273+
'--error-name=ATen or torch include',
274+
"""--error-description=\
275+
PyTorch includes in ExecuTorch core are prohibited to prevent \
276+
accidentally breaking core's requirements; please make sure this \
277+
header complies (e.g., no streams/malloc/syscalls) and then include \
278+
a patch to update this linter.\
279+
""",
280+
'--',
281+
'@{{PATHSFILE}}',
282+
]

0 commit comments

Comments
 (0)