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# pylint:disable=relative-beyond-top-level 19# pylint:disable=g-importing-member 20from .cpp_warn_patterns import compile_patterns 21from .severity import Severity 22 23 24def 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 33def aapt(description, pattern_list): 34 return warn('aapt', Severity.MEDIUM, description, pattern_list) 35 36 37def misc(description, pattern_list): 38 return warn('logtags', Severity.LOW, description, pattern_list) 39 40 41def asm(description, pattern_list): 42 return warn('asm', Severity.MEDIUM, description, pattern_list) 43 44 45def kotlin(description, pattern): 46 return warn('Kotlin', Severity.MEDIUM, description, 47 [r'.*\.kt:.*: warning: ' + pattern]) 48 49 50def yacc(description, pattern_list): 51 return warn('yacc', Severity.MEDIUM, description, pattern_list) 52 53 54def rust(severity, description, pattern): 55 return warn('Rust', severity, description, 56 [r'.*\.rs:.*: warning: ' + pattern]) 57 58 59warn_patterns = [ 60 # pylint:disable=line-too-long,g-inconsistent-quotes 61 # aapt warnings 62 aapt('No comment for public symbol', 63 [r".*: warning: No comment for public symbol .+"]), 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, 112 'description': 'Proto: Enum name collision after strip', 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 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$'), 126 kotlin('elvis operator always returns ...', 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 .+'), 132 kotlin('unnecessary safe call on a non-null receiver', 133 'unnecessary safe call on a non-null receiver'), 134 kotlin('Deprecated in Java', 135 '\'.*\' is deprecated. Deprecated in Java'), 136 kotlin('Replacing Handler for Executor', 137 '.+ Replacing Handler for Executor in '), 138 kotlin('library has Kotlin runtime', 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 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."]}, 151 # Rust warnings 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: ']}, 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 174 {'category': 'C/C++', 'severity': Severity.UNMATCHED, 175 'description': 'Unclassified/unrecognized warnings', 176 'patterns': [r".*: warning: .+"]}, 177] 178 179 180compile_patterns(warn_patterns) 181