3 # * FreeRTOS Kernel <DEVELOPMENT BRANCH>
4 # * Copyright (C) 2024 Amazon.com, Inc. or its affiliates. All Rights Reserved.
6 # * SPDX-License-Identifier: MIT
8 # * Permission is hereby granted, free of charge, to any person obtaining a copy of
9 # * this software and associated documentation files (the "Software"), to deal in
10 # * the Software without restriction, including without limitation the rights to
11 # * use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
12 # * the Software, and to permit persons to whom the Software is furnished to do so,
13 # * subject to the following conditions:
15 # * The above copyright notice and this permission notice shall be included in all
16 # * copies or substantial portions of the Software.
18 # * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
19 # * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
20 # * FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
21 # * COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
22 # * IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
23 # * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
25 # * https://www.FreeRTOS.org
26 # * https://github.com/FreeRTOS
32 from common.header_checker import HeaderChecker
34 #--------------------------------------------------------------------------------------------------
36 #--------------------------------------------------------------------------------------------------
37 KERNEL_IGNORED_FILES = [
45 KERNEL_IGNORED_EXTENSIONS = [
71 KERNEL_ASM_EXTENSIONS = [
86 KERNEL_PY_EXTENSIONS = [
90 KERNEL_IGNORED_PATTERNS = [
92 r'.*portable/IAR/AtmelSAM7S64/.*AT91SAM7.*',
93 r'.*portable/GCC/ARM7_AT91SAM7S/.*',
94 r'.*portable/MPLAB/PIC18F/stdio.h',
95 r'.*portable/ThirdParty/xClang/XCOREAI/*',
99 r'.*portable/template/*',
100 r'.*template_configuration/*'
103 KERNEL_THIRD_PARTY_PATTERNS = [
104 r'.*portable/ThirdParty/GCC/Posix/port*',
105 r'.*portable/ThirdParty/*',
106 r'.*portable/IAR/AVR32_UC3/.*',
107 r'.*portable/GCC/AVR32_UC3/.*',
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*',
121 ' * FreeRTOS Kernel <DEVELOPMENT BRANCH>\n',
122 ' * Copyright (C) 2021 Amazon.com, Inc. or its affiliates. All Rights Reserved.\n',
124 ' * SPDX-License-Identifier: MIT\n',
126 ' * Permission is hereby granted, free of charge, to any person obtaining a copy of\n',
127 ' * this software and associated documentation files (the "Software"), to deal in\n',
128 ' * the Software without restriction, including without limitation the rights to\n',
129 ' * use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of\n',
130 ' * the Software, and to permit persons to whom the Software is furnished to do so,\n',
131 ' * subject to the following conditions:\n',
133 ' * The above copyright notice and this permission notice shall be included in all\n',
134 ' * copies or substantial portions of the Software.\n',
136 ' * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR\n',
137 ' * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS\n',
138 ' * FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR\n',
139 ' * COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER\n',
140 ' * IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN\n',
141 ' * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.\n',
143 ' * https://www.FreeRTOS.org\n',
144 ' * https://github.com/FreeRTOS\n',
150 FREERTOS_COPYRIGHT_REGEX = r"^(;|#)?( *(\/\*|\*|#|\/\/))? Copyright \(C\) 20\d\d Amazon.com, Inc. or its affiliates. All Rights Reserved\.( \*\/)?$"
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"(^(;|#)?( *(\/\*|\*|#|\/\/))? <open-source-office@arm.com>( \*\/)?$)"
157 class KernelHeaderChecker(HeaderChecker):
164 ignored_patterns=None,
167 third_party_patterns=None,
168 copyright_regex = None
170 super().__init__(header, padding, ignored_files, ignored_ext, ignored_patterns,
171 py_ext, asm_ext, third_party_patterns, copyright_regex)
173 self.armCollabRegex = re.compile(FREERTOS_ARM_COLLAB_COPYRIGHT_REGEX)
175 self.armCollabFilesPatternList = []
176 for pattern in KERNEL_ARM_COLLAB_FILES_PATTERNS:
177 self.armCollabFilesPatternList.append(re.compile(pattern))
179 def isArmCollabFile(self, path):
180 for pattern in self.armCollabFilesPatternList:
181 if pattern.match(path):
185 def checkArmCollabFile(self, path):
187 file_ext = os.path.splitext(path)[-1]
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
194 if (len(lines) > 0) and (lines[0].find("#!") == 0):
195 lines.remove(lines[0])
197 # Split lines in sections.
200 headers["copyright"] = []
203 if self.armCollabRegex.match(line):
204 headers["copyright"].append(line)
205 elif "SPDX-License-Identifier:" in line:
206 headers["spdx"].append(line)
208 headers["text"].append(line)
210 text_equal = self.isValidHeaderSection(file_ext, "text", headers["text"])
211 spdx_equal = self.isValidHeaderSection(file_ext, "spdx", headers["spdx"])
213 if text_equal and spdx_equal and len(headers["copyright"]) == 3:
218 def customCheck(self, path):
220 if self.isArmCollabFile(path):
221 isValid = self.checkArmCollabFile(path)
226 parser = HeaderChecker.configArgParser()
227 args = parser.parse_args()
229 # Configure the checks then run
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)
238 checker.ignoreFile(os.path.split(__file__)[-1])
240 rc = checker.processArgs(args)
242 checker.showHelp(__file__)
246 if __name__ == '__main__':