Chih-Hung Hsieh | 949205a | 2020-01-10 10:33:40 -0800 | [diff] [blame] | 1 | # python3 |
Chih-Hung Hsieh | 888d143 | 2019-12-09 19:32:03 -0800 | [diff] [blame] | 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 | |
Chih-Hung Hsieh | 949205a | 2020-01-10 10:33:40 -0800 | [diff] [blame] | 18 | # pylint:disable=relative-beyond-top-level |
Chih-Hung Hsieh | 949205a | 2020-01-10 10:33:40 -0800 | [diff] [blame] | 19 | # pylint:disable=g-importing-member |
Chih-Hung Hsieh | 3cce2bc | 2020-02-27 15:39:18 -0800 | [diff] [blame] | 20 | from .cpp_warn_patterns import compile_patterns |
Chih-Hung Hsieh | 949205a | 2020-01-10 10:33:40 -0800 | [diff] [blame] | 21 | from .severity import Severity |
Chih-Hung Hsieh | 888d143 | 2019-12-09 19:32:03 -0800 | [diff] [blame] | 22 | |
| 23 | |
| 24 | def warn(name, severity, description, pattern_list): |
| 25 | return { |
| 26 | 'category': name, |
| 27 | 'severity': severity, |
| 28 | 'description': name + ': ' + description, |
| 29 | 'patterns': pattern_list |
| 30 | } |
| 31 | |
| 32 | |
| 33 | def aapt(description, pattern_list): |
| 34 | return warn('aapt', Severity.MEDIUM, description, pattern_list) |
| 35 | |
| 36 | |
| 37 | def misc(description, pattern_list): |
| 38 | return warn('logtags', Severity.LOW, description, pattern_list) |
| 39 | |
| 40 | |
| 41 | def asm(description, pattern_list): |
| 42 | return warn('asm', Severity.MEDIUM, description, pattern_list) |
| 43 | |
| 44 | |
Chih-Hung Hsieh | 445ad81 | 2020-02-26 14:34:21 -0800 | [diff] [blame] | 45 | def kotlin(description, pattern): |
| 46 | return warn('Kotlin', Severity.MEDIUM, description, |
| 47 | [r'.*\.kt:.*: warning: ' + pattern]) |
Chih-Hung Hsieh | a9f7746 | 2020-01-06 12:02:27 -0800 | [diff] [blame] | 48 | |
| 49 | |
Chih-Hung Hsieh | 5392cdb | 2020-01-13 14:05:17 -0800 | [diff] [blame] | 50 | def yacc(description, pattern_list): |
| 51 | return warn('yacc', Severity.MEDIUM, description, pattern_list) |
| 52 | |
| 53 | |
Chih-Hung Hsieh | 445ad81 | 2020-02-26 14:34:21 -0800 | [diff] [blame] | 54 | def rust(severity, description, pattern): |
| 55 | return warn('Rust', severity, description, |
| 56 | [r'.*\.rs:.*: warning: ' + pattern]) |
| 57 | |
| 58 | |
Chih-Hung Hsieh | 949205a | 2020-01-10 10:33:40 -0800 | [diff] [blame] | 59 | warn_patterns = [ |
Chih-Hung Hsieh | 888d143 | 2019-12-09 19:32:03 -0800 | [diff] [blame] | 60 | # pylint:disable=line-too-long,g-inconsistent-quotes |
| 61 | # aapt warnings |
Chih-Hung Hsieh | 949205a | 2020-01-10 10:33:40 -0800 | [diff] [blame] | 62 | aapt('No comment for public symbol', |
| 63 | [r".*: warning: No comment for public symbol .+"]), |
Chih-Hung Hsieh | 888d143 | 2019-12-09 19:32:03 -0800 | [diff] [blame] | 64 | aapt('No default translation', |
| 65 | [r".*: warning: string '.+' has no default translation in .*"]), |
| 66 | aapt('Missing default or required localization', |
| 67 | [r".*: warning: \*\*\*\* string '.+' has no default or required localization for '.+' in .+"]), |
| 68 | aapt('String marked untranslatable, but translation exists', |
| 69 | [r".*: warning: string '.+' in .* marked untranslatable but exists in locale '??_??'"]), |
| 70 | aapt('empty span in string', |
| 71 | [r".*: warning: empty '.+' span found in text '.+"]), |
| 72 | # misc warnings |
| 73 | misc('Duplicate logtag', |
| 74 | [r".*: warning: tag \".+\" \(.+\) duplicated in .+"]), |
| 75 | misc('Typedef redefinition', |
| 76 | [r".*: warning: redefinition of typedef '.+' is a C11 feature"]), |
| 77 | misc('GNU old-style field designator', |
| 78 | [r".*: warning: use of GNU old-style field designator extension"]), |
| 79 | misc('Missing field initializers', |
| 80 | [r".*: warning: missing field '.+' initializer"]), |
| 81 | misc('Missing braces', |
| 82 | [r".*: warning: suggest braces around initialization of", |
| 83 | r".*: warning: too many braces around scalar initializer .+Wmany-braces-around-scalar-init", |
| 84 | r".*: warning: braces around scalar initializer"]), |
| 85 | misc('Comparison of integers of different signs', |
| 86 | [r".*: warning: comparison of integers of different signs.+sign-compare"]), |
| 87 | misc('Add braces to avoid dangling else', |
| 88 | [r".*: warning: add explicit braces to avoid dangling else"]), |
| 89 | misc('Initializer overrides prior initialization', |
| 90 | [r".*: warning: initializer overrides prior initialization of this subobject"]), |
| 91 | misc('Assigning value to self', |
| 92 | [r".*: warning: explicitly assigning value of .+ to itself"]), |
| 93 | misc('GNU extension, variable sized type not at end', |
| 94 | [r".*: warning: field '.+' with variable sized type '.+' not at the end of a struct or class"]), |
| 95 | misc('Comparison of constant is always false/true', |
| 96 | [r".*: comparison of .+ is always .+Wtautological-constant-out-of-range-compare"]), |
| 97 | misc('Hides overloaded virtual function', |
| 98 | [r".*: '.+' hides overloaded virtual function"]), |
| 99 | misc('Incompatible pointer types', |
| 100 | [r".*: warning: incompatible .*pointer types .*-Wincompatible-.*pointer-types"]), |
| 101 | # Assembler warnings |
| 102 | asm('ASM value size does not match register size', |
| 103 | [r".*: warning: value size does not match register size specified by the constraint and modifier"]), |
| 104 | asm('IT instruction is deprecated', |
| 105 | [r".*: warning: applying IT instruction .* is deprecated"]), |
| 106 | # NDK warnings |
| 107 | {'category': 'NDK', 'severity': Severity.HIGH, |
| 108 | 'description': 'NDK: Generate guard with empty availability, obsoleted', |
| 109 | 'patterns': [r".*: warning: .* generate guard with empty availability: obsoleted ="]}, |
| 110 | # Protoc warnings |
| 111 | {'category': 'Protoc', 'severity': Severity.MEDIUM, |
Chih-Hung Hsieh | 949205a | 2020-01-10 10:33:40 -0800 | [diff] [blame] | 112 | 'description': 'Proto: Enum name collision after strip', |
Chih-Hung Hsieh | 888d143 | 2019-12-09 19:32:03 -0800 | [diff] [blame] | 113 | 'patterns': [r".*: warning: Enum .* has the same name .* ignore case and strip"]}, |
| 114 | {'category': 'Protoc', 'severity': Severity.MEDIUM, |
| 115 | 'description': 'Proto: Import not used', |
| 116 | 'patterns': [r".*: warning: Import .*/.*\.proto but not used.$"]}, |
| 117 | # Kotlin warnings |
Chih-Hung Hsieh | 445ad81 | 2020-02-26 14:34:21 -0800 | [diff] [blame] | 118 | kotlin('never used parameter or variable', '.+ \'.*\' is never used'), |
| 119 | kotlin('multiple labels', '.+ more than one label .+ in this scope'), |
| 120 | kotlin('type mismatch', 'type mismatch: '), |
| 121 | kotlin('is always true', '.+ is always \'true\''), |
| 122 | kotlin('no effect', '.+ annotation has no effect for '), |
| 123 | kotlin('no cast needed', 'no cast needed'), |
| 124 | kotlin('accessor not generated', 'an accessor will not be generated '), |
| 125 | kotlin('initializer is redundant', '.* initializer is redundant$'), |
Chih-Hung Hsieh | a7f5f3f | 2020-01-31 16:14:04 -0800 | [diff] [blame] | 126 | kotlin('elvis operator always returns ...', |
Chih-Hung Hsieh | 445ad81 | 2020-02-26 14:34:21 -0800 | [diff] [blame] | 127 | 'elvis operator (?:) always returns .+'), |
| 128 | kotlin('shadowed name', 'name shadowed: .+'), |
| 129 | kotlin('unchecked cast', 'unchecked cast: .* to .*$'), |
| 130 | kotlin('unreachable code', 'unreachable code'), |
| 131 | kotlin('unnecessary assertion', 'unnecessary .+ assertion .+'), |
Chih-Hung Hsieh | a7f5f3f | 2020-01-31 16:14:04 -0800 | [diff] [blame] | 132 | kotlin('unnecessary safe call on a non-null receiver', |
Chih-Hung Hsieh | 445ad81 | 2020-02-26 14:34:21 -0800 | [diff] [blame] | 133 | 'unnecessary safe call on a non-null receiver'), |
Chih-Hung Hsieh | a9f7746 | 2020-01-06 12:02:27 -0800 | [diff] [blame] | 134 | kotlin('Deprecated in Java', |
Chih-Hung Hsieh | 445ad81 | 2020-02-26 14:34:21 -0800 | [diff] [blame] | 135 | '\'.*\' is deprecated. Deprecated in Java'), |
Chih-Hung Hsieh | ed74896 | 2020-02-04 12:12:11 -0800 | [diff] [blame] | 136 | kotlin('Replacing Handler for Executor', |
Chih-Hung Hsieh | 445ad81 | 2020-02-26 14:34:21 -0800 | [diff] [blame] | 137 | '.+ Replacing Handler for Executor in '), |
Chih-Hung Hsieh | a9f7746 | 2020-01-06 12:02:27 -0800 | [diff] [blame] | 138 | kotlin('library has Kotlin runtime', |
Chih-Hung Hsieh | 445ad81 | 2020-02-26 14:34:21 -0800 | [diff] [blame] | 139 | '.+ has Kotlin runtime (bundled|library)'), |
| 140 | warn('Kotlin', Severity.MEDIUM, 'bundled Kotlin runtime', |
| 141 | ['.*warning: .+ (has|have the) Kotlin (runtime|Runtime library) bundled']), |
| 142 | kotlin('other warnings', '.+'), # catch all other Kotlin warnings |
Chih-Hung Hsieh | 5392cdb | 2020-01-13 14:05:17 -0800 | [diff] [blame] | 143 | # Yacc warnings |
| 144 | yacc('deprecate directive', |
| 145 | [r".*\.yy?:.*: warning: deprecated directive: "]), |
| 146 | yacc('shift/reduce conflicts', |
| 147 | [r".*\.yy?: warning: .+ shift/reduce conflicts "]), |
| 148 | {'category': 'yacc', 'severity': Severity.SKIP, |
| 149 | 'description': 'yacc: fix-its can be applied', |
| 150 | 'patterns': [r".*\.yy?: warning: fix-its can be applied."]}, |
Chih-Hung Hsieh | 888d143 | 2019-12-09 19:32:03 -0800 | [diff] [blame] | 151 | # Rust warnings |
Chih-Hung Hsieh | 445ad81 | 2020-02-26 14:34:21 -0800 | [diff] [blame] | 152 | rust(Severity.HIGH, 'Does not derive Copy', '.+ does not derive Copy'), |
| 153 | rust(Severity.MEDIUM, '... are deprecated', |
| 154 | ('(.+ are deprecated$|' + |
| 155 | 'use of deprecated item .* (use .* instead|is now preferred))')), |
| 156 | rust(Severity.MEDIUM, 'never used', '.* is never used:'), |
| 157 | rust(Severity.MEDIUM, 'unused import', 'unused import: '), |
| 158 | rust(Severity.MEDIUM, 'unnecessary attribute', |
| 159 | '.+ no longer requires an attribute'), |
| 160 | rust(Severity.MEDIUM, 'unnecessary parentheses', |
| 161 | 'unnecessary parentheses around'), |
| 162 | # Catch all RenderScript warnings |
| 163 | {'category': 'RenderScript', 'severity': Severity.LOW, |
| 164 | 'description': 'RenderScript warnings', |
| 165 | 'patterns': [r'.*\.rscript:.*: warning: ']}, |
Chih-Hung Hsieh | 888d143 | 2019-12-09 19:32:03 -0800 | [diff] [blame] | 166 | # Broken/partial warning messages will be skipped. |
| 167 | {'category': 'Misc', 'severity': Severity.SKIP, |
| 168 | 'description': 'skip, ,', |
| 169 | 'patterns': [r".*: warning: ,?$"]}, |
| 170 | {'category': 'C/C++', 'severity': Severity.SKIP, |
| 171 | 'description': 'skip, In file included from ...', |
| 172 | 'patterns': [r".*: warning: In file included from .+,"]}, |
| 173 | # catch-all for warnings this script doesn't know about yet |
Chih-Hung Hsieh | 949205a | 2020-01-10 10:33:40 -0800 | [diff] [blame] | 174 | {'category': 'C/C++', 'severity': Severity.UNMATCHED, |
Chih-Hung Hsieh | 888d143 | 2019-12-09 19:32:03 -0800 | [diff] [blame] | 175 | 'description': 'Unclassified/unrecognized warnings', |
| 176 | 'patterns': [r".*: warning: .+"]}, |
| 177 | ] |
Chih-Hung Hsieh | 949205a | 2020-01-10 10:33:40 -0800 | [diff] [blame] | 178 | |
| 179 | |
| 180 | compile_patterns(warn_patterns) |