David Horstmann | fa928f1 | 2022-11-01 15:46:16 +0000 | [diff] [blame] | 1 | #!/usr/bin/env python3 |
| 2 | """Check or fix the code style by running Uncrustify. |
David Horstmann | 8b5a449 | 2023-01-16 18:28:21 +0000 | [diff] [blame] | 3 | |
| 4 | This script must be run from the root of a Git work tree containing Mbed TLS. |
David Horstmann | fa928f1 | 2022-11-01 15:46:16 +0000 | [diff] [blame] | 5 | """ |
| 6 | # Copyright The Mbed TLS Contributors |
Dave Rodgman | 16799db | 2023-11-02 19:47:20 +0000 | [diff] [blame] | 7 | # SPDX-License-Identifier: Apache-2.0 OR GPL-2.0-or-later |
David Horstmann | fa928f1 | 2022-11-01 15:46:16 +0000 | [diff] [blame] | 8 | import argparse |
David Horstmann | fa928f1 | 2022-11-01 15:46:16 +0000 | [diff] [blame] | 9 | import os |
Gilles Peskine | 9a3771e | 2022-12-19 00:48:58 +0100 | [diff] [blame] | 10 | import re |
David Horstmann | fa928f1 | 2022-11-01 15:46:16 +0000 | [diff] [blame] | 11 | import subprocess |
| 12 | import sys |
Gilles Peskine | 43838b8 | 2023-06-22 20:29:41 +0200 | [diff] [blame] | 13 | from typing import FrozenSet, List, Optional |
David Horstmann | fa928f1 | 2022-11-01 15:46:16 +0000 | [diff] [blame] | 14 | |
David Horstmann | 2cf779c | 2022-12-08 14:44:36 +0000 | [diff] [blame] | 15 | UNCRUSTIFY_SUPPORTED_VERSION = "0.75.1" |
David Horstmann | ae93a3f | 2022-12-08 17:03:01 +0000 | [diff] [blame] | 16 | CONFIG_FILE = ".uncrustify.cfg" |
David Horstmann | fa928f1 | 2022-11-01 15:46:16 +0000 | [diff] [blame] | 17 | UNCRUSTIFY_EXE = "uncrustify" |
| 18 | UNCRUSTIFY_ARGS = ["-c", CONFIG_FILE] |
Gilles Peskine | 9a3771e | 2022-12-19 00:48:58 +0100 | [diff] [blame] | 19 | CHECK_GENERATED_FILES = "tests/scripts/check-generated-files.sh" |
David Horstmann | fa928f1 | 2022-11-01 15:46:16 +0000 | [diff] [blame] | 20 | |
David Horstmann | ca13c4f | 2022-12-08 14:33:52 +0000 | [diff] [blame] | 21 | def print_err(*args): |
David Horstmann | 6b3ce30 | 2023-01-24 18:36:41 +0000 | [diff] [blame] | 22 | print("Error: ", *args, file=sys.stderr) |
David Horstmann | ca13c4f | 2022-12-08 14:33:52 +0000 | [diff] [blame] | 23 | |
Pengyu Lv | acbeb7f | 2023-02-06 14:27:30 +0800 | [diff] [blame] | 24 | # Print the file names that will be skipped and the help message |
| 25 | def print_skip(files_to_skip): |
| 26 | print() |
| 27 | print(*files_to_skip, sep=", SKIP\n", end=", SKIP\n") |
Pengyu Lv | c36743f | 2023-02-15 10:20:40 +0800 | [diff] [blame] | 28 | print("Warning: The listed files will be skipped because\n" |
| 29 | "they are not known to git.") |
Pengyu Lv | acbeb7f | 2023-02-06 14:27:30 +0800 | [diff] [blame] | 30 | print() |
| 31 | |
Gilles Peskine | 9a3771e | 2022-12-19 00:48:58 +0100 | [diff] [blame] | 32 | # Match FILENAME(s) in "check SCRIPT (FILENAME...)" |
| 33 | CHECK_CALL_RE = re.compile(r"\n\s*check\s+[^\s#$&*?;|]+([^\n#$&*?;|]+)", |
| 34 | re.ASCII) |
| 35 | def list_generated_files() -> FrozenSet[str]: |
| 36 | """Return the names of generated files. |
| 37 | |
| 38 | We don't reformat generated files, since the result might be different |
| 39 | from the output of the generator. Ideally the result of the generator |
| 40 | would conform to the code style, but this would be difficult, especially |
| 41 | with respect to the placement of line breaks in long logical lines. |
| 42 | """ |
| 43 | # Parse check-generated-files.sh to get an up-to-date list of |
| 44 | # generated files. Read the file rather than calling it so that |
| 45 | # this script only depends on Git, Python and uncrustify, and not other |
| 46 | # tools such as sh or grep which might not be available on Windows. |
| 47 | # This introduces a limitation: check-generated-files.sh must have |
| 48 | # the expected format and must list the files explicitly, not through |
| 49 | # wildcards or command substitution. |
| 50 | content = open(CHECK_GENERATED_FILES, encoding="utf-8").read() |
| 51 | checks = re.findall(CHECK_CALL_RE, content) |
| 52 | return frozenset(word for s in checks for word in s.split()) |
| 53 | |
Dave Rodgman | 2a9eb22 | 2024-03-18 11:15:06 +0000 | [diff] [blame] | 54 | # Check for comment string indicating an auto-generated file |
Dave Rodgman | 1bd787a | 2024-03-18 12:32:49 +0000 | [diff] [blame] | 55 | AUTOGEN_RE = re.compile(r"Warning[ :-]+This file is (now )?auto[ -]?generated", |
Dave Rodgman | 4e4540d | 2024-03-18 11:55:39 +0000 | [diff] [blame] | 56 | re.ASCII | re.IGNORECASE) |
Dave Rodgman | 2a9eb22 | 2024-03-18 11:15:06 +0000 | [diff] [blame] | 57 | def is_file_autogenerated(filename): |
| 58 | content = open(filename, encoding="utf-8").read() |
| 59 | return AUTOGEN_RE.search(content) is not None |
| 60 | |
Gilles Peskine | 43838b8 | 2023-06-22 20:29:41 +0200 | [diff] [blame] | 61 | def get_src_files(since: Optional[str]) -> List[str]: |
David Horstmann | fa928f1 | 2022-11-01 15:46:16 +0000 | [diff] [blame] | 62 | """ |
Gilles Peskine | 22eb82c | 2023-06-22 19:45:01 +0200 | [diff] [blame] | 63 | Use git to get a list of the source files. |
| 64 | |
Gilles Peskine | 43838b8 | 2023-06-22 20:29:41 +0200 | [diff] [blame] | 65 | The optional argument since is a commit, indicating to only list files |
| 66 | that have changed since that commit. Without this argument, list all |
| 67 | files known to git. |
| 68 | |
Gilles Peskine | 22eb82c | 2023-06-22 19:45:01 +0200 | [diff] [blame] | 69 | Only C files are included, and certain files (generated, or 3rdparty) |
| 70 | are excluded. |
David Horstmann | fa928f1 | 2022-11-01 15:46:16 +0000 | [diff] [blame] | 71 | """ |
Gilles Peskine | 163ec40 | 2023-06-25 22:18:40 +0200 | [diff] [blame] | 72 | file_patterns = ["*.[hc]", |
| 73 | "tests/suites/*.function", |
| 74 | "scripts/data_files/*.fmt"] |
| 75 | output = subprocess.check_output(["git", "ls-files"] + file_patterns, |
| 76 | universal_newlines=True) |
Gilles Peskine | 22eb82c | 2023-06-22 19:45:01 +0200 | [diff] [blame] | 77 | src_files = output.split() |
David Horstmann | 8eaeb38 | 2024-06-06 15:25:10 +0100 | [diff] [blame] | 78 | |
| 79 | # When this script is called from a git hook, some environment variables |
| 80 | # are set by default which force all git commands to use the main repository |
| 81 | # (i.e. prevent us from performing commands on the framework repo). |
| 82 | # Create an environment without these variables for running commands on the |
| 83 | # framework repo. |
| 84 | framework_env = os.environ.copy() |
| 85 | # Get a list of environment vars that git sets |
| 86 | git_env_vars = subprocess.check_output(["git", "rev-parse", "--local-env-vars"], |
| 87 | universal_newlines=True) |
David Horstmann | 8eaeb38 | 2024-06-06 15:25:10 +0100 | [diff] [blame] | 88 | # Remove the vars from the environment |
David Horstmann | 93ee016 | 2024-06-06 16:16:31 +0100 | [diff] [blame] | 89 | for var in git_env_vars.split(): |
David Horstmann | 8eaeb38 | 2024-06-06 15:25:10 +0100 | [diff] [blame] | 90 | framework_env.pop(var, None) |
| 91 | |
Ronald Cron | bc93d0e | 2024-04-25 15:46:01 +0200 | [diff] [blame] | 92 | output = subprocess.check_output(["git", "-C", "framework", "ls-files"] |
David Horstmann | 8eaeb38 | 2024-06-06 15:25:10 +0100 | [diff] [blame] | 93 | + file_patterns, |
| 94 | universal_newlines=True, |
| 95 | env=framework_env) |
Ronald Cron | bc93d0e | 2024-04-25 15:46:01 +0200 | [diff] [blame] | 96 | framework_src_files = output.split() |
| 97 | |
Gilles Peskine | 163ec40 | 2023-06-25 22:18:40 +0200 | [diff] [blame] | 98 | if since: |
Ronald Cron | bc93d0e | 2024-04-25 15:46:01 +0200 | [diff] [blame] | 99 | # get all files changed in commits since the starting point in ... |
| 100 | # ... the main repository |
| 101 | cmd = ["git", "log", since + "..HEAD", "--ignore-submodules", |
| 102 | "--name-only", "--pretty=", "--"] + src_files |
Dave Rodgman | 05b60f4 | 2023-07-27 14:22:34 +0100 | [diff] [blame] | 103 | output = subprocess.check_output(cmd, universal_newlines=True) |
| 104 | committed_changed_files = output.split() |
Harry Ramsey | 5098d04 | 2024-09-18 14:03:26 +0100 | [diff] [blame^] | 105 | |
Ronald Cron | bc93d0e | 2024-04-25 15:46:01 +0200 | [diff] [blame] | 106 | # ... the framework submodule |
Harry Ramsey | 5098d04 | 2024-09-18 14:03:26 +0100 | [diff] [blame^] | 107 | framework_since = get_submodule_hash(since, "framework") |
| 108 | cmd = ["git", "-C", "framework", "log", framework_since + "..HEAD", |
Ronald Cron | bc93d0e | 2024-04-25 15:46:01 +0200 | [diff] [blame] | 109 | "--name-only", "--pretty=", "--"] + framework_src_files |
David Horstmann | 8eaeb38 | 2024-06-06 15:25:10 +0100 | [diff] [blame] | 110 | output = subprocess.check_output(cmd, universal_newlines=True, |
| 111 | env=framework_env) |
Ronald Cron | bc93d0e | 2024-04-25 15:46:01 +0200 | [diff] [blame] | 112 | committed_changed_files += ["framework/" + s for s in output.split()] |
| 113 | |
| 114 | # and also get all files with uncommitted changes in ... |
| 115 | # ... the main repository |
Dave Rodgman | fccc5f8 | 2023-07-27 20:00:41 +0100 | [diff] [blame] | 116 | cmd = ["git", "diff", "--name-only", "--"] + src_files |
Dave Rodgman | 05b60f4 | 2023-07-27 14:22:34 +0100 | [diff] [blame] | 117 | output = subprocess.check_output(cmd, universal_newlines=True) |
| 118 | uncommitted_changed_files = output.split() |
Ronald Cron | bc93d0e | 2024-04-25 15:46:01 +0200 | [diff] [blame] | 119 | # ... the framework submodule |
| 120 | cmd = ["git", "-C", "framework", "diff", "--name-only", "--"] + \ |
| 121 | framework_src_files |
David Horstmann | 8eaeb38 | 2024-06-06 15:25:10 +0100 | [diff] [blame] | 122 | output = subprocess.check_output(cmd, universal_newlines=True, |
| 123 | env=framework_env) |
Ronald Cron | bc93d0e | 2024-04-25 15:46:01 +0200 | [diff] [blame] | 124 | uncommitted_changed_files += ["framework/" + s for s in output.split()] |
| 125 | |
| 126 | src_files = committed_changed_files + uncommitted_changed_files |
| 127 | else: |
| 128 | src_files += ["framework/" + s for s in framework_src_files] |
David Horstmann | fa928f1 | 2022-11-01 15:46:16 +0000 | [diff] [blame] | 129 | |
Gilles Peskine | 22eb82c | 2023-06-22 19:45:01 +0200 | [diff] [blame] | 130 | generated_files = list_generated_files() |
| 131 | # Don't correct style for third-party files (and, for simplicity, |
| 132 | # companion files in the same subtree), or for automatically |
| 133 | # generated files (we're correcting the templates instead). |
| 134 | src_files = [filename for filename in src_files |
| 135 | if not (filename.startswith("3rdparty/") or |
Dave Rodgman | 2a9eb22 | 2024-03-18 11:15:06 +0000 | [diff] [blame] | 136 | filename in generated_files or |
| 137 | is_file_autogenerated(filename))] |
Gilles Peskine | 22eb82c | 2023-06-22 19:45:01 +0200 | [diff] [blame] | 138 | return src_files |
David Horstmann | fa928f1 | 2022-11-01 15:46:16 +0000 | [diff] [blame] | 139 | |
Harry Ramsey | 5098d04 | 2024-09-18 14:03:26 +0100 | [diff] [blame^] | 140 | def get_submodule_hash(commit: str, submodule: str) -> str: |
| 141 | """Get the commit hash of a submodule at a given commit in the Git repository.""" |
| 142 | cmd = ["git", "ls-tree", commit, submodule] |
| 143 | output = subprocess.check_output(cmd, universal_newlines=True) |
| 144 | return output.split()[2] |
| 145 | |
David Horstmann | fa928f1 | 2022-11-01 15:46:16 +0000 | [diff] [blame] | 146 | def get_uncrustify_version() -> str: |
| 147 | """ |
| 148 | Get the version string from Uncrustify |
| 149 | """ |
David Horstmann | 04bdbe3 | 2023-01-25 11:39:04 +0000 | [diff] [blame] | 150 | result = subprocess.run([UNCRUSTIFY_EXE, "--version"], |
| 151 | stdout=subprocess.PIPE, stderr=subprocess.PIPE, |
| 152 | check=False) |
David Horstmann | fa928f1 | 2022-11-01 15:46:16 +0000 | [diff] [blame] | 153 | if result.returncode != 0: |
David Horstmann | ca13c4f | 2022-12-08 14:33:52 +0000 | [diff] [blame] | 154 | print_err("Could not get Uncrustify version:", str(result.stderr, "utf-8")) |
David Horstmann | fa928f1 | 2022-11-01 15:46:16 +0000 | [diff] [blame] | 155 | return "" |
| 156 | else: |
| 157 | return str(result.stdout, "utf-8") |
| 158 | |
| 159 | def check_style_is_correct(src_file_list: List[str]) -> bool: |
| 160 | """ |
David Horstmann | 9711f4e | 2022-12-08 14:36:10 +0000 | [diff] [blame] | 161 | Check the code style and output a diff for each file whose style is |
David Horstmann | fa928f1 | 2022-11-01 15:46:16 +0000 | [diff] [blame] | 162 | incorrect. |
| 163 | """ |
| 164 | style_correct = True |
| 165 | for src_file in src_file_list: |
| 166 | uncrustify_cmd = [UNCRUSTIFY_EXE] + UNCRUSTIFY_ARGS + [src_file] |
David Horstmann | 04bdbe3 | 2023-01-25 11:39:04 +0000 | [diff] [blame] | 167 | result = subprocess.run(uncrustify_cmd, stdout=subprocess.PIPE, |
| 168 | stderr=subprocess.PIPE, check=False) |
David Horstmann | c571c5b | 2023-01-04 18:33:25 +0000 | [diff] [blame] | 169 | if result.returncode != 0: |
David Horstmann | 04bdbe3 | 2023-01-25 11:39:04 +0000 | [diff] [blame] | 170 | print_err("Uncrustify returned " + str(result.returncode) + |
| 171 | " correcting file " + src_file) |
David Horstmann | c571c5b | 2023-01-04 18:33:25 +0000 | [diff] [blame] | 172 | return False |
David Horstmann | fa928f1 | 2022-11-01 15:46:16 +0000 | [diff] [blame] | 173 | |
| 174 | # Uncrustify makes changes to the code and places the result in a new |
| 175 | # file with the extension ".uncrustify". To get the changes (if any) |
| 176 | # simply diff the 2 files. |
David Horstmann | 0ebc12e | 2022-12-08 15:04:20 +0000 | [diff] [blame] | 177 | diff_cmd = ["diff", "-u", src_file, src_file + ".uncrustify"] |
David Horstmann | ce42cc2 | 2023-01-24 18:08:49 +0000 | [diff] [blame] | 178 | cp = subprocess.run(diff_cmd, check=False) |
| 179 | |
| 180 | if cp.returncode == 1: |
David Horstmann | 6b3ce30 | 2023-01-24 18:36:41 +0000 | [diff] [blame] | 181 | print(src_file + " changed - code style is incorrect.") |
David Horstmann | fa928f1 | 2022-11-01 15:46:16 +0000 | [diff] [blame] | 182 | style_correct = False |
David Horstmann | ce42cc2 | 2023-01-24 18:08:49 +0000 | [diff] [blame] | 183 | elif cp.returncode != 0: |
| 184 | raise subprocess.CalledProcessError(cp.returncode, cp.args, |
| 185 | cp.stdout, cp.stderr) |
David Horstmann | fa928f1 | 2022-11-01 15:46:16 +0000 | [diff] [blame] | 186 | |
| 187 | # Tidy up artifact |
David Horstmann | 0ebc12e | 2022-12-08 15:04:20 +0000 | [diff] [blame] | 188 | os.remove(src_file + ".uncrustify") |
David Horstmann | fa928f1 | 2022-11-01 15:46:16 +0000 | [diff] [blame] | 189 | |
| 190 | return style_correct |
| 191 | |
David Horstmann | 8d1d6ed | 2023-01-05 09:59:35 +0000 | [diff] [blame] | 192 | def fix_style_single_pass(src_file_list: List[str]) -> bool: |
David Horstmann | fa928f1 | 2022-11-01 15:46:16 +0000 | [diff] [blame] | 193 | """ |
| 194 | Run Uncrustify once over the source files. |
| 195 | """ |
| 196 | code_change_args = UNCRUSTIFY_ARGS + ["--no-backup"] |
| 197 | for src_file in src_file_list: |
| 198 | uncrustify_cmd = [UNCRUSTIFY_EXE] + code_change_args + [src_file] |
David Horstmann | 6b3ce30 | 2023-01-24 18:36:41 +0000 | [diff] [blame] | 199 | result = subprocess.run(uncrustify_cmd, check=False) |
David Horstmann | c571c5b | 2023-01-04 18:33:25 +0000 | [diff] [blame] | 200 | if result.returncode != 0: |
David Horstmann | 04bdbe3 | 2023-01-25 11:39:04 +0000 | [diff] [blame] | 201 | print_err("Uncrustify with file returned: " + |
| 202 | str(result.returncode) + " correcting file " + |
| 203 | src_file) |
David Horstmann | c571c5b | 2023-01-04 18:33:25 +0000 | [diff] [blame] | 204 | return False |
David Horstmann | 8d1d6ed | 2023-01-05 09:59:35 +0000 | [diff] [blame] | 205 | return True |
David Horstmann | fa928f1 | 2022-11-01 15:46:16 +0000 | [diff] [blame] | 206 | |
| 207 | def fix_style(src_file_list: List[str]) -> int: |
| 208 | """ |
| 209 | Fix the code style. This takes 2 passes of Uncrustify. |
| 210 | """ |
David Horstmann | 78d566b | 2023-01-05 10:02:09 +0000 | [diff] [blame] | 211 | if not fix_style_single_pass(src_file_list): |
David Horstmann | c571c5b | 2023-01-04 18:33:25 +0000 | [diff] [blame] | 212 | return 1 |
David Horstmann | 78d566b | 2023-01-05 10:02:09 +0000 | [diff] [blame] | 213 | if not fix_style_single_pass(src_file_list): |
David Horstmann | c571c5b | 2023-01-04 18:33:25 +0000 | [diff] [blame] | 214 | return 1 |
David Horstmann | fa928f1 | 2022-11-01 15:46:16 +0000 | [diff] [blame] | 215 | |
| 216 | # Guard against future changes that cause the codebase to require |
| 217 | # more passes. |
| 218 | if not check_style_is_correct(src_file_list): |
David Horstmann | 28d2157 | 2023-01-16 18:32:56 +0000 | [diff] [blame] | 219 | print_err("Code style still incorrect after second run of Uncrustify.") |
David Horstmann | fa928f1 | 2022-11-01 15:46:16 +0000 | [diff] [blame] | 220 | return 1 |
| 221 | else: |
| 222 | return 0 |
| 223 | |
| 224 | def main() -> int: |
| 225 | """ |
| 226 | Main with command line arguments. |
| 227 | """ |
David Horstmann | 2cf779c | 2022-12-08 14:44:36 +0000 | [diff] [blame] | 228 | uncrustify_version = get_uncrustify_version().strip() |
| 229 | if UNCRUSTIFY_SUPPORTED_VERSION not in uncrustify_version: |
Gilles Peskine | 9d34cf3 | 2022-12-23 18:15:19 +0100 | [diff] [blame] | 230 | print("Warning: Using unsupported Uncrustify version '" + |
David Horstmann | 6b3ce30 | 2023-01-24 18:36:41 +0000 | [diff] [blame] | 231 | uncrustify_version + "'") |
Gilles Peskine | 9d34cf3 | 2022-12-23 18:15:19 +0100 | [diff] [blame] | 232 | print("Note: The only supported version is " + |
David Horstmann | 6b3ce30 | 2023-01-24 18:36:41 +0000 | [diff] [blame] | 233 | UNCRUSTIFY_SUPPORTED_VERSION) |
David Horstmann | fa928f1 | 2022-11-01 15:46:16 +0000 | [diff] [blame] | 234 | |
| 235 | parser = argparse.ArgumentParser() |
Gilles Peskine | 59803db | 2022-12-22 16:34:01 +0100 | [diff] [blame] | 236 | parser.add_argument('-f', '--fix', action='store_true', |
Gilles Peskine | 9d34cf3 | 2022-12-23 18:15:19 +0100 | [diff] [blame] | 237 | help=('modify source files to fix the code style ' |
| 238 | '(default: print diff, do not modify files)')) |
Dave Rodgman | eaf2761 | 2023-07-27 14:22:55 +0100 | [diff] [blame] | 239 | parser.add_argument('-s', '--since', metavar='COMMIT', const='development', nargs='?', |
Gilles Peskine | 43838b8 | 2023-06-22 20:29:41 +0200 | [diff] [blame] | 240 | help=('only check files modified since the specified commit' |
Dave Rodgman | eaf2761 | 2023-07-27 14:22:55 +0100 | [diff] [blame] | 241 | ' (e.g. --since=HEAD~3 or --since=development). If no' |
| 242 | ' commit is specified, default to development.')) |
Pengyu Lv | c36743f | 2023-02-15 10:20:40 +0800 | [diff] [blame] | 243 | # --subset is almost useless: it only matters if there are no files |
| 244 | # ('code_style.py' without arguments checks all files known to Git, |
| 245 | # 'code_style.py --subset' does nothing). In particular, |
| 246 | # 'code_style.py --fix --subset ...' is intended as a stable ("porcelain") |
| 247 | # way to restyle a possibly empty set of files. |
Pengyu Lv | 8c6325c | 2023-02-06 14:29:02 +0800 | [diff] [blame] | 248 | parser.add_argument('--subset', action='store_true', |
Pengyu Lv | c36743f | 2023-02-15 10:20:40 +0800 | [diff] [blame] | 249 | help='only check the specified files (default with non-option arguments)') |
Gilles Peskine | 59803db | 2022-12-22 16:34:01 +0100 | [diff] [blame] | 250 | parser.add_argument('operands', nargs='*', metavar='FILE', |
Pengyu Lv | c36743f | 2023-02-15 10:20:40 +0800 | [diff] [blame] | 251 | help='files to check (files MUST be known to git, if none: check all)') |
David Horstmann | fa928f1 | 2022-11-01 15:46:16 +0000 | [diff] [blame] | 252 | |
| 253 | args = parser.parse_args() |
| 254 | |
Gilles Peskine | 43838b8 | 2023-06-22 20:29:41 +0200 | [diff] [blame] | 255 | covered = frozenset(get_src_files(args.since)) |
Pengyu Lv | c36743f | 2023-02-15 10:20:40 +0800 | [diff] [blame] | 256 | # We only check files that are known to git |
| 257 | if args.subset or args.operands: |
Pengyu Lv | e19b51b | 2023-02-14 10:29:53 +0800 | [diff] [blame] | 258 | src_files = [f for f in args.operands if f in covered] |
| 259 | skip_src_files = [f for f in args.operands if f not in covered] |
Pengyu Lv | acbeb7f | 2023-02-06 14:27:30 +0800 | [diff] [blame] | 260 | if skip_src_files: |
| 261 | print_skip(skip_src_files) |
Pengyu Lv | c36743f | 2023-02-15 10:20:40 +0800 | [diff] [blame] | 262 | else: |
Pengyu Lv | 10f4144 | 2023-02-15 16:58:09 +0800 | [diff] [blame] | 263 | src_files = list(covered) |
Gilles Peskine | 59803db | 2022-12-22 16:34:01 +0100 | [diff] [blame] | 264 | |
David Horstmann | fa928f1 | 2022-11-01 15:46:16 +0000 | [diff] [blame] | 265 | if args.fix: |
| 266 | # Fix mode |
| 267 | return fix_style(src_files) |
| 268 | else: |
| 269 | # Check mode |
| 270 | if check_style_is_correct(src_files): |
David Horstmann | 6b3ce30 | 2023-01-24 18:36:41 +0000 | [diff] [blame] | 271 | print("Checked {} files, style ok.".format(len(src_files))) |
David Horstmann | fa928f1 | 2022-11-01 15:46:16 +0000 | [diff] [blame] | 272 | return 0 |
| 273 | else: |
| 274 | return 1 |
| 275 | |
| 276 | if __name__ == '__main__': |
| 277 | sys.exit(main()) |