Yuto Takano | 3963967 | 2021-08-05 19:47:48 +0100 | [diff] [blame] | 1 | #!/usr/bin/env python3 |
| 2 | # |
| 3 | # Copyright The Mbed TLS Contributors |
| 4 | # SPDX-License-Identifier: Apache-2.0 |
| 5 | # |
| 6 | # Licensed under the Apache License, Version 2.0 (the "License"); you may |
| 7 | # not use this file except in compliance with the License. |
| 8 | # You may obtain a copy of the License at |
| 9 | # |
| 10 | # http://www.apache.org/licenses/LICENSE-2.0 |
| 11 | # |
| 12 | # Unless required by applicable law or agreed to in writing, software |
| 13 | # distributed under the License is distributed on an "AS IS" BASIS, WITHOUT |
| 14 | # WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 15 | # See the License for the specific language governing permissions and |
| 16 | # limitations under the License. |
| 17 | |
Darryl Green | d580292 | 2018-05-08 15:30:59 +0100 | [diff] [blame] | 18 | """ |
Yuto Takano | 3963967 | 2021-08-05 19:47:48 +0100 | [diff] [blame] | 19 | This script confirms that the naming of all symbols and identifiers in Mbed TLS |
Yuto Takano | 159255a | 2021-08-06 17:00:28 +0100 | [diff] [blame] | 20 | are consistent with the house style and are also self-consistent. It only runs |
| 21 | on Linux and macOS since it depends on nm. |
| 22 | |
Yuto Takano | 55c6c87 | 2021-08-09 15:35:19 +0100 | [diff] [blame] | 23 | It contains two major Python classes, CodeParser and NameChecker. They both have |
| 24 | a comprehensive "run-all" function (comprehensive_parse() and perform_checks()) |
| 25 | but the individual functions can also be used for specific needs. |
| 26 | |
| 27 | CodeParser makes heavy use of regular expressions to parse the code, and is |
| 28 | dependent on the current code formatting. Many Python C parser libraries require |
| 29 | preprocessed C code, which means no macro parsing. Compiler tools are also not |
| 30 | very helpful when we want the exact location in the original source (which |
| 31 | becomes impossible when e.g. comments are stripped). |
| 32 | |
| 33 | NameChecker performs the following checks: |
Yuto Takano | 81528c0 | 2021-08-06 16:22:06 +0100 | [diff] [blame] | 34 | |
| 35 | - All exported and available symbols in the library object files, are explicitly |
Yuto Takano | 159255a | 2021-08-06 17:00:28 +0100 | [diff] [blame] | 36 | declared in the header files. This uses the nm command. |
Yuto Takano | 81528c0 | 2021-08-06 16:22:06 +0100 | [diff] [blame] | 37 | - All macros, constants, and identifiers (function names, struct names, etc) |
Yuto Takano | 55c6c87 | 2021-08-09 15:35:19 +0100 | [diff] [blame] | 38 | follow the required regex pattern. |
Yuto Takano | 81528c0 | 2021-08-06 16:22:06 +0100 | [diff] [blame] | 39 | - Typo checking: All words that begin with MBED exist as macros or constants. |
Yuto Takano | fc54dfb | 2021-08-07 17:18:28 +0100 | [diff] [blame] | 40 | |
Yuto Takano | 55c6c87 | 2021-08-09 15:35:19 +0100 | [diff] [blame] | 41 | The script returns 0 on success, 1 on test failure, and 2 if there is a script |
| 42 | error error. Must be run from Mbed TLS root. |
Darryl Green | d580292 | 2018-05-08 15:30:59 +0100 | [diff] [blame] | 43 | """ |
Yuto Takano | 3963967 | 2021-08-05 19:47:48 +0100 | [diff] [blame] | 44 | |
| 45 | import argparse |
Yuto Takano | 977e07f | 2021-08-09 11:56:15 +0100 | [diff] [blame] | 46 | import glob |
Yuto Takano | 3963967 | 2021-08-05 19:47:48 +0100 | [diff] [blame] | 47 | import textwrap |
Darryl Green | d580292 | 2018-05-08 15:30:59 +0100 | [diff] [blame] | 48 | import os |
| 49 | import sys |
| 50 | import traceback |
| 51 | import re |
| 52 | import shutil |
| 53 | import subprocess |
| 54 | import logging |
| 55 | |
Yuto Takano | 81528c0 | 2021-08-06 16:22:06 +0100 | [diff] [blame] | 56 | # Naming patterns to check against. These are defined outside the NameCheck |
| 57 | # class for ease of modification. |
Yuto Takano | bb7dca4 | 2021-08-05 19:57:58 +0100 | [diff] [blame] | 58 | MACRO_PATTERN = r"^(MBEDTLS|PSA)_[0-9A-Z_]*[0-9A-Z]$" |
Yuto Takano | 81528c0 | 2021-08-06 16:22:06 +0100 | [diff] [blame] | 59 | CONSTANTS_PATTERN = MACRO_PATTERN |
Yuto Takano | c183893 | 2021-08-05 19:52:09 +0100 | [diff] [blame] | 60 | IDENTIFIER_PATTERN = r"^(mbedtls|psa)_[0-9a-z_]*[0-9a-z]$" |
Yuto Takano | 3963967 | 2021-08-05 19:47:48 +0100 | [diff] [blame] | 61 | |
Yuto Takano | d93fa37 | 2021-08-06 23:05:55 +0100 | [diff] [blame] | 62 | class Match(): # pylint: disable=too-few-public-methods |
Yuto Takano | 81528c0 | 2021-08-06 16:22:06 +0100 | [diff] [blame] | 63 | """ |
| 64 | A class representing a match, together with its found position. |
| 65 | |
| 66 | Fields: |
| 67 | * filename: the file that the match was in. |
| 68 | * line: the full line containing the match. |
Yuto Takano | d93fa37 | 2021-08-06 23:05:55 +0100 | [diff] [blame] | 69 | * pos: a tuple of (line_no, start, end) positions on the file line where the |
| 70 | match is. |
Yuto Takano | 81528c0 | 2021-08-06 16:22:06 +0100 | [diff] [blame] | 71 | * name: the match itself. |
| 72 | """ |
Yuto Takano | d93fa37 | 2021-08-06 23:05:55 +0100 | [diff] [blame] | 73 | def __init__(self, filename, line, pos, name): |
Yuto Takano | 3963967 | 2021-08-05 19:47:48 +0100 | [diff] [blame] | 74 | self.filename = filename |
| 75 | self.line = line |
| 76 | self.pos = pos |
| 77 | self.name = name |
Yuto Takano | 3963967 | 2021-08-05 19:47:48 +0100 | [diff] [blame] | 78 | |
Yuto Takano | a4e7512 | 2021-08-06 17:23:28 +0100 | [diff] [blame] | 79 | def __str__(self): |
Yuto Takano | 381fda8 | 2021-08-06 23:37:20 +0100 | [diff] [blame] | 80 | ln_str = str(self.pos[0]) |
| 81 | gutter_len = max(4, len(ln_str)) |
| 82 | gutter = (gutter_len - len(ln_str)) * " " + ln_str |
| 83 | underline = self.pos[1] * " " + (self.pos[2] - self.pos[1]) * "^" |
| 84 | |
Yuto Takano | a4e7512 | 2021-08-06 17:23:28 +0100 | [diff] [blame] | 85 | return ( |
Yuto Takano | 381fda8 | 2021-08-06 23:37:20 +0100 | [diff] [blame] | 86 | " {0} |\n".format(gutter_len * " ") + |
| 87 | " {0} | {1}".format(gutter, self.line) + |
Yuto Takano | 55614b5 | 2021-08-07 01:00:18 +0100 | [diff] [blame] | 88 | " {0} | {1}\n".format(gutter_len * " ", underline) |
Yuto Takano | a4e7512 | 2021-08-06 17:23:28 +0100 | [diff] [blame] | 89 | ) |
Yuto Takano | d93fa37 | 2021-08-06 23:05:55 +0100 | [diff] [blame] | 90 | |
| 91 | class Problem(): # pylint: disable=too-few-public-methods |
Yuto Takano | 81528c0 | 2021-08-06 16:22:06 +0100 | [diff] [blame] | 92 | """ |
| 93 | A parent class representing a form of static analysis error. |
Yuto Takano | 81528c0 | 2021-08-06 16:22:06 +0100 | [diff] [blame] | 94 | """ |
Yuto Takano | 3963967 | 2021-08-05 19:47:48 +0100 | [diff] [blame] | 95 | def __init__(self): |
Yuto Takano | d70d446 | 2021-08-09 12:45:51 +0100 | [diff] [blame] | 96 | self.quiet = False |
Yuto Takano | 3963967 | 2021-08-05 19:47:48 +0100 | [diff] [blame] | 97 | self.textwrapper = textwrap.TextWrapper() |
Yuto Takano | 81528c0 | 2021-08-06 16:22:06 +0100 | [diff] [blame] | 98 | self.textwrapper.width = 80 |
Yuto Takano | a4e7512 | 2021-08-06 17:23:28 +0100 | [diff] [blame] | 99 | self.textwrapper.initial_indent = " > " |
Yuto Takano | 81528c0 | 2021-08-06 16:22:06 +0100 | [diff] [blame] | 100 | self.textwrapper.subsequent_indent = " " |
Yuto Takano | 3963967 | 2021-08-05 19:47:48 +0100 | [diff] [blame] | 101 | |
Yuto Takano | d93fa37 | 2021-08-06 23:05:55 +0100 | [diff] [blame] | 102 | class SymbolNotInHeader(Problem): # pylint: disable=too-few-public-methods |
Yuto Takano | 81528c0 | 2021-08-06 16:22:06 +0100 | [diff] [blame] | 103 | """ |
| 104 | A problem that occurs when an exported/available symbol in the object file |
| 105 | is not explicitly declared in header files. Created with |
| 106 | NameCheck.check_symbols_declared_in_header() |
| 107 | |
| 108 | Fields: |
| 109 | * symbol_name: the name of the symbol. |
| 110 | """ |
Yuto Takano | d70d446 | 2021-08-09 12:45:51 +0100 | [diff] [blame] | 111 | def __init__(self, symbol_name): |
Yuto Takano | 3963967 | 2021-08-05 19:47:48 +0100 | [diff] [blame] | 112 | self.symbol_name = symbol_name |
| 113 | Problem.__init__(self) |
| 114 | |
| 115 | def __str__(self): |
Yuto Takano | 55614b5 | 2021-08-07 01:00:18 +0100 | [diff] [blame] | 116 | if self.quiet: |
| 117 | return "{0}".format(self.symbol_name) |
| 118 | |
Yuto Takano | 3963967 | 2021-08-05 19:47:48 +0100 | [diff] [blame] | 119 | return self.textwrapper.fill( |
| 120 | "'{0}' was found as an available symbol in the output of nm, " |
| 121 | "however it was not declared in any header files." |
| 122 | .format(self.symbol_name)) |
| 123 | |
Yuto Takano | d93fa37 | 2021-08-06 23:05:55 +0100 | [diff] [blame] | 124 | class PatternMismatch(Problem): # pylint: disable=too-few-public-methods |
Yuto Takano | 81528c0 | 2021-08-06 16:22:06 +0100 | [diff] [blame] | 125 | """ |
| 126 | A problem that occurs when something doesn't match the expected pattern. |
| 127 | Created with NameCheck.check_match_pattern() |
| 128 | |
| 129 | Fields: |
| 130 | * pattern: the expected regex pattern |
| 131 | * match: the Match object in question |
| 132 | """ |
Yuto Takano | d70d446 | 2021-08-09 12:45:51 +0100 | [diff] [blame] | 133 | def __init__(self, pattern, match): |
Yuto Takano | 3963967 | 2021-08-05 19:47:48 +0100 | [diff] [blame] | 134 | self.pattern = pattern |
| 135 | self.match = match |
| 136 | Problem.__init__(self) |
Yuto Takano | 81528c0 | 2021-08-06 16:22:06 +0100 | [diff] [blame] | 137 | |
Yuto Takano | 3963967 | 2021-08-05 19:47:48 +0100 | [diff] [blame] | 138 | def __str__(self): |
Yuto Takano | 55614b5 | 2021-08-07 01:00:18 +0100 | [diff] [blame] | 139 | if self.quiet: |
Yuto Takano | d70d446 | 2021-08-09 12:45:51 +0100 | [diff] [blame] | 140 | return ( |
Yuto Takano | 206b022 | 2021-08-10 11:30:43 +0100 | [diff] [blame] | 141 | "{0}:{1}:{2}" |
Yuto Takano | d70d446 | 2021-08-09 12:45:51 +0100 | [diff] [blame] | 142 | .format(self.match.filename, self.match.pos[0], self.match.name) |
| 143 | ) |
Yuto Takano | 55614b5 | 2021-08-07 01:00:18 +0100 | [diff] [blame] | 144 | |
Yuto Takano | 3963967 | 2021-08-05 19:47:48 +0100 | [diff] [blame] | 145 | return self.textwrapper.fill( |
Yuto Takano | a4e7512 | 2021-08-06 17:23:28 +0100 | [diff] [blame] | 146 | "{0}:{1}: '{2}' does not match the required pattern '{3}'." |
| 147 | .format( |
| 148 | self.match.filename, |
Yuto Takano | d93fa37 | 2021-08-06 23:05:55 +0100 | [diff] [blame] | 149 | self.match.pos[0], |
Yuto Takano | a4e7512 | 2021-08-06 17:23:28 +0100 | [diff] [blame] | 150 | self.match.name, |
Yuto Takano | d70d446 | 2021-08-09 12:45:51 +0100 | [diff] [blame] | 151 | self.pattern |
| 152 | ) |
| 153 | ) + "\n" + str(self.match) |
Yuto Takano | 3963967 | 2021-08-05 19:47:48 +0100 | [diff] [blame] | 154 | |
Yuto Takano | d93fa37 | 2021-08-06 23:05:55 +0100 | [diff] [blame] | 155 | class Typo(Problem): # pylint: disable=too-few-public-methods |
Yuto Takano | 81528c0 | 2021-08-06 16:22:06 +0100 | [diff] [blame] | 156 | """ |
| 157 | A problem that occurs when a word using MBED doesn't appear to be defined as |
| 158 | constants nor enum values. Created with NameCheck.check_for_typos() |
| 159 | |
| 160 | Fields: |
| 161 | * match: the Match object of the MBED name in question. |
| 162 | """ |
Yuto Takano | d70d446 | 2021-08-09 12:45:51 +0100 | [diff] [blame] | 163 | def __init__(self, match): |
Yuto Takano | 3963967 | 2021-08-05 19:47:48 +0100 | [diff] [blame] | 164 | self.match = match |
| 165 | Problem.__init__(self) |
Yuto Takano | 81528c0 | 2021-08-06 16:22:06 +0100 | [diff] [blame] | 166 | |
Yuto Takano | 3963967 | 2021-08-05 19:47:48 +0100 | [diff] [blame] | 167 | def __str__(self): |
Yuto Takano | 55614b5 | 2021-08-07 01:00:18 +0100 | [diff] [blame] | 168 | if self.quiet: |
Yuto Takano | d70d446 | 2021-08-09 12:45:51 +0100 | [diff] [blame] | 169 | return ( |
| 170 | "{0}:{1}:{2}" |
| 171 | .format(self.match.filename, self.match.pos[0], self.match.name) |
| 172 | ) |
Yuto Takano | 55614b5 | 2021-08-07 01:00:18 +0100 | [diff] [blame] | 173 | |
Yuto Takano | 3963967 | 2021-08-05 19:47:48 +0100 | [diff] [blame] | 174 | return self.textwrapper.fill( |
Yuto Takano | a4e7512 | 2021-08-06 17:23:28 +0100 | [diff] [blame] | 175 | "{0}:{1}: '{2}' looks like a typo. It was not found in any " |
| 176 | "macros or any enums. If this is not a typo, put " |
| 177 | "//no-check-names after it." |
Yuto Takano | d70d446 | 2021-08-09 12:45:51 +0100 | [diff] [blame] | 178 | .format(self.match.filename, self.match.pos[0], self.match.name) |
| 179 | ) + "\n" + str(self.match) |
Darryl Green | d580292 | 2018-05-08 15:30:59 +0100 | [diff] [blame] | 180 | |
Yuto Takano | 55c6c87 | 2021-08-09 15:35:19 +0100 | [diff] [blame] | 181 | class CodeParser(): |
Yuto Takano | 81528c0 | 2021-08-06 16:22:06 +0100 | [diff] [blame] | 182 | """ |
Yuto Takano | 55c6c87 | 2021-08-09 15:35:19 +0100 | [diff] [blame] | 183 | Class for retrieving files and parsing the code. This can be used |
| 184 | independently of the checks that NameChecker performs, for example for |
| 185 | list_internal_identifiers.py. |
Yuto Takano | 81528c0 | 2021-08-06 16:22:06 +0100 | [diff] [blame] | 186 | """ |
Yuto Takano | 55c6c87 | 2021-08-09 15:35:19 +0100 | [diff] [blame] | 187 | def __init__(self, log): |
| 188 | self.log = log |
Yuto Takano | fc54dfb | 2021-08-07 17:18:28 +0100 | [diff] [blame] | 189 | self.check_repo_path() |
Yuto Takano | 977e07f | 2021-08-09 11:56:15 +0100 | [diff] [blame] | 190 | |
Yuto Takano | 8e9a219 | 2021-08-09 14:48:53 +0100 | [diff] [blame] | 191 | # Memo for storing "glob expression": set(filepaths) |
| 192 | self.files = {} |
| 193 | |
Yuto Takano | 977e07f | 2021-08-09 11:56:15 +0100 | [diff] [blame] | 194 | # Globally excluded filenames |
Yuto Takano | 8e9a219 | 2021-08-09 14:48:53 +0100 | [diff] [blame] | 195 | self.excluded_files = ["**/bn_mul", "**/compat-2.x.h"] |
Yuto Takano | 977e07f | 2021-08-09 11:56:15 +0100 | [diff] [blame] | 196 | |
Yuto Takano | fc54dfb | 2021-08-07 17:18:28 +0100 | [diff] [blame] | 197 | @staticmethod |
| 198 | def check_repo_path(): |
| 199 | """ |
| 200 | Check that the current working directory is the project root, and throw |
| 201 | an exception if not. |
| 202 | """ |
| 203 | if not all(os.path.isdir(d) for d in ["include", "library", "tests"]): |
| 204 | raise Exception("This script must be run from Mbed TLS root") |
| 205 | |
Yuto Takano | 55c6c87 | 2021-08-09 15:35:19 +0100 | [diff] [blame] | 206 | def comprehensive_parse(self): |
Yuto Takano | 3963967 | 2021-08-05 19:47:48 +0100 | [diff] [blame] | 207 | """ |
Yuto Takano | 55c6c87 | 2021-08-09 15:35:19 +0100 | [diff] [blame] | 208 | Comprehensive ("default") function to call each parsing function and |
| 209 | retrieve various elements of the code, together with the source location. |
Darryl Green | d580292 | 2018-05-08 15:30:59 +0100 | [diff] [blame] | 210 | |
Yuto Takano | 55c6c87 | 2021-08-09 15:35:19 +0100 | [diff] [blame] | 211 | Returns a dict of parsed item key to the corresponding List of Matches. |
Yuto Takano | 81528c0 | 2021-08-06 16:22:06 +0100 | [diff] [blame] | 212 | """ |
| 213 | self.log.info("Parsing source code...") |
Yuto Takano | d24e037 | 2021-08-06 16:42:33 +0100 | [diff] [blame] | 214 | self.log.debug( |
Yuto Takano | 5095343 | 2021-08-09 14:54:36 +0100 | [diff] [blame] | 215 | "The following files are excluded from the search: {}" |
Yuto Takano | d24e037 | 2021-08-06 16:42:33 +0100 | [diff] [blame] | 216 | .format(str(self.excluded_files)) |
| 217 | ) |
Yuto Takano | 81528c0 | 2021-08-06 16:22:06 +0100 | [diff] [blame] | 218 | |
Yuto Takano | 8e9a219 | 2021-08-09 14:48:53 +0100 | [diff] [blame] | 219 | all_macros = self.parse_macros([ |
| 220 | "include/mbedtls/*.h", |
| 221 | "include/psa/*.h", |
| 222 | "library/*.h", |
| 223 | "tests/include/test/drivers/*.h", |
Yuto Takano | d70d446 | 2021-08-09 12:45:51 +0100 | [diff] [blame] | 224 | "3rdparty/everest/include/everest/everest.h", |
| 225 | "3rdparty/everest/include/everest/x25519.h" |
Yuto Takano | 8e9a219 | 2021-08-09 14:48:53 +0100 | [diff] [blame] | 226 | ]) |
| 227 | enum_consts = self.parse_enum_consts([ |
| 228 | "include/mbedtls/*.h", |
| 229 | "library/*.h", |
| 230 | "3rdparty/everest/include/everest/everest.h", |
| 231 | "3rdparty/everest/include/everest/x25519.h" |
| 232 | ]) |
| 233 | identifiers = self.parse_identifiers([ |
| 234 | "include/mbedtls/*.h", |
| 235 | "include/psa/*.h", |
| 236 | "library/*.h", |
| 237 | "3rdparty/everest/include/everest/everest.h", |
| 238 | "3rdparty/everest/include/everest/x25519.h" |
| 239 | ]) |
| 240 | mbed_words = self.parse_mbed_words([ |
| 241 | "include/mbedtls/*.h", |
| 242 | "include/psa/*.h", |
| 243 | "library/*.h", |
| 244 | "3rdparty/everest/include/everest/everest.h", |
| 245 | "3rdparty/everest/include/everest/x25519.h", |
| 246 | "library/*.c", |
Yuto Takano | 81528c0 | 2021-08-06 16:22:06 +0100 | [diff] [blame] | 247 | "3rdparty/everest/library/everest.c", |
Yuto Takano | d70d446 | 2021-08-09 12:45:51 +0100 | [diff] [blame] | 248 | "3rdparty/everest/library/x25519.c" |
Yuto Takano | 8e9a219 | 2021-08-09 14:48:53 +0100 | [diff] [blame] | 249 | ]) |
Yuto Takano | 81528c0 | 2021-08-06 16:22:06 +0100 | [diff] [blame] | 250 | symbols = self.parse_symbols() |
| 251 | |
| 252 | # Remove identifier macros like mbedtls_printf or mbedtls_calloc |
| 253 | identifiers_justname = [x.name for x in identifiers] |
| 254 | actual_macros = [] |
| 255 | for macro in all_macros: |
| 256 | if macro.name not in identifiers_justname: |
| 257 | actual_macros.append(macro) |
| 258 | |
| 259 | self.log.debug("Found:") |
Yuto Takano | d70d446 | 2021-08-09 12:45:51 +0100 | [diff] [blame] | 260 | self.log.debug(" {} Total Macros".format(len(all_macros))) |
Yuto Takano | 81528c0 | 2021-08-06 16:22:06 +0100 | [diff] [blame] | 261 | self.log.debug(" {} Non-identifier Macros".format(len(actual_macros))) |
| 262 | self.log.debug(" {} Enum Constants".format(len(enum_consts))) |
| 263 | self.log.debug(" {} Identifiers".format(len(identifiers))) |
| 264 | self.log.debug(" {} Exported Symbols".format(len(symbols))) |
Yuto Takano | 55c6c87 | 2021-08-09 15:35:19 +0100 | [diff] [blame] | 265 | return { |
Yuto Takano | 81528c0 | 2021-08-06 16:22:06 +0100 | [diff] [blame] | 266 | "macros": actual_macros, |
| 267 | "enum_consts": enum_consts, |
| 268 | "identifiers": identifiers, |
| 269 | "symbols": symbols, |
Yuto Takano | d93fa37 | 2021-08-06 23:05:55 +0100 | [diff] [blame] | 270 | "mbed_words": mbed_words |
Yuto Takano | 81528c0 | 2021-08-06 16:22:06 +0100 | [diff] [blame] | 271 | } |
| 272 | |
Yuto Takano | 55c6c87 | 2021-08-09 15:35:19 +0100 | [diff] [blame] | 273 | def get_files(self, include_wildcards, exclude_wildcards): |
| 274 | """ |
| 275 | Get all files that match any of the UNIX-style wildcards. While the |
| 276 | check_names script is designed only for use on UNIX/macOS (due to nm), |
| 277 | this function alone would work fine on Windows even with forward slashes |
| 278 | in the wildcard. |
| 279 | |
| 280 | Args: |
| 281 | * include_wildcards: a List of shell-style wildcards to match filepaths. |
| 282 | * exclude_wildcards: a List of shell-style wildcards to exclude. |
| 283 | |
| 284 | Returns a List of relative filepaths. |
| 285 | """ |
| 286 | accumulator = set() |
| 287 | |
| 288 | # exclude_wildcards may be None. Also, consider the global exclusions. |
| 289 | exclude_wildcards = (exclude_wildcards or []) + self.excluded_files |
| 290 | |
| 291 | # Perform set union on the glob results. Memoise individual sets. |
| 292 | for include_wildcard in include_wildcards: |
| 293 | if include_wildcard not in self.files: |
| 294 | self.files[include_wildcard] = set(glob.glob( |
| 295 | include_wildcard, |
| 296 | recursive=True |
| 297 | )) |
| 298 | |
| 299 | accumulator = accumulator.union(self.files[include_wildcard]) |
| 300 | |
| 301 | # Perform set difference to exclude. Also use the same memo since their |
| 302 | # behaviour is pretty much identical and it can benefit from the cache. |
| 303 | for exclude_wildcard in exclude_wildcards: |
| 304 | if exclude_wildcard not in self.files: |
| 305 | self.files[exclude_wildcard] = set(glob.glob( |
| 306 | exclude_wildcard, |
| 307 | recursive=True |
| 308 | )) |
| 309 | |
| 310 | accumulator = accumulator.difference(self.files[exclude_wildcard]) |
| 311 | |
| 312 | return list(accumulator) |
| 313 | |
Yuto Takano | 8e9a219 | 2021-08-09 14:48:53 +0100 | [diff] [blame] | 314 | def parse_macros(self, include, exclude=None): |
Yuto Takano | 3963967 | 2021-08-05 19:47:48 +0100 | [diff] [blame] | 315 | """ |
| 316 | Parse all macros defined by #define preprocessor directives. |
| 317 | |
| 318 | Args: |
Yuto Takano | 8e9a219 | 2021-08-09 14:48:53 +0100 | [diff] [blame] | 319 | * include: A List of glob expressions to look for files through. |
| 320 | * exclude: A List of glob expressions for excluding files. |
Yuto Takano | 81528c0 | 2021-08-06 16:22:06 +0100 | [diff] [blame] | 321 | |
| 322 | Returns a List of Match objects for the found macros. |
Yuto Takano | 3963967 | 2021-08-05 19:47:48 +0100 | [diff] [blame] | 323 | """ |
Yuto Takano | d93fa37 | 2021-08-06 23:05:55 +0100 | [diff] [blame] | 324 | macro_regex = re.compile(r"# *define +(?P<macro>\w+)") |
| 325 | exclusions = ( |
Yuto Takano | 3963967 | 2021-08-05 19:47:48 +0100 | [diff] [blame] | 326 | "asm", "inline", "EMIT", "_CRT_SECURE_NO_DEPRECATE", "MULADDC_" |
| 327 | ) |
| 328 | |
Yuto Takano | 5095343 | 2021-08-09 14:54:36 +0100 | [diff] [blame] | 329 | files = self.get_files(include, exclude) |
| 330 | self.log.debug("Looking for macros in {} files".format(len(files))) |
Yuto Takano | d93fa37 | 2021-08-06 23:05:55 +0100 | [diff] [blame] | 331 | |
Yuto Takano | 5095343 | 2021-08-09 14:54:36 +0100 | [diff] [blame] | 332 | macros = [] |
| 333 | for header_file in files: |
Yuto Takano | a083d15 | 2021-08-07 00:25:59 +0100 | [diff] [blame] | 334 | with open(header_file, "r", encoding="utf-8") as header: |
Yuto Takano | 8f457cf | 2021-08-06 17:54:58 +0100 | [diff] [blame] | 335 | for line_no, line in enumerate(header): |
Yuto Takano | d93fa37 | 2021-08-06 23:05:55 +0100 | [diff] [blame] | 336 | for macro in macro_regex.finditer(line): |
Yuto Takano | d70d446 | 2021-08-09 12:45:51 +0100 | [diff] [blame] | 337 | if macro.group("macro").startswith(exclusions): |
| 338 | continue |
| 339 | |
| 340 | macros.append(Match( |
| 341 | header_file, |
| 342 | line, |
| 343 | (line_no, macro.start(), macro.end()), |
| 344 | macro.group("macro"))) |
Darryl Green | d580292 | 2018-05-08 15:30:59 +0100 | [diff] [blame] | 345 | |
Yuto Takano | 3963967 | 2021-08-05 19:47:48 +0100 | [diff] [blame] | 346 | return macros |
Darryl Green | d580292 | 2018-05-08 15:30:59 +0100 | [diff] [blame] | 347 | |
Yuto Takano | 8e9a219 | 2021-08-09 14:48:53 +0100 | [diff] [blame] | 348 | def parse_mbed_words(self, include, exclude=None): |
Yuto Takano | 3963967 | 2021-08-05 19:47:48 +0100 | [diff] [blame] | 349 | """ |
Yuto Takano | b47b504 | 2021-08-07 00:42:54 +0100 | [diff] [blame] | 350 | Parse all words in the file that begin with MBED, in and out of macros, |
| 351 | comments, anything. |
Yuto Takano | 3963967 | 2021-08-05 19:47:48 +0100 | [diff] [blame] | 352 | |
| 353 | Args: |
Yuto Takano | 8e9a219 | 2021-08-09 14:48:53 +0100 | [diff] [blame] | 354 | * include: A List of glob expressions to look for files through. |
| 355 | * exclude: A List of glob expressions for excluding files. |
Yuto Takano | 81528c0 | 2021-08-06 16:22:06 +0100 | [diff] [blame] | 356 | |
| 357 | Returns a List of Match objects for words beginning with MBED. |
Yuto Takano | 3963967 | 2021-08-05 19:47:48 +0100 | [diff] [blame] | 358 | """ |
Yuto Takano | b47b504 | 2021-08-07 00:42:54 +0100 | [diff] [blame] | 359 | # Typos of TLS are common, hence the broader check below than MBEDTLS. |
Yuto Takano | d93fa37 | 2021-08-06 23:05:55 +0100 | [diff] [blame] | 360 | mbed_regex = re.compile(r"\bMBED.+?_[A-Z0-9_]*") |
| 361 | exclusions = re.compile(r"// *no-check-names|#error") |
| 362 | |
Yuto Takano | 5095343 | 2021-08-09 14:54:36 +0100 | [diff] [blame] | 363 | files = self.get_files(include, exclude) |
| 364 | self.log.debug("Looking for MBED words in {} files".format(len(files))) |
Yuto Takano | d93fa37 | 2021-08-06 23:05:55 +0100 | [diff] [blame] | 365 | |
Yuto Takano | 5095343 | 2021-08-09 14:54:36 +0100 | [diff] [blame] | 366 | mbed_words = [] |
| 367 | for filename in files: |
Yuto Takano | a083d15 | 2021-08-07 00:25:59 +0100 | [diff] [blame] | 368 | with open(filename, "r", encoding="utf-8") as fp: |
Yuto Takano | 8f457cf | 2021-08-06 17:54:58 +0100 | [diff] [blame] | 369 | for line_no, line in enumerate(fp): |
Yuto Takano | d93fa37 | 2021-08-06 23:05:55 +0100 | [diff] [blame] | 370 | if exclusions.search(line): |
Yuto Takano | c62b408 | 2021-08-05 20:17:07 +0100 | [diff] [blame] | 371 | continue |
Yuto Takano | 81528c0 | 2021-08-06 16:22:06 +0100 | [diff] [blame] | 372 | |
Yuto Takano | d93fa37 | 2021-08-06 23:05:55 +0100 | [diff] [blame] | 373 | for name in mbed_regex.finditer(line): |
| 374 | mbed_words.append(Match( |
Yuto Takano | 3963967 | 2021-08-05 19:47:48 +0100 | [diff] [blame] | 375 | filename, |
| 376 | line, |
Yuto Takano | d93fa37 | 2021-08-06 23:05:55 +0100 | [diff] [blame] | 377 | (line_no, name.start(), name.end()), |
Yuto Takano | 3963967 | 2021-08-05 19:47:48 +0100 | [diff] [blame] | 378 | name.group(0) |
| 379 | )) |
| 380 | |
Yuto Takano | d93fa37 | 2021-08-06 23:05:55 +0100 | [diff] [blame] | 381 | return mbed_words |
Yuto Takano | 3963967 | 2021-08-05 19:47:48 +0100 | [diff] [blame] | 382 | |
Yuto Takano | 8e9a219 | 2021-08-09 14:48:53 +0100 | [diff] [blame] | 383 | def parse_enum_consts(self, include, exclude=None): |
Yuto Takano | 3963967 | 2021-08-05 19:47:48 +0100 | [diff] [blame] | 384 | """ |
| 385 | Parse all enum value constants that are declared. |
| 386 | |
| 387 | Args: |
Yuto Takano | 8e9a219 | 2021-08-09 14:48:53 +0100 | [diff] [blame] | 388 | * include: A List of glob expressions to look for files through. |
| 389 | * exclude: A List of glob expressions for excluding files. |
Yuto Takano | 3963967 | 2021-08-05 19:47:48 +0100 | [diff] [blame] | 390 | |
Yuto Takano | 81528c0 | 2021-08-06 16:22:06 +0100 | [diff] [blame] | 391 | Returns a List of Match objects for the findings. |
Yuto Takano | 3963967 | 2021-08-05 19:47:48 +0100 | [diff] [blame] | 392 | """ |
Yuto Takano | 5095343 | 2021-08-09 14:54:36 +0100 | [diff] [blame] | 393 | files = self.get_files(include, exclude) |
| 394 | self.log.debug("Looking for enum consts in {} files".format(len(files))) |
Yuto Takano | d93fa37 | 2021-08-06 23:05:55 +0100 | [diff] [blame] | 395 | |
Yuto Takano | 5095343 | 2021-08-09 14:54:36 +0100 | [diff] [blame] | 396 | enum_consts = [] |
| 397 | for header_file in files: |
Yuto Takano | 3963967 | 2021-08-05 19:47:48 +0100 | [diff] [blame] | 398 | # Emulate a finite state machine to parse enum declarations. |
Yuto Takano | 81528c0 | 2021-08-06 16:22:06 +0100 | [diff] [blame] | 399 | # 0 = not in enum |
| 400 | # 1 = inside enum |
| 401 | # 2 = almost inside enum |
Darryl Green | d580292 | 2018-05-08 15:30:59 +0100 | [diff] [blame] | 402 | state = 0 |
Yuto Takano | a083d15 | 2021-08-07 00:25:59 +0100 | [diff] [blame] | 403 | with open(header_file, "r", encoding="utf-8") as header: |
Yuto Takano | 8f457cf | 2021-08-06 17:54:58 +0100 | [diff] [blame] | 404 | for line_no, line in enumerate(header): |
Yuto Takano | 13ecd99 | 2021-08-06 16:56:52 +0100 | [diff] [blame] | 405 | # Match typedefs and brackets only when they are at the |
| 406 | # beginning of the line -- if they are indented, they might |
| 407 | # be sub-structures within structs, etc. |
Yuto Takano | d93fa37 | 2021-08-06 23:05:55 +0100 | [diff] [blame] | 408 | if state == 0 and re.match(r"^(typedef +)?enum +{", line): |
Darryl Green | d580292 | 2018-05-08 15:30:59 +0100 | [diff] [blame] | 409 | state = 1 |
Yuto Takano | d93fa37 | 2021-08-06 23:05:55 +0100 | [diff] [blame] | 410 | elif state == 0 and re.match(r"^(typedef +)?enum", line): |
Darryl Green | d580292 | 2018-05-08 15:30:59 +0100 | [diff] [blame] | 411 | state = 2 |
Yuto Takano | d93fa37 | 2021-08-06 23:05:55 +0100 | [diff] [blame] | 412 | elif state == 2 and re.match(r"^{", line): |
Darryl Green | d580292 | 2018-05-08 15:30:59 +0100 | [diff] [blame] | 413 | state = 1 |
Yuto Takano | d93fa37 | 2021-08-06 23:05:55 +0100 | [diff] [blame] | 414 | elif state == 1 and re.match(r"^}", line): |
Darryl Green | d580292 | 2018-05-08 15:30:59 +0100 | [diff] [blame] | 415 | state = 0 |
Yuto Takano | d93fa37 | 2021-08-06 23:05:55 +0100 | [diff] [blame] | 416 | elif state == 1 and not re.match(r" *#", line): |
Yuto Takano | 13ecd99 | 2021-08-06 16:56:52 +0100 | [diff] [blame] | 417 | enum_const = re.match(r" *(?P<enum_const>\w+)", line) |
Yuto Takano | d70d446 | 2021-08-09 12:45:51 +0100 | [diff] [blame] | 418 | if not enum_const: |
| 419 | continue |
| 420 | |
| 421 | enum_consts.append(Match( |
| 422 | header_file, |
| 423 | line, |
| 424 | (line_no, enum_const.start(), enum_const.end()), |
| 425 | enum_const.group("enum_const"))) |
Yuto Takano | 81528c0 | 2021-08-06 16:22:06 +0100 | [diff] [blame] | 426 | |
Yuto Takano | 3963967 | 2021-08-05 19:47:48 +0100 | [diff] [blame] | 427 | return enum_consts |
Darryl Green | d580292 | 2018-05-08 15:30:59 +0100 | [diff] [blame] | 428 | |
Yuto Takano | 8e9a219 | 2021-08-09 14:48:53 +0100 | [diff] [blame] | 429 | def parse_identifiers(self, include, exclude=None): |
Yuto Takano | 3963967 | 2021-08-05 19:47:48 +0100 | [diff] [blame] | 430 | """ |
| 431 | Parse all lines of a header where a function identifier is declared, |
Yuto Takano | 81528c0 | 2021-08-06 16:22:06 +0100 | [diff] [blame] | 432 | based on some huersitics. Highly dependent on formatting style. |
Yuto Takano | d70d446 | 2021-08-09 12:45:51 +0100 | [diff] [blame] | 433 | Note: .match() checks at the beginning of the string (implicit ^), while |
| 434 | .search() checks throughout. |
Darryl Green | d580292 | 2018-05-08 15:30:59 +0100 | [diff] [blame] | 435 | |
Yuto Takano | 3963967 | 2021-08-05 19:47:48 +0100 | [diff] [blame] | 436 | Args: |
Yuto Takano | 8e9a219 | 2021-08-09 14:48:53 +0100 | [diff] [blame] | 437 | * include: A List of glob expressions to look for files through. |
| 438 | * exclude: A List of glob expressions for excluding files. |
Yuto Takano | 81528c0 | 2021-08-06 16:22:06 +0100 | [diff] [blame] | 439 | |
| 440 | Returns a List of Match objects with identifiers. |
Yuto Takano | 3963967 | 2021-08-05 19:47:48 +0100 | [diff] [blame] | 441 | """ |
Yuto Takano | d93fa37 | 2021-08-06 23:05:55 +0100 | [diff] [blame] | 442 | identifier_regex = re.compile( |
| 443 | # Match " something(a" or " *something(a". Functions. |
| 444 | # Assumptions: |
| 445 | # - function definition from return type to one of its arguments is |
Yuto Takano | 55c6c87 | 2021-08-09 15:35:19 +0100 | [diff] [blame] | 446 | # all on one line |
Yuto Takano | d93fa37 | 2021-08-06 23:05:55 +0100 | [diff] [blame] | 447 | # - function definition line only contains alphanumeric, asterisk, |
| 448 | # underscore, and open bracket |
| 449 | r".* \**(\w+) *\( *\w|" |
Yuto Takano | 55c6c87 | 2021-08-09 15:35:19 +0100 | [diff] [blame] | 450 | # Match "(*something)(". |
Yuto Takano | d93fa37 | 2021-08-06 23:05:55 +0100 | [diff] [blame] | 451 | r".*\( *\* *(\w+) *\) *\(|" |
| 452 | # Match names of named data structures. |
| 453 | r"(?:typedef +)?(?:struct|union|enum) +(\w+)(?: *{)?$|" |
| 454 | # Match names of typedef instances, after closing bracket. |
Yuto Takano | d70d446 | 2021-08-09 12:45:51 +0100 | [diff] [blame] | 455 | r"}? *(\w+)[;[].*" |
| 456 | ) |
| 457 | exclusion_lines = re.compile( |
| 458 | r"^(" |
| 459 | r"extern +\"C\"|" |
| 460 | r"(typedef +)?(struct|union|enum)( *{)?$|" |
| 461 | r"} *;?$|" |
| 462 | r"$|" |
| 463 | r"//|" |
| 464 | r"#" |
| 465 | r")" |
| 466 | ) |
Yuto Takano | d93fa37 | 2021-08-06 23:05:55 +0100 | [diff] [blame] | 467 | |
Yuto Takano | 5095343 | 2021-08-09 14:54:36 +0100 | [diff] [blame] | 468 | files = self.get_files(include, exclude) |
| 469 | self.log.debug("Looking for identifiers in {} files".format(len(files))) |
| 470 | |
| 471 | identifiers = [] |
| 472 | for header_file in files: |
Yuto Takano | a083d15 | 2021-08-07 00:25:59 +0100 | [diff] [blame] | 473 | with open(header_file, "r", encoding="utf-8") as header: |
Yuto Takano | 3963967 | 2021-08-05 19:47:48 +0100 | [diff] [blame] | 474 | in_block_comment = False |
Yuto Takano | 55c6c87 | 2021-08-09 15:35:19 +0100 | [diff] [blame] | 475 | # The previous line variable is used for concatenating lines |
Yuto Takano | d70d446 | 2021-08-09 12:45:51 +0100 | [diff] [blame] | 476 | # when identifiers are formatted and spread across multiple. |
Yuto Takano | d93fa37 | 2021-08-06 23:05:55 +0100 | [diff] [blame] | 477 | previous_line = "" |
Darryl Green | d580292 | 2018-05-08 15:30:59 +0100 | [diff] [blame] | 478 | |
Yuto Takano | 8f457cf | 2021-08-06 17:54:58 +0100 | [diff] [blame] | 479 | for line_no, line in enumerate(header): |
Yuto Takano | 81528c0 | 2021-08-06 16:22:06 +0100 | [diff] [blame] | 480 | # Skip parsing this line if a block comment ends on it, |
| 481 | # but don't skip if it has just started -- there is a chance |
| 482 | # it ends on the same line. |
Yuto Takano | 3963967 | 2021-08-05 19:47:48 +0100 | [diff] [blame] | 483 | if re.search(r"/\*", line): |
Yuto Takano | 81528c0 | 2021-08-06 16:22:06 +0100 | [diff] [blame] | 484 | in_block_comment = not in_block_comment |
| 485 | if re.search(r"\*/", line): |
| 486 | in_block_comment = not in_block_comment |
Yuto Takano | 3963967 | 2021-08-05 19:47:48 +0100 | [diff] [blame] | 487 | continue |
| 488 | |
Yuto Takano | 81528c0 | 2021-08-06 16:22:06 +0100 | [diff] [blame] | 489 | if in_block_comment: |
Yuto Takano | d93fa37 | 2021-08-06 23:05:55 +0100 | [diff] [blame] | 490 | previous_line = "" |
Yuto Takano | 81528c0 | 2021-08-06 16:22:06 +0100 | [diff] [blame] | 491 | continue |
| 492 | |
Yuto Takano | d93fa37 | 2021-08-06 23:05:55 +0100 | [diff] [blame] | 493 | if exclusion_lines.match(line): |
| 494 | previous_line = "" |
Yuto Takano | 81528c0 | 2021-08-06 16:22:06 +0100 | [diff] [blame] | 495 | continue |
| 496 | |
Yuto Takano | cfc9e4a | 2021-08-06 20:02:32 +0100 | [diff] [blame] | 497 | # If the line contains only space-separated alphanumeric |
| 498 | # characters (or underscore, asterisk, or, open bracket), |
| 499 | # and nothing else, high chance it's a declaration that |
| 500 | # continues on the next line |
| 501 | if re.match(r"^([\w\*\(]+\s+)+$", line): |
Yuto Takano | d93fa37 | 2021-08-06 23:05:55 +0100 | [diff] [blame] | 502 | previous_line += line |
Yuto Takano | 81528c0 | 2021-08-06 16:22:06 +0100 | [diff] [blame] | 503 | continue |
| 504 | |
| 505 | # If previous line seemed to start an unfinished declaration |
Yuto Takano | cfc9e4a | 2021-08-06 20:02:32 +0100 | [diff] [blame] | 506 | # (as above), concat and treat them as one. |
| 507 | if previous_line: |
| 508 | line = previous_line.strip() + " " + line.strip() |
Yuto Takano | d93fa37 | 2021-08-06 23:05:55 +0100 | [diff] [blame] | 509 | previous_line = "" |
Yuto Takano | 81528c0 | 2021-08-06 16:22:06 +0100 | [diff] [blame] | 510 | |
| 511 | # Skip parsing if line has a space in front = hueristic to |
| 512 | # skip function argument lines (highly subject to formatting |
| 513 | # changes) |
| 514 | if line[0] == " ": |
Yuto Takano | 3963967 | 2021-08-05 19:47:48 +0100 | [diff] [blame] | 515 | continue |
Yuto Takano | 6f38ab3 | 2021-08-05 21:07:14 +0100 | [diff] [blame] | 516 | |
Yuto Takano | d93fa37 | 2021-08-06 23:05:55 +0100 | [diff] [blame] | 517 | identifier = identifier_regex.search(line) |
Yuto Takano | 3963967 | 2021-08-05 19:47:48 +0100 | [diff] [blame] | 518 | |
Yuto Takano | d70d446 | 2021-08-09 12:45:51 +0100 | [diff] [blame] | 519 | if not identifier: |
| 520 | continue |
| 521 | |
| 522 | # Find the group that matched, and append it |
| 523 | for group in identifier.groups(): |
| 524 | if not group: |
| 525 | continue |
| 526 | |
| 527 | identifiers.append(Match( |
| 528 | header_file, |
| 529 | line, |
| 530 | (line_no, identifier.start(), identifier.end()), |
| 531 | group)) |
Yuto Takano | 3963967 | 2021-08-05 19:47:48 +0100 | [diff] [blame] | 532 | |
| 533 | return identifiers |
| 534 | |
| 535 | def parse_symbols(self): |
| 536 | """ |
| 537 | Compile the Mbed TLS libraries, and parse the TLS, Crypto, and x509 |
| 538 | object files using nm to retrieve the list of referenced symbols. |
Yuto Takano | 81528c0 | 2021-08-06 16:22:06 +0100 | [diff] [blame] | 539 | Exceptions thrown here are rethrown because they would be critical |
| 540 | errors that void several tests, and thus needs to halt the program. This |
| 541 | is explicitly done for clarity. |
Yuto Takano | 3963967 | 2021-08-05 19:47:48 +0100 | [diff] [blame] | 542 | |
Yuto Takano | 81528c0 | 2021-08-06 16:22:06 +0100 | [diff] [blame] | 543 | Returns a List of unique symbols defined and used in the libraries. |
| 544 | """ |
| 545 | self.log.info("Compiling...") |
Yuto Takano | 3963967 | 2021-08-05 19:47:48 +0100 | [diff] [blame] | 546 | symbols = [] |
| 547 | |
| 548 | # Back up the config and atomically compile with the full configratuion. |
Yuto Takano | d70d446 | 2021-08-09 12:45:51 +0100 | [diff] [blame] | 549 | shutil.copy( |
| 550 | "include/mbedtls/mbedtls_config.h", |
| 551 | "include/mbedtls/mbedtls_config.h.bak" |
| 552 | ) |
Darryl Green | d580292 | 2018-05-08 15:30:59 +0100 | [diff] [blame] | 553 | try: |
Yuto Takano | 81528c0 | 2021-08-06 16:22:06 +0100 | [diff] [blame] | 554 | # Use check=True in all subprocess calls so that failures are raised |
| 555 | # as exceptions and logged. |
Yuto Takano | 3963967 | 2021-08-05 19:47:48 +0100 | [diff] [blame] | 556 | subprocess.run( |
Yuto Takano | 81528c0 | 2021-08-06 16:22:06 +0100 | [diff] [blame] | 557 | ["python3", "scripts/config.py", "full"], |
Yuto Takano | bcc3d99 | 2021-08-06 23:14:58 +0100 | [diff] [blame] | 558 | universal_newlines=True, |
Yuto Takano | 3963967 | 2021-08-05 19:47:48 +0100 | [diff] [blame] | 559 | check=True |
Darryl Green | d580292 | 2018-05-08 15:30:59 +0100 | [diff] [blame] | 560 | ) |
| 561 | my_environment = os.environ.copy() |
| 562 | my_environment["CFLAGS"] = "-fno-asynchronous-unwind-tables" |
Yuto Takano | 3963967 | 2021-08-05 19:47:48 +0100 | [diff] [blame] | 563 | subprocess.run( |
Darryl Green | d580292 | 2018-05-08 15:30:59 +0100 | [diff] [blame] | 564 | ["make", "clean", "lib"], |
| 565 | env=my_environment, |
Yuto Takano | bcc3d99 | 2021-08-06 23:14:58 +0100 | [diff] [blame] | 566 | universal_newlines=True, |
Yuto Takano | 3963967 | 2021-08-05 19:47:48 +0100 | [diff] [blame] | 567 | stdout=subprocess.PIPE, |
Darryl Green | d580292 | 2018-05-08 15:30:59 +0100 | [diff] [blame] | 568 | stderr=subprocess.STDOUT, |
Yuto Takano | 3963967 | 2021-08-05 19:47:48 +0100 | [diff] [blame] | 569 | check=True |
Darryl Green | d580292 | 2018-05-08 15:30:59 +0100 | [diff] [blame] | 570 | ) |
Yuto Takano | 3963967 | 2021-08-05 19:47:48 +0100 | [diff] [blame] | 571 | |
| 572 | # Perform object file analysis using nm |
Yuto Takano | d70d446 | 2021-08-09 12:45:51 +0100 | [diff] [blame] | 573 | symbols = self.parse_symbols_from_nm([ |
| 574 | "library/libmbedcrypto.a", |
| 575 | "library/libmbedtls.a", |
| 576 | "library/libmbedx509.a" |
| 577 | ]) |
Yuto Takano | 3963967 | 2021-08-05 19:47:48 +0100 | [diff] [blame] | 578 | |
| 579 | subprocess.run( |
Darryl Green | d580292 | 2018-05-08 15:30:59 +0100 | [diff] [blame] | 580 | ["make", "clean"], |
Yuto Takano | bcc3d99 | 2021-08-06 23:14:58 +0100 | [diff] [blame] | 581 | universal_newlines=True, |
Yuto Takano | 3963967 | 2021-08-05 19:47:48 +0100 | [diff] [blame] | 582 | check=True |
Darryl Green | d580292 | 2018-05-08 15:30:59 +0100 | [diff] [blame] | 583 | ) |
| 584 | except subprocess.CalledProcessError as error: |
Yuto Takano | 25eeb7b | 2021-08-06 21:27:59 +0100 | [diff] [blame] | 585 | self.log.debug(error.output) |
Yuto Takano | 81528c0 | 2021-08-06 16:22:06 +0100 | [diff] [blame] | 586 | raise error |
Yuto Takano | 3963967 | 2021-08-05 19:47:48 +0100 | [diff] [blame] | 587 | finally: |
Yuto Takano | 6fececf | 2021-08-07 17:28:23 +0100 | [diff] [blame] | 588 | # Put back the original config regardless of there being errors. |
| 589 | # Works also for keyboard interrupts. |
Yuto Takano | d70d446 | 2021-08-09 12:45:51 +0100 | [diff] [blame] | 590 | shutil.move( |
| 591 | "include/mbedtls/mbedtls_config.h.bak", |
| 592 | "include/mbedtls/mbedtls_config.h" |
| 593 | ) |
Yuto Takano | 3963967 | 2021-08-05 19:47:48 +0100 | [diff] [blame] | 594 | |
| 595 | return symbols |
| 596 | |
| 597 | def parse_symbols_from_nm(self, object_files): |
| 598 | """ |
| 599 | Run nm to retrieve the list of referenced symbols in each object file. |
| 600 | Does not return the position data since it is of no use. |
| 601 | |
Yuto Takano | 81528c0 | 2021-08-06 16:22:06 +0100 | [diff] [blame] | 602 | Args: |
Yuto Takano | 55c6c87 | 2021-08-09 15:35:19 +0100 | [diff] [blame] | 603 | * object_files: a List of compiled object filepaths to search through. |
Yuto Takano | 81528c0 | 2021-08-06 16:22:06 +0100 | [diff] [blame] | 604 | |
| 605 | Returns a List of unique symbols defined and used in any of the object |
| 606 | files. |
Yuto Takano | 3963967 | 2021-08-05 19:47:48 +0100 | [diff] [blame] | 607 | """ |
Yuto Takano | d93fa37 | 2021-08-06 23:05:55 +0100 | [diff] [blame] | 608 | nm_undefined_regex = re.compile(r"^\S+: +U |^$|^\S+:$") |
| 609 | nm_valid_regex = re.compile(r"^\S+( [0-9A-Fa-f]+)* . _*(?P<symbol>\w+)") |
Yuto Takano | 12a7ecd | 2021-08-07 00:40:29 +0100 | [diff] [blame] | 610 | exclusions = ("FStar", "Hacl") |
Yuto Takano | 3963967 | 2021-08-05 19:47:48 +0100 | [diff] [blame] | 611 | |
| 612 | symbols = [] |
| 613 | |
Yuto Takano | 81528c0 | 2021-08-06 16:22:06 +0100 | [diff] [blame] | 614 | # Gather all outputs of nm |
Yuto Takano | 3963967 | 2021-08-05 19:47:48 +0100 | [diff] [blame] | 615 | nm_output = "" |
| 616 | for lib in object_files: |
| 617 | nm_output += subprocess.run( |
| 618 | ["nm", "-og", lib], |
Yuto Takano | bcc3d99 | 2021-08-06 23:14:58 +0100 | [diff] [blame] | 619 | universal_newlines=True, |
Yuto Takano | 3963967 | 2021-08-05 19:47:48 +0100 | [diff] [blame] | 620 | stdout=subprocess.PIPE, |
| 621 | stderr=subprocess.STDOUT, |
| 622 | check=True |
| 623 | ).stdout |
Yuto Takano | 81528c0 | 2021-08-06 16:22:06 +0100 | [diff] [blame] | 624 | |
Yuto Takano | 3963967 | 2021-08-05 19:47:48 +0100 | [diff] [blame] | 625 | for line in nm_output.splitlines(): |
Yuto Takano | d93fa37 | 2021-08-06 23:05:55 +0100 | [diff] [blame] | 626 | if not nm_undefined_regex.match(line): |
| 627 | symbol = nm_valid_regex.match(line) |
Yuto Takano | 12a7ecd | 2021-08-07 00:40:29 +0100 | [diff] [blame] | 628 | if (symbol and not symbol.group("symbol").startswith(exclusions)): |
Yuto Takano | e77f699 | 2021-08-05 20:22:59 +0100 | [diff] [blame] | 629 | symbols.append(symbol.group("symbol")) |
Yuto Takano | 3963967 | 2021-08-05 19:47:48 +0100 | [diff] [blame] | 630 | else: |
| 631 | self.log.error(line) |
Yuto Takano | 81528c0 | 2021-08-06 16:22:06 +0100 | [diff] [blame] | 632 | |
Yuto Takano | 3963967 | 2021-08-05 19:47:48 +0100 | [diff] [blame] | 633 | return symbols |
| 634 | |
Yuto Takano | 55c6c87 | 2021-08-09 15:35:19 +0100 | [diff] [blame] | 635 | class NameChecker(): |
| 636 | """ |
| 637 | Representation of the core name checking operation performed by this script. |
| 638 | """ |
| 639 | def __init__(self, parse_result, log): |
| 640 | self.parse_result = parse_result |
| 641 | self.log = log |
| 642 | |
Yuto Takano | 55614b5 | 2021-08-07 01:00:18 +0100 | [diff] [blame] | 643 | def perform_checks(self, quiet=False): |
Yuto Takano | 3963967 | 2021-08-05 19:47:48 +0100 | [diff] [blame] | 644 | """ |
Yuto Takano | 55c6c87 | 2021-08-09 15:35:19 +0100 | [diff] [blame] | 645 | A comprehensive checker that performs each check in order, and outputs |
| 646 | a final verdict. |
Yuto Takano | 81528c0 | 2021-08-06 16:22:06 +0100 | [diff] [blame] | 647 | |
| 648 | Args: |
Yuto Takano | 55614b5 | 2021-08-07 01:00:18 +0100 | [diff] [blame] | 649 | * quiet: whether to hide detailed problem explanation. |
Yuto Takano | 3963967 | 2021-08-05 19:47:48 +0100 | [diff] [blame] | 650 | """ |
Yuto Takano | 81528c0 | 2021-08-06 16:22:06 +0100 | [diff] [blame] | 651 | self.log.info("=============") |
Yuto Takano | 3963967 | 2021-08-05 19:47:48 +0100 | [diff] [blame] | 652 | problems = 0 |
Yuto Takano | 55614b5 | 2021-08-07 01:00:18 +0100 | [diff] [blame] | 653 | problems += self.check_symbols_declared_in_header(quiet) |
Yuto Takano | 3963967 | 2021-08-05 19:47:48 +0100 | [diff] [blame] | 654 | |
Yuto Takano | d70d446 | 2021-08-09 12:45:51 +0100 | [diff] [blame] | 655 | pattern_checks = [ |
| 656 | ("macros", MACRO_PATTERN), |
| 657 | ("enum_consts", CONSTANTS_PATTERN), |
| 658 | ("identifiers", IDENTIFIER_PATTERN) |
| 659 | ] |
Yuto Takano | 3963967 | 2021-08-05 19:47:48 +0100 | [diff] [blame] | 660 | for group, check_pattern in pattern_checks: |
Yuto Takano | 55614b5 | 2021-08-07 01:00:18 +0100 | [diff] [blame] | 661 | problems += self.check_match_pattern(quiet, group, check_pattern) |
Yuto Takano | 3963967 | 2021-08-05 19:47:48 +0100 | [diff] [blame] | 662 | |
Yuto Takano | 55614b5 | 2021-08-07 01:00:18 +0100 | [diff] [blame] | 663 | problems += self.check_for_typos(quiet) |
Yuto Takano | 3963967 | 2021-08-05 19:47:48 +0100 | [diff] [blame] | 664 | |
| 665 | self.log.info("=============") |
| 666 | if problems > 0: |
| 667 | self.log.info("FAIL: {0} problem(s) to fix".format(str(problems))) |
Yuto Takano | 55614b5 | 2021-08-07 01:00:18 +0100 | [diff] [blame] | 668 | if quiet: |
| 669 | self.log.info("Remove --quiet to see explanations.") |
Yuto Takano | fc54dfb | 2021-08-07 17:18:28 +0100 | [diff] [blame] | 670 | else: |
| 671 | self.log.info("Use --quiet for minimal output.") |
Yuto Takano | 55c6c87 | 2021-08-09 15:35:19 +0100 | [diff] [blame] | 672 | return 1 |
Yuto Takano | 3963967 | 2021-08-05 19:47:48 +0100 | [diff] [blame] | 673 | else: |
| 674 | self.log.info("PASS") |
Yuto Takano | 55c6c87 | 2021-08-09 15:35:19 +0100 | [diff] [blame] | 675 | return 0 |
Darryl Green | d580292 | 2018-05-08 15:30:59 +0100 | [diff] [blame] | 676 | |
Yuto Takano | 55614b5 | 2021-08-07 01:00:18 +0100 | [diff] [blame] | 677 | def check_symbols_declared_in_header(self, quiet): |
Yuto Takano | 3963967 | 2021-08-05 19:47:48 +0100 | [diff] [blame] | 678 | """ |
| 679 | Perform a check that all detected symbols in the library object files |
| 680 | are properly declared in headers. |
Yuto Takano | 977e07f | 2021-08-09 11:56:15 +0100 | [diff] [blame] | 681 | Assumes parse_names_in_source() was called before this. |
Darryl Green | d580292 | 2018-05-08 15:30:59 +0100 | [diff] [blame] | 682 | |
Yuto Takano | 81528c0 | 2021-08-06 16:22:06 +0100 | [diff] [blame] | 683 | Args: |
Yuto Takano | 55614b5 | 2021-08-07 01:00:18 +0100 | [diff] [blame] | 684 | * quiet: whether to hide detailed problem explanation. |
Yuto Takano | 81528c0 | 2021-08-06 16:22:06 +0100 | [diff] [blame] | 685 | |
| 686 | Returns the number of problems that need fixing. |
Yuto Takano | 3963967 | 2021-08-05 19:47:48 +0100 | [diff] [blame] | 687 | """ |
| 688 | problems = [] |
Yuto Takano | d93fa37 | 2021-08-06 23:05:55 +0100 | [diff] [blame] | 689 | |
Yuto Takano | 3963967 | 2021-08-05 19:47:48 +0100 | [diff] [blame] | 690 | for symbol in self.parse_result["symbols"]: |
| 691 | found_symbol_declared = False |
| 692 | for identifier_match in self.parse_result["identifiers"]: |
| 693 | if symbol == identifier_match.name: |
| 694 | found_symbol_declared = True |
| 695 | break |
Yuto Takano | 81528c0 | 2021-08-06 16:22:06 +0100 | [diff] [blame] | 696 | |
Yuto Takano | 3963967 | 2021-08-05 19:47:48 +0100 | [diff] [blame] | 697 | if not found_symbol_declared: |
Yuto Takano | d70d446 | 2021-08-09 12:45:51 +0100 | [diff] [blame] | 698 | problems.append(SymbolNotInHeader(symbol)) |
Yuto Takano | 3963967 | 2021-08-05 19:47:48 +0100 | [diff] [blame] | 699 | |
Yuto Takano | d70d446 | 2021-08-09 12:45:51 +0100 | [diff] [blame] | 700 | self.output_check_result(quiet, "All symbols in header", problems) |
Yuto Takano | 3963967 | 2021-08-05 19:47:48 +0100 | [diff] [blame] | 701 | return len(problems) |
| 702 | |
Yuto Takano | 55614b5 | 2021-08-07 01:00:18 +0100 | [diff] [blame] | 703 | def check_match_pattern(self, quiet, group_to_check, check_pattern): |
Yuto Takano | 81528c0 | 2021-08-06 16:22:06 +0100 | [diff] [blame] | 704 | """ |
| 705 | Perform a check that all items of a group conform to a regex pattern. |
Yuto Takano | 977e07f | 2021-08-09 11:56:15 +0100 | [diff] [blame] | 706 | Assumes parse_names_in_source() was called before this. |
Yuto Takano | 81528c0 | 2021-08-06 16:22:06 +0100 | [diff] [blame] | 707 | |
| 708 | Args: |
Yuto Takano | 55614b5 | 2021-08-07 01:00:18 +0100 | [diff] [blame] | 709 | * quiet: whether to hide detailed problem explanation. |
Yuto Takano | 81528c0 | 2021-08-06 16:22:06 +0100 | [diff] [blame] | 710 | * group_to_check: string key to index into self.parse_result. |
| 711 | * check_pattern: the regex to check against. |
| 712 | |
| 713 | Returns the number of problems that need fixing. |
| 714 | """ |
Yuto Takano | 3963967 | 2021-08-05 19:47:48 +0100 | [diff] [blame] | 715 | problems = [] |
Yuto Takano | d93fa37 | 2021-08-06 23:05:55 +0100 | [diff] [blame] | 716 | |
Yuto Takano | 3963967 | 2021-08-05 19:47:48 +0100 | [diff] [blame] | 717 | for item_match in self.parse_result[group_to_check]: |
| 718 | if not re.match(check_pattern, item_match.name): |
| 719 | problems.append(PatternMismatch(check_pattern, item_match)) |
Yuto Takano | 201f9e8 | 2021-08-06 16:36:54 +0100 | [diff] [blame] | 720 | # Double underscore is a reserved identifier, never to be used |
Yuto Takano | c763cc3 | 2021-08-05 20:06:34 +0100 | [diff] [blame] | 721 | if re.match(r".*__.*", item_match.name): |
Yuto Takano | d70d446 | 2021-08-09 12:45:51 +0100 | [diff] [blame] | 722 | problems.append(PatternMismatch("double underscore", item_match)) |
Yuto Takano | 81528c0 | 2021-08-06 16:22:06 +0100 | [diff] [blame] | 723 | |
| 724 | self.output_check_result( |
Yuto Takano | d70d446 | 2021-08-09 12:45:51 +0100 | [diff] [blame] | 725 | quiet, |
Yuto Takano | 81528c0 | 2021-08-06 16:22:06 +0100 | [diff] [blame] | 726 | "Naming patterns of {}".format(group_to_check), |
Yuto Takano | 55614b5 | 2021-08-07 01:00:18 +0100 | [diff] [blame] | 727 | problems) |
Yuto Takano | 3963967 | 2021-08-05 19:47:48 +0100 | [diff] [blame] | 728 | return len(problems) |
Darryl Green | d580292 | 2018-05-08 15:30:59 +0100 | [diff] [blame] | 729 | |
Yuto Takano | 55614b5 | 2021-08-07 01:00:18 +0100 | [diff] [blame] | 730 | def check_for_typos(self, quiet): |
Yuto Takano | 81528c0 | 2021-08-06 16:22:06 +0100 | [diff] [blame] | 731 | """ |
| 732 | Perform a check that all words in the soure code beginning with MBED are |
| 733 | either defined as macros, or as enum constants. |
Yuto Takano | 977e07f | 2021-08-09 11:56:15 +0100 | [diff] [blame] | 734 | Assumes parse_names_in_source() was called before this. |
Yuto Takano | 81528c0 | 2021-08-06 16:22:06 +0100 | [diff] [blame] | 735 | |
| 736 | Args: |
Yuto Takano | 55614b5 | 2021-08-07 01:00:18 +0100 | [diff] [blame] | 737 | * quiet: whether to hide detailed problem explanation. |
Yuto Takano | 81528c0 | 2021-08-06 16:22:06 +0100 | [diff] [blame] | 738 | |
| 739 | Returns the number of problems that need fixing. |
| 740 | """ |
Yuto Takano | 3963967 | 2021-08-05 19:47:48 +0100 | [diff] [blame] | 741 | problems = [] |
Yuto Takano | 3963967 | 2021-08-05 19:47:48 +0100 | [diff] [blame] | 742 | |
Yuto Takano | d70d446 | 2021-08-09 12:45:51 +0100 | [diff] [blame] | 743 | # Set comprehension, equivalent to a list comprehension wrapped by set() |
Yuto Takano | d93fa37 | 2021-08-06 23:05:55 +0100 | [diff] [blame] | 744 | all_caps_names = { |
| 745 | match.name |
| 746 | for match |
| 747 | in self.parse_result["macros"] + self.parse_result["enum_consts"]} |
| 748 | typo_exclusion = re.compile(r"XXX|__|_$|^MBEDTLS_.*CONFIG_FILE$") |
Yuto Takano | 3963967 | 2021-08-05 19:47:48 +0100 | [diff] [blame] | 749 | |
Yuto Takano | d93fa37 | 2021-08-06 23:05:55 +0100 | [diff] [blame] | 750 | for name_match in self.parse_result["mbed_words"]: |
Yuto Takano | 81528c0 | 2021-08-06 16:22:06 +0100 | [diff] [blame] | 751 | found = name_match.name in all_caps_names |
| 752 | |
| 753 | # Since MBEDTLS_PSA_ACCEL_XXX defines are defined by the |
| 754 | # PSA driver, they will not exist as macros. However, they |
| 755 | # should still be checked for typos using the equivalent |
| 756 | # BUILTINs that exist. |
| 757 | if "MBEDTLS_PSA_ACCEL_" in name_match.name: |
| 758 | found = name_match.name.replace( |
| 759 | "MBEDTLS_PSA_ACCEL_", |
| 760 | "MBEDTLS_PSA_BUILTIN_") in all_caps_names |
| 761 | |
Yuto Takano | d93fa37 | 2021-08-06 23:05:55 +0100 | [diff] [blame] | 762 | if not found and not typo_exclusion.search(name_match.name): |
Yuto Takano | d70d446 | 2021-08-09 12:45:51 +0100 | [diff] [blame] | 763 | problems.append(Typo(name_match)) |
Yuto Takano | 3963967 | 2021-08-05 19:47:48 +0100 | [diff] [blame] | 764 | |
Yuto Takano | d70d446 | 2021-08-09 12:45:51 +0100 | [diff] [blame] | 765 | self.output_check_result(quiet, "Likely typos", problems) |
Yuto Takano | 81528c0 | 2021-08-06 16:22:06 +0100 | [diff] [blame] | 766 | return len(problems) |
| 767 | |
Yuto Takano | d70d446 | 2021-08-09 12:45:51 +0100 | [diff] [blame] | 768 | def output_check_result(self, quiet, name, problems): |
Yuto Takano | 81528c0 | 2021-08-06 16:22:06 +0100 | [diff] [blame] | 769 | """ |
| 770 | Write out the PASS/FAIL status of a performed check depending on whether |
| 771 | there were problems. |
Yuto Takano | d70d446 | 2021-08-09 12:45:51 +0100 | [diff] [blame] | 772 | |
| 773 | Args: |
| 774 | * quiet: whether to hide detailed problem explanation. |
| 775 | * name: the name of the test |
| 776 | * problems: a List of encountered Problems |
Yuto Takano | 81528c0 | 2021-08-06 16:22:06 +0100 | [diff] [blame] | 777 | """ |
Yuto Takano | 3963967 | 2021-08-05 19:47:48 +0100 | [diff] [blame] | 778 | if problems: |
Yuto Takano | 55614b5 | 2021-08-07 01:00:18 +0100 | [diff] [blame] | 779 | self.log.info("{}: FAIL\n".format(name)) |
| 780 | for problem in problems: |
Yuto Takano | d70d446 | 2021-08-09 12:45:51 +0100 | [diff] [blame] | 781 | problem.quiet = quiet |
Yuto Takano | 55614b5 | 2021-08-07 01:00:18 +0100 | [diff] [blame] | 782 | self.log.warning(str(problem)) |
Darryl Green | d580292 | 2018-05-08 15:30:59 +0100 | [diff] [blame] | 783 | else: |
Yuto Takano | 81528c0 | 2021-08-06 16:22:06 +0100 | [diff] [blame] | 784 | self.log.info("{}: PASS".format(name)) |
Darryl Green | d580292 | 2018-05-08 15:30:59 +0100 | [diff] [blame] | 785 | |
Yuto Takano | 3963967 | 2021-08-05 19:47:48 +0100 | [diff] [blame] | 786 | def main(): |
| 787 | """ |
Yuto Takano | 55c6c87 | 2021-08-09 15:35:19 +0100 | [diff] [blame] | 788 | Perform argument parsing, and create an instance of CodeParser and |
| 789 | NameChecker to begin the core operation. |
Yuto Takano | 3963967 | 2021-08-05 19:47:48 +0100 | [diff] [blame] | 790 | """ |
Yuto Takano | f005c33 | 2021-08-09 13:56:36 +0100 | [diff] [blame] | 791 | parser = argparse.ArgumentParser( |
Yuto Takano | 3963967 | 2021-08-05 19:47:48 +0100 | [diff] [blame] | 792 | formatter_class=argparse.RawDescriptionHelpFormatter, |
| 793 | description=( |
| 794 | "This script confirms that the naming of all symbols and identifiers " |
| 795 | "in Mbed TLS are consistent with the house style and are also " |
| 796 | "self-consistent.\n\n" |
Yuto Takano | f005c33 | 2021-08-09 13:56:36 +0100 | [diff] [blame] | 797 | "Expected to be run from the MbedTLS root directory.") |
| 798 | ) |
| 799 | parser.add_argument( |
| 800 | "-v", "--verbose", |
| 801 | action="store_true", |
| 802 | help="show parse results" |
| 803 | ) |
| 804 | parser.add_argument( |
| 805 | "-q", "--quiet", |
| 806 | action="store_true", |
| 807 | help="hide unnecessary text, explanations, and highlighs" |
| 808 | ) |
Darryl Green | d580292 | 2018-05-08 15:30:59 +0100 | [diff] [blame] | 809 | |
Yuto Takano | f005c33 | 2021-08-09 13:56:36 +0100 | [diff] [blame] | 810 | args = parser.parse_args() |
Darryl Green | d580292 | 2018-05-08 15:30:59 +0100 | [diff] [blame] | 811 | |
Yuto Takano | 55c6c87 | 2021-08-09 15:35:19 +0100 | [diff] [blame] | 812 | # Configure the global logger, which is then passed to the classes below |
| 813 | log = logging.getLogger() |
| 814 | log.setLevel(logging.DEBUG if args.verbose else logging.INFO) |
| 815 | log.addHandler(logging.StreamHandler()) |
| 816 | |
Darryl Green | d580292 | 2018-05-08 15:30:59 +0100 | [diff] [blame] | 817 | try: |
Yuto Takano | 55c6c87 | 2021-08-09 15:35:19 +0100 | [diff] [blame] | 818 | code_parser = CodeParser(log) |
| 819 | parse_result = code_parser.comprehensive_parse() |
Yuto Takano | d93fa37 | 2021-08-06 23:05:55 +0100 | [diff] [blame] | 820 | except Exception: # pylint: disable=broad-except |
Darryl Green | d580292 | 2018-05-08 15:30:59 +0100 | [diff] [blame] | 821 | traceback.print_exc() |
| 822 | sys.exit(2) |
| 823 | |
Yuto Takano | 55c6c87 | 2021-08-09 15:35:19 +0100 | [diff] [blame] | 824 | name_checker = NameChecker(parse_result, log) |
| 825 | return_code = name_checker.perform_checks(quiet=args.quiet) |
| 826 | |
| 827 | sys.exit(return_code) |
| 828 | |
Darryl Green | d580292 | 2018-05-08 15:30:59 +0100 | [diff] [blame] | 829 | if __name__ == "__main__": |
Yuto Takano | 3963967 | 2021-08-05 19:47:48 +0100 | [diff] [blame] | 830 | main() |