diff options
author | Robert Yang <liezhi.yang@windriver.com> | 2018-11-23 19:13:44 +0800 |
---|---|---|
committer | Richard Purdie <richard.purdie@linuxfoundation.org> | 2018-12-05 13:04:54 +0000 |
commit | f7060a43995279723036c37d173f846a3613180e (patch) | |
tree | 1ca51dba885c34c24d04addde9854b25de26c4b7 /bitbake/lib | |
parent | eff9942d30c34a8290fa3ff5edafe32a8992c633 (diff) | |
download | poky-f7060a43995279723036c37d173f846a3613180e.tar.gz |
bitbake: bitbake: BBHandler: Check tab indentation for python code
The previous check was in data.py which only can check code like "python
funcname()" in the dependency chain, but there are 3 kinds of python functions:
- python()
- def py_funcname()
- python funcname()
Add the checking to BBHandler to check and warn for all of them.
The warning looks like:
WARNING: /path/to/recipes-core/busybox/busybox_1.29.2.bb: python should use 4 spaces indentation, but found tabs in busybox.inc, line 75
(Bitbake rev: 0cdc5b81fc1f5e5281a525a657e420ebc3bb9e90)
Signed-off-by: Robert Yang <liezhi.yang@windriver.com>
Signed-off-by: Richard Purdie <richard.purdie@linuxfoundation.org>
Diffstat (limited to 'bitbake/lib')
-rw-r--r-- | bitbake/lib/bb/data.py | 2 | ||||
-rw-r--r-- | bitbake/lib/bb/parse/parse_py/BBHandler.py | 11 |
2 files changed, 11 insertions, 2 deletions
diff --git a/bitbake/lib/bb/data.py b/bitbake/lib/bb/data.py index d66d98cc8b..6bcfcf46cc 100644 --- a/bitbake/lib/bb/data.py +++ b/bitbake/lib/bb/data.py | |||
@@ -322,8 +322,6 @@ def build_dependencies(key, keys, shelldeps, varflagsexcl, d): | |||
322 | if varflags.get("python"): | 322 | if varflags.get("python"): |
323 | value = d.getVarFlag(key, "_content", False) | 323 | value = d.getVarFlag(key, "_content", False) |
324 | parser = bb.codeparser.PythonParser(key, logger) | 324 | parser = bb.codeparser.PythonParser(key, logger) |
325 | if value and "\t" in value: | ||
326 | logger.warning("Variable %s contains tabs, please remove these (%s)" % (key, d.getVar("FILE"))) | ||
327 | parser.parse_python(value, filename=varflags.get("filename"), lineno=varflags.get("lineno")) | 325 | parser.parse_python(value, filename=varflags.get("filename"), lineno=varflags.get("lineno")) |
328 | deps = deps | parser.references | 326 | deps = deps | parser.references |
329 | deps = deps | (keys & parser.execs) | 327 | deps = deps | (keys & parser.execs) |
diff --git a/bitbake/lib/bb/parse/parse_py/BBHandler.py b/bitbake/lib/bb/parse/parse_py/BBHandler.py index 01fc47e512..f3bf4aa529 100644 --- a/bitbake/lib/bb/parse/parse_py/BBHandler.py +++ b/bitbake/lib/bb/parse/parse_py/BBHandler.py | |||
@@ -46,6 +46,7 @@ __deltask_regexp__ = re.compile("deltask\s+(?P<func>\w+)") | |||
46 | __addhandler_regexp__ = re.compile( r"addhandler\s+(.+)" ) | 46 | __addhandler_regexp__ = re.compile( r"addhandler\s+(.+)" ) |
47 | __def_regexp__ = re.compile( r"def\s+(\w+).*:" ) | 47 | __def_regexp__ = re.compile( r"def\s+(\w+).*:" ) |
48 | __python_func_regexp__ = re.compile( r"(\s+.*)|(^$)|(^#)" ) | 48 | __python_func_regexp__ = re.compile( r"(\s+.*)|(^$)|(^#)" ) |
49 | __python_tab_regexp__ = re.compile(" *\t") | ||
49 | 50 | ||
50 | __infunc__ = [] | 51 | __infunc__ = [] |
51 | __inpython__ = False | 52 | __inpython__ = False |
@@ -160,6 +161,16 @@ def handle(fn, d, include): | |||
160 | 161 | ||
161 | def feeder(lineno, s, fn, root, statements, eof=False): | 162 | def feeder(lineno, s, fn, root, statements, eof=False): |
162 | global __func_start_regexp__, __inherit_regexp__, __export_func_regexp__, __addtask_regexp__, __addhandler_regexp__, __def_regexp__, __python_func_regexp__, __inpython__, __infunc__, __body__, bb, __residue__, __classname__ | 163 | global __func_start_regexp__, __inherit_regexp__, __export_func_regexp__, __addtask_regexp__, __addhandler_regexp__, __def_regexp__, __python_func_regexp__, __inpython__, __infunc__, __body__, bb, __residue__, __classname__ |
164 | |||
165 | # Check tabs in python functions: | ||
166 | # - def py_funcname(): covered by __inpython__ | ||
167 | # - python(): covered by '__anonymous' == __infunc__[0] | ||
168 | # - python funcname(): covered by __infunc__[3] | ||
169 | if __inpython__ or (__infunc__ and ('__anonymous' == __infunc__[0] or __infunc__[3])): | ||
170 | tab = __python_tab_regexp__.match(s) | ||
171 | if tab: | ||
172 | bb.warn('python should use 4 spaces indentation, but found tabs in %s, line %s' % (root, lineno)) | ||
173 | |||
163 | if __infunc__: | 174 | if __infunc__: |
164 | if s == '}': | 175 | if s == '}': |
165 | __body__.append('') | 176 | __body__.append('') |