• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1# python3
2# Copyright (C) 2019 The Android Open Source Project
3#
4# Licensed under the Apache License, Version 2.0 (the "License");
5# you may not use this file except in compliance with the License.
6# You may obtain a copy of the License at
7#
8#      http://www.apache.org/licenses/LICENSE-2.0
9#
10# Unless required by applicable law or agreed to in writing, software
11# distributed under the License is distributed on an "AS IS" BASIS,
12# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13# See the License for the specific language governing permissions and
14# limitations under the License.
15
16"""Warning patterns from other tools."""
17
18# No need of doc strings for trivial small functions.
19# pylint:disable=missing-function-docstring
20
21# pylint:disable=relative-beyond-top-level
22from .cpp_warn_patterns import compile_patterns
23from .severity import Severity
24
25
26def warn(name, severity, description, pattern_list):
27  return {
28      'category': name,
29      'severity': severity,
30      'description': name + ': ' + description,
31      'patterns': pattern_list
32  }
33
34
35def aapt(description, pattern_list):
36  return warn('aapt', Severity.MEDIUM, description, pattern_list)
37
38
39def misc(description, pattern_list):
40  return warn('logtags', Severity.LOW, description, pattern_list)
41
42
43def asm(description, pattern_list):
44  return warn('asm', Severity.MEDIUM, description, pattern_list)
45
46
47def kotlin(description, pattern):
48  return warn('Kotlin', Severity.MEDIUM, description,
49              [r'.*\.kt:.*: warning: ' + pattern])
50
51
52def yacc(description, pattern_list):
53  return warn('yacc', Severity.MEDIUM, description, pattern_list)
54
55
56def rust(severity, description, pattern):
57  return warn('Rust', severity, description,
58              [r'.*\.rs:.*: warning: ' + pattern])
59
60
61warn_patterns = [
62    # pylint does not recognize g-inconsistent-quotes
63    # pylint:disable=line-too-long,bad-option-value,g-inconsistent-quotes
64    # aapt warnings
65    aapt('No comment for public symbol',
66         [r".*: warning: No comment for public symbol .+"]),
67    aapt('No default translation',
68         [r".*: warning: string '.+' has no default translation in .*"]),
69    aapt('Missing default or required localization',
70         [r".*: warning: \*\*\*\* string '.+' has no default or required localization for '.+' in .+"]),
71    aapt('String marked untranslatable, but translation exists',
72         [r".*: warning: string '.+' in .* marked untranslatable but exists in locale '??_??'"]),
73    aapt('empty span in string',
74         [r".*: warning: empty '.+' span found in text '.+"]),
75    # misc warnings
76    misc('Duplicate logtag',
77         [r".*: warning: tag \".+\" \(.+\) duplicated in .+"]),
78    # Assembler warnings
79    asm('ASM value size does not match register size',
80        [r".*: warning: value size does not match register size specified by the constraint and modifier"]),
81    asm('IT instruction is deprecated',
82        [r".*: warning: applying IT instruction .* is deprecated"]),
83    asm('section flags ignored',
84        [r".*: warning: section flags ignored on section redeclaration"]),
85    asm('setjmp/longjmp/vfork changed binding',
86        [r".*: warning: .*(setjmp|longjmp|vfork) changed binding to .*"]),
87    # NDK warnings
88    {'category': 'NDK', 'severity': Severity.HIGH,
89     'description': 'NDK: Generate guard with empty availability, obsoleted',
90     'patterns': [r".*: warning: .* generate guard with empty availability: obsoleted ="]},
91    # Protoc warnings
92    {'category': 'Protoc', 'severity': Severity.MEDIUM,
93     'description': 'Proto: Enum name collision after strip',
94     'patterns': [r".*: warning: Enum .* has the same name .* ignore case and strip"]},
95    {'category': 'Protoc', 'severity': Severity.MEDIUM,
96     'description': 'Proto: Import not used',
97     'patterns': [r".*: warning: Import .*/.*\.proto but not used.$"]},
98    # Kotlin warnings
99    kotlin('never used parameter or variable', '.+ \'.*\' is never used'),
100    kotlin('multiple labels', '.+ more than one label .+ in this scope'),
101    kotlin('type mismatch', 'type mismatch: '),
102    kotlin('is always true', '.+ is always \'true\''),
103    kotlin('no effect', '.+ annotation has no effect for '),
104    kotlin('no cast needed', 'no cast needed'),
105    kotlin('accessor not generated', 'an accessor will not be generated '),
106    kotlin('initializer is redundant', '.* initializer is redundant$'),
107    kotlin('elvis operator always returns ...',
108           'elvis operator (?:) always returns .+'),
109    kotlin('shadowed name', 'name shadowed: .+'),
110    kotlin('unchecked cast', 'unchecked cast: .* to .*$'),
111    kotlin('unreachable code', 'unreachable code'),
112    kotlin('unnecessary assertion', 'unnecessary .+ assertion .+'),
113    kotlin('unnecessary safe call on a non-null receiver',
114           'unnecessary safe call on a non-null receiver'),
115    kotlin('Deprecated in Java',
116           '\'.*\' is deprecated. Deprecated in Java'),
117    kotlin('Replacing Handler for Executor',
118           '.+ Replacing Handler for Executor in '),
119    kotlin('library has Kotlin runtime',
120           '.+ has Kotlin runtime (bundled|library)'),
121    warn('Kotlin', Severity.MEDIUM, 'bundled Kotlin runtime',
122         ['.*warning: .+ (has|have the) Kotlin (runtime|Runtime library) bundled']),
123    kotlin('other warnings', '.+'),  # catch all other Kotlin warnings
124    # Yacc warnings
125    yacc('deprecate directive',
126         [r".*\.yy?:.*: warning: deprecated directive: "]),
127    yacc('reduce/reduce conflicts',
128         [r".*\.yy?: warning: .+ reduce/reduce conflicts "]),
129    yacc('shift/reduce conflicts',
130         [r".*\.yy?: warning: .+ shift/reduce conflicts "]),
131    {'category': 'yacc', 'severity': Severity.SKIP,
132     'description': 'yacc: fix-its can be applied',
133     'patterns': [r".*\.yy?: warning: fix-its can be applied."]},
134    # Rust warnings
135    rust(Severity.HIGH, 'Does not derive Copy', '.+ does not derive Copy'),
136    rust(Severity.MEDIUM, '... are deprecated',
137         ('(.+ are deprecated$|' +
138          'use of deprecated item .* (use .* instead|is now preferred))')),
139    rust(Severity.MEDIUM, 'never used', '.* is never used:'),
140    rust(Severity.MEDIUM, 'unused import', 'unused import: '),
141    rust(Severity.MEDIUM, 'unnecessary attribute',
142         '.+ no longer requires an attribute'),
143    rust(Severity.MEDIUM, 'unnecessary parentheses',
144         'unnecessary parentheses around'),
145    # Catch all RenderScript warnings
146    {'category': 'RenderScript', 'severity': Severity.LOW,
147     'description': 'RenderScript warnings',
148     'patterns': [r'.*\.rscript:.*: warning: ']},
149    {'category': 'RenderScript', 'severity': Severity.HIGH,
150     'description': 'RenderScript is deprecated',
151     'patterns': [r'.*: warning: Renderscript is deprecated:.+']},
152    # Broken/partial warning messages will be skipped.
153    {'category': 'Misc', 'severity': Severity.SKIP,
154     'description': 'skip, ,',
155     'patterns': [r".*: warning: ,?$"]},
156    {'category': 'C/C++', 'severity': Severity.SKIP,
157     'description': 'skip, In file included from ...',
158     'patterns': [r".*: warning: In file included from .+,"]},
159    # catch-all for warnings this script doesn't know about yet
160    {'category': 'C/C++', 'severity': Severity.UNMATCHED,
161     'description': 'Unclassified/unrecognized warnings',
162     'patterns': [r".*: warning: .+"]},
163]
164
165
166compile_patterns(warn_patterns)
167