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