blob: 524673e4f1cd785cf92847ab7fdf51ee020948f4 [file] [log] [blame]
Chih-Hung Hsieh888d1432019-12-09 19:32:03 -08001#
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
18from severity import Severity
19
20
21def warn(name, severity, description, pattern_list):
22 return {
23 'category': name,
24 'severity': severity,
25 'description': name + ': ' + description,
26 'patterns': pattern_list
27 }
28
29
30def aapt(description, pattern_list):
31 return warn('aapt', Severity.MEDIUM, description, pattern_list)
32
33
34def misc(description, pattern_list):
35 return warn('logtags', Severity.LOW, description, pattern_list)
36
37
38def asm(description, pattern_list):
39 return warn('asm', Severity.MEDIUM, description, pattern_list)
40
41
Chih-Hung Hsieha9f77462020-01-06 12:02:27 -080042def kotlin(description, pattern_list):
43 return warn('Kotlin', Severity.MEDIUM, description, pattern_list)
44
45
Chih-Hung Hsieh888d1432019-12-09 19:32:03 -080046patterns = [
47 # pylint:disable=line-too-long,g-inconsistent-quotes
48 # aapt warnings
49 aapt('No default translation',
50 [r".*: warning: string '.+' has no default translation in .*"]),
51 aapt('Missing default or required localization',
52 [r".*: warning: \*\*\*\* string '.+' has no default or required localization for '.+' in .+"]),
53 aapt('String marked untranslatable, but translation exists',
54 [r".*: warning: string '.+' in .* marked untranslatable but exists in locale '??_??'"]),
55 aapt('empty span in string',
56 [r".*: warning: empty '.+' span found in text '.+"]),
57 # misc warnings
58 misc('Duplicate logtag',
59 [r".*: warning: tag \".+\" \(.+\) duplicated in .+"]),
60 misc('Typedef redefinition',
61 [r".*: warning: redefinition of typedef '.+' is a C11 feature"]),
62 misc('GNU old-style field designator',
63 [r".*: warning: use of GNU old-style field designator extension"]),
64 misc('Missing field initializers',
65 [r".*: warning: missing field '.+' initializer"]),
66 misc('Missing braces',
67 [r".*: warning: suggest braces around initialization of",
68 r".*: warning: too many braces around scalar initializer .+Wmany-braces-around-scalar-init",
69 r".*: warning: braces around scalar initializer"]),
70 misc('Comparison of integers of different signs',
71 [r".*: warning: comparison of integers of different signs.+sign-compare"]),
72 misc('Add braces to avoid dangling else',
73 [r".*: warning: add explicit braces to avoid dangling else"]),
74 misc('Initializer overrides prior initialization',
75 [r".*: warning: initializer overrides prior initialization of this subobject"]),
76 misc('Assigning value to self',
77 [r".*: warning: explicitly assigning value of .+ to itself"]),
78 misc('GNU extension, variable sized type not at end',
79 [r".*: warning: field '.+' with variable sized type '.+' not at the end of a struct or class"]),
80 misc('Comparison of constant is always false/true',
81 [r".*: comparison of .+ is always .+Wtautological-constant-out-of-range-compare"]),
82 misc('Hides overloaded virtual function',
83 [r".*: '.+' hides overloaded virtual function"]),
84 misc('Incompatible pointer types',
85 [r".*: warning: incompatible .*pointer types .*-Wincompatible-.*pointer-types"]),
86 # Assembler warnings
87 asm('ASM value size does not match register size',
88 [r".*: warning: value size does not match register size specified by the constraint and modifier"]),
89 asm('IT instruction is deprecated',
90 [r".*: warning: applying IT instruction .* is deprecated"]),
91 # NDK warnings
92 {'category': 'NDK', 'severity': Severity.HIGH,
93 'description': 'NDK: Generate guard with empty availability, obsoleted',
94 'patterns': [r".*: warning: .* generate guard with empty availability: obsoleted ="]},
95 # Protoc warnings
96 {'category': 'Protoc', 'severity': Severity.MEDIUM,
97 'description': 'Proto: Enum name colision after strip',
98 'patterns': [r".*: warning: Enum .* has the same name .* ignore case and strip"]},
99 {'category': 'Protoc', 'severity': Severity.MEDIUM,
100 'description': 'Proto: Import not used',
101 'patterns': [r".*: warning: Import .*/.*\.proto but not used.$"]},
102 # Kotlin warnings
Chih-Hung Hsieha9f77462020-01-06 12:02:27 -0800103 kotlin('never used parameter or variable',
104 [r".*\.kt:.*: warning: (parameter|variable) '.*' is never used$",
105 r".*\.kt:.*: warning: (parameter|variable) '.*' is never used, could be renamed to _$"]),
106 kotlin('unchecked cast',
107 [r".*\.kt:.*: warning: unchecked cast: .* to .*$"]),
108 kotlin('Deprecated in Java',
109 [r".*\.kt:.*: warning: '.*' is deprecated. Deprecated in Java"]),
110 kotlin('library has Kotlin runtime',
111 [r".*: warning: library has Kotlin runtime bundled into it",
112 r".*: warning: some JAR files .* have the Kotlin Runtime library"]),
Chih-Hung Hsieh888d1432019-12-09 19:32:03 -0800113 # Rust warnings
114 {'category': 'Rust', 'severity': Severity.HIGH,
115 'description': 'Rust: Does not derive Copy',
116 'patterns': [r".*: warning: .+ does not derive Copy"]},
117 {'category': 'Rust', 'severity': Severity.MEDIUM,
118 'description': 'Rust: Deprecated range pattern',
119 'patterns': [r".*: warning: .+ range patterns are deprecated"]},
120 {'category': 'Rust', 'severity': Severity.MEDIUM,
121 'description': 'Rust: Deprecated missing explicit \'dyn\'',
122 'patterns': [r".*: warning: .+ without an explicit `dyn` are deprecated"]},
123 # Broken/partial warning messages will be skipped.
124 {'category': 'Misc', 'severity': Severity.SKIP,
125 'description': 'skip, ,',
126 'patterns': [r".*: warning: ,?$"]},
127 {'category': 'C/C++', 'severity': Severity.SKIP,
128 'description': 'skip, In file included from ...',
129 'patterns': [r".*: warning: In file included from .+,"]},
130 # catch-all for warnings this script doesn't know about yet
131 {'category': 'C/C++', 'severity': Severity.UNKNOWN,
132 'description': 'Unclassified/unrecognized warnings',
133 'patterns': [r".*: warning: .+"]},
134]