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