|
28 | 28 | # */ |
29 | 29 |
|
30 | 30 | import os |
| 31 | +import re |
31 | 32 | from common.header_checker import HeaderChecker |
32 | 33 |
|
33 | 34 | #-------------------------------------------------------------------------------------------------- |
|
106 | 107 | r'.*portable/GCC/AVR32_UC3/.*', |
107 | 108 | ] |
108 | 109 |
|
| 110 | +KERNEL_ARM_COLLAB_FILES_PATTERNS = [ |
| 111 | + r'.*portable/ARMv8M/*', |
| 112 | + r'.*portable/.*/ARM_CM23*', |
| 113 | + r'.*portable/.*/ARM_CM33*', |
| 114 | + r'.*portable/.*/ARM_CM35*', |
| 115 | + r'.*portable/.*/ARM_CM55*', |
| 116 | + r'.*portable/.*/ARM_CM85*', |
| 117 | +] |
| 118 | + |
109 | 119 | KERNEL_HEADER = [ |
110 | 120 | '/*\n', |
111 | 121 | ' * FreeRTOS Kernel <DEVELOPMENT BRANCH>\n', |
|
139 | 149 |
|
140 | 150 | FREERTOS_COPYRIGHT_REGEX = r"^(;|#)?( *(\/\*|\*|#|\/\/))? Copyright \(C\) 20\d\d Amazon.com, Inc. or its affiliates. All Rights Reserved\.( \*\/)?$" |
141 | 151 |
|
| 152 | +FREERTOS_ARM_COLLAB_COPYRIGHT_REGEX = r"(^(;|#)?( *(\/\*|\*|#|\/\/))? Copyright \(C\) 20\d\d Amazon.com, Inc. or its affiliates. All Rights Reserved\.( \*\/)?$)|" + \ |
| 153 | + r"(^(;|#)?( *(\/\*|\*|#|\/\/))? Copyright 20\d\d Arm Limited and/or its affiliates( \*\/)?$)|" + \ |
| 154 | + r"(^(;|#)?( *(\/\*|\*|#|\/\/))? <[email protected]>( \*\/)?$)" |
| 155 | + |
| 156 | + |
| 157 | +class KernelHeaderChecker(HeaderChecker): |
| 158 | + def __init__( |
| 159 | + self, |
| 160 | + header, |
| 161 | + padding=1000, |
| 162 | + ignored_files=None, |
| 163 | + ignored_ext=None, |
| 164 | + ignored_patterns=None, |
| 165 | + py_ext=None, |
| 166 | + asm_ext=None, |
| 167 | + third_party_patterns=None, |
| 168 | + copyright_regex = None |
| 169 | + ): |
| 170 | + super().__init__(header, padding, ignored_files, ignored_ext, ignored_patterns, |
| 171 | + py_ext, asm_ext, third_party_patterns, copyright_regex) |
| 172 | + |
| 173 | + self.armCollabRegex = re.compile(FREERTOS_ARM_COLLAB_COPYRIGHT_REGEX) |
| 174 | + |
| 175 | + self.armCollabFilesPatternList = [] |
| 176 | + for pattern in KERNEL_ARM_COLLAB_FILES_PATTERNS: |
| 177 | + self.armCollabFilesPatternList.append(re.compile(pattern)) |
| 178 | + |
| 179 | + def isArmCollabFile(self, path): |
| 180 | + for pattern in self.armCollabFilesPatternList: |
| 181 | + if pattern.match(path): |
| 182 | + return True |
| 183 | + return False |
| 184 | + |
| 185 | + def checkArmCollabFile(self, path): |
| 186 | + isValid = False |
| 187 | + file_ext = os.path.splitext(path)[-1] |
| 188 | + |
| 189 | + with open(path, encoding="utf-8", errors="ignore") as file: |
| 190 | + chunk = file.read(len("".join(self.header)) + self.padding) |
| 191 | + lines = [("%s\n" % line) for line in chunk.strip().splitlines()][ |
| 192 | + : len(self.header) + 2 |
| 193 | + ] |
| 194 | + if (len(lines) > 0) and (lines[0].find("#!") == 0): |
| 195 | + lines.remove(lines[0]) |
| 196 | + |
| 197 | + # Split lines in sections. |
| 198 | + headers = dict() |
| 199 | + headers["text"] = [] |
| 200 | + headers["copyright"] = [] |
| 201 | + headers["spdx"] = [] |
| 202 | + for line in lines: |
| 203 | + if self.armCollabRegex.match(line): |
| 204 | + headers["copyright"].append(line) |
| 205 | + elif "SPDX-License-Identifier:" in line: |
| 206 | + headers["spdx"].append(line) |
| 207 | + else: |
| 208 | + headers["text"].append(line) |
| 209 | + |
| 210 | + text_equal = self.isValidHeaderSection(file_ext, "text", headers["text"]) |
| 211 | + spdx_equal = self.isValidHeaderSection(file_ext, "spdx", headers["spdx"]) |
| 212 | + |
| 213 | + if text_equal and spdx_equal and len(headers["copyright"]) == 3: |
| 214 | + isValid = True |
| 215 | + |
| 216 | + return isValid |
| 217 | + |
| 218 | + def customCheck(self, path): |
| 219 | + isValid = False |
| 220 | + if self.isArmCollabFile(path): |
| 221 | + isValid = self.checkArmCollabFile(path) |
| 222 | + return isValid |
| 223 | + |
| 224 | + |
142 | 225 | def main(): |
143 | 226 | parser = HeaderChecker.configArgParser() |
144 | 227 | args = parser.parse_args() |
145 | 228 |
|
146 | 229 | # Configure the checks then run |
147 | | - checker = HeaderChecker(KERNEL_HEADER, |
148 | | - copyright_regex=FREERTOS_COPYRIGHT_REGEX, |
149 | | - ignored_files=KERNEL_IGNORED_FILES, |
150 | | - ignored_ext=KERNEL_IGNORED_EXTENSIONS, |
151 | | - ignored_patterns=KERNEL_IGNORED_PATTERNS, |
152 | | - third_party_patterns=KERNEL_THIRD_PARTY_PATTERNS, |
153 | | - py_ext=KERNEL_PY_EXTENSIONS, |
154 | | - asm_ext=KERNEL_ASM_EXTENSIONS) |
| 230 | + checker = KernelHeaderChecker(KERNEL_HEADER, |
| 231 | + copyright_regex=FREERTOS_COPYRIGHT_REGEX, |
| 232 | + ignored_files=KERNEL_IGNORED_FILES, |
| 233 | + ignored_ext=KERNEL_IGNORED_EXTENSIONS, |
| 234 | + ignored_patterns=KERNEL_IGNORED_PATTERNS, |
| 235 | + third_party_patterns=KERNEL_THIRD_PARTY_PATTERNS, |
| 236 | + py_ext=KERNEL_PY_EXTENSIONS, |
| 237 | + asm_ext=KERNEL_ASM_EXTENSIONS) |
155 | 238 | checker.ignoreFile(os.path.split(__file__)[-1]) |
156 | 239 |
|
157 | 240 | rc = checker.processArgs(args) |
|
0 commit comments