-
Notifications
You must be signed in to change notification settings - Fork 23
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Move some scripts to framework submodule #5
Closed
Closed
Changes from all commits
Commits
Show all changes
580 commits
Select commit
Hold shift + click to select a range
1a1deb8
Support restyling only the specified files
gilles-peskine-arm 6071e90
Merge pull request #6747 from gilles-peskine-arm/bignum-mod-random
mpg bbb0a7f
Merge pull request #6776 from gabor-mezei-arm/6222_bignum_mod_mul
mpg c46bb0a
Documentation improvements
gilles-peskine-arm 5059797
Check Uncrustify returncode in code_style.py
davidhorstmann-arm 3b1c55d
Fix incorrect typing of function in code_style.py
davidhorstmann-arm 50dfaca
Fix pylint warnings about comparison to True
davidhorstmann-arm 293404f
Merge pull request #6876 from davidhorstmann-arm/disable-code-style-f…
gilles-peskine-arm 8dc85d9
Fix example command
gilles-peskine-arm 990bb78
Add test generation support for the ecp module
gabor-mezei-arm 12d70a9
Add generated test for ecp quasi-reduction
gabor-mezei-arm 9b226cb
Fix pylint issues
gabor-mezei-arm df4464a
Fix lint issues
gabor-mezei-arm f048545
Refactoring: new method Algorithm.is_valid_for_operation
gilles-peskine-arm 3325957
A key agreement cannot be chained with PSA_ALG_TLS12_ECJPAKE_TO_PMS
gilles-peskine-arm 617b051
Merge pull request #6834 from gilles-peskine-arm/code-style-files
gilles-peskine-arm bf903a0
Move the quasi reduction fixing function to bignum_mod_raw
gabor-mezei-arm c4fe40d
Remove provisional notice on code style script
davidhorstmann-arm edb88c4
Document that the script must be run from the root
davidhorstmann-arm 20694ab
Change print to print_err for an error message
davidhorstmann-arm b9c3833
Remove overly verbose output on success
davidhorstmann-arm 21157c0
Fix pylint issues
gabor-mezei-arm 7dce673
Add basic output on success
davidhorstmann-arm 42c4850
Use reproductable random numbers
gabor-mezei-arm 2abb538
Output diff without capturing it
davidhorstmann-arm 3a0d806
Don't wrap stdout and stderr in UTF-8 wrapper
davidhorstmann-arm 2813823
Give proper Dict type hints in crypto_knowledge.py
davidhorstmann-arm f6866ce
Remove unnecessary '\' linebreak characters
davidhorstmann-arm 613468f
Add dependency for generated test cases
gabor-mezei-arm fa86a19
Merge pull request #6802 from gilles-peskine-arm/test_suite_psa_crypt…
mpg 1d1957a
Revert "Add dependency for generated test cases"
gabor-mezei-arm da4b0c4
Shorten the prefix of the test case belongs to the fix quasi-reductio…
gabor-mezei-arm 65386fd
c_build_helper.py: Move compile to helper
davidhorstmann-arm c3642e6
Make c_build_helper module respect HOSTCC
davidhorstmann-arm 2995eb9
Add docstring for new compile function.
davidhorstmann-arm 6d6209f
Switch to the new code style
gilles-peskine-arm 914ee88
Merge pull request #6941 from gabor-mezei-arm/6375_quasi-reduction_fu…
gilles-peskine-arm fc04802
Add test generation support for the ecp module
gabor-mezei-arm e5c94b8
Add test generation for ecp_mod_p192_raw
gabor-mezei-arm 4377cb5
Fix pylint issues
gabor-mezei-arm ddc3fbc
Merge pull request #6964 from davidhorstmann-arm/code-style-improvements
gilles-peskine-arm 4b83c29
Merge pull request #6975 from davidhorstmann-arm/c-build-helper-impro…
gilles-peskine-arm 8da7cd3
code_style.py: Apply exclusions to the file list
lpy4105 dc41dda
code_style.py: Add helpers to print warning and skipped files
lpy4105 2fc0c25
print skipped file names to stdout
lpy4105 39d3cb5
adjust help message
lpy4105 d2b2508
Merge pull request #6816 from nick-child-ibm/pkcs7_coverage
daverodgman 45f9a2f
Add more test cases
gabor-mezei-arm 2923ed0
Improve readability
lpy4105 8508172
Only check files known to git
lpy4105 83a19cd
Fix CI failure
lpy4105 b20d2c0
Merge pull request #6971 from gabor-mezei-arm/6026_Secp192r1_fast_red…
gilles-peskine-arm 1fc3529
Add test generation for ecp_mod_p521_raw
gabor-mezei-arm 6b348de
Fix pylint issues
gabor-mezei-arm 0f22852
Fix 32-bit issues
gabor-mezei-arm d388080
Add corner case to mod_p521 tests
yanesca 44fbcaf
Restrict input parameter size for ecp_mod_p521_raw
gabor-mezei-arm 8959be7
Revert the addition of hex digit calculator function
gabor-mezei-arm f43a2c9
Fix tests for 32bit
gabor-mezei-arm 77c489f
Merge pull request #7045 from lpy4105/issue/6947/apply-exclusions-in-…
gilles-peskine-arm 217efa0
Use a common function to calculate the number of hex digits
gabor-mezei-arm 7011783
Add test generation for ecp_mod_p224_raw
gabor-mezei-arm 35626cc
Add more test cases for P224 testing
gabor-mezei-arm c494135
Use lower case hex number
gabor-mezei-arm f1cbbec
Remove unnecessary function override
gabor-mezei-arm 1c1eb3c
Code style: have two empty lines before and after class definitions
gabor-mezei-arm e0a84d7
Correct the maximum canonical value in tests
gabor-mezei-arm c9709b3
The is_valid() function is needed to not filter out test cases
gabor-mezei-arm 340f92f
Add test generation for ecp_mod_p256_raw
gabor-mezei-arm fa85e66
Add and fix comments
gabor-mezei-arm a970c38
Fix maximum cannonical value
gabor-mezei-arm 6dc6947
ecp test generator: Added EcpPp384R1Raw().
minosgalanakis 636abec
ecp_curves: Minor rework for p384
minosgalanakis 75bdc54
EcpP384R1Raw: Added test case for 2nd round of carry reduction.
minosgalanakis ce6c440
Add test cases for P192 fast reduction testing
gabor-mezei-arm 59e748a
Add test cases for P224 fast reduction testing
gabor-mezei-arm bf59479
Add test cases for P521 fast reduction testing
gabor-mezei-arm 83abbc1
Typo: reformat numbers
gabor-mezei-arm ca9b17c
Add test cases for P384 fast reduction testing
gabor-mezei-arm 5f5421c
Add test cases for P256 fast reduction testing
gabor-mezei-arm 3211697
Typo: reorder testing classes
gabor-mezei-arm 9be2525
Fix comments
gabor-mezei-arm dc86aa7
Fix 0 limb size for value 0
gabor-mezei-arm 3f37a25
Add generated test for core_mul
gabor-mezei-arm 8645c27
Multplication is simmetric so only generate unique combinations
gabor-mezei-arm f3c99a9
bignum: Removed merge scaffolding.
minosgalanakis 32f3bcc
cert_audit: Initial script for auditing expiry date
lpy4105 109399c
cert_audit: Support audit on test suite data files
lpy4105 b427f27
Merge pull request #7324 from minosgalanakis/bignum/remove-scaffolding
yanesca ef3cd67
Merge pull request #7351 from gabor-mezei-arm/7109_ecp_fast_reduction…
yanesca e5624fc
test_suite_ecp: Introduced `ecp_mod_p_generic_raw`
minosgalanakis 47f7017
ecp.py: Set test-dependencies as attributes.
minosgalanakis 8e8cc2b
cert_audit: Parse more information from test suite data file
lpy4105 3b7a941
cert_audit: Introduce not-[before|after] option
lpy4105 2a4abc4
cert_audit: Fill validity dates in AuditData constructor
lpy4105 a678c0a
cert_audit: Disable pylint error for importing cryptography
lpy4105 adda9da
cert_audit: Make FILE as positional argument
lpy4105 ac593c7
cert_audit: Output line/argument number for *.data files
lpy4105 2184cf2
Add generated tests for ecp_mod_p192k1
gabor-mezei-arm 1331362
Add dependency for P192K1 tests
gabor-mezei-arm 7b02aa3
Fix test case dependency
gabor-mezei-arm 17d14fd
cert_audit: Improve documentation
lpy4105 6f97d92
cert_audit: Code refinement
lpy4105 7ff6f7c
ecp_curves: Added unit-tests for `secp224k1`
minosgalanakis 9dfb26f
New implementation for generate_test_code.FileWrapper
lpy4105 228d863
cert_audit: Reuse generate_test_code.FileWrapper
lpy4105 8f21dd9
cert_audit: Enable logging module
lpy4105 fb508f0
cert_audit: Add data-files and suite-data-files options
lpy4105 f948226
cert_audit: Improve the method to find tests folder
lpy4105 372e7a0
Merge pull request #7425 from minosgalanakis/ecp/7257_ecp_mod_p224k1_…
paul-elliott-arm 64a5fb5
cert_audit: Add simple parser of suite data file
lpy4105 25d1dae
cert_audit: Clarify the abstraction of Auditor
lpy4105 831471a
cert_audit: Check the version of cryptography
lpy4105 17b7c70
cert_audit: Reword the options and their descriptions
lpy4105 f6a6fe8
ecp_curves: Added unit-tests for `secp256k1`
minosgalanakis afe5ca7
bignum_core.py: Add "BignumCoreShiftL()"
minosgalanakis f33ba7b
Add line number to a few error messages
gilles-peskine-arm e74801e
Factor get_function_info out of gen_from_test_data
gilles-peskine-arm 2d07e7f
Simplify parsing of integers in .datax files
gilles-peskine-arm 8f35c81
Support different types in the parameter store
gilles-peskine-arm 4bd2ad9
parse_function_arguments: make local_vars a list
gilles-peskine-arm 02fc566
parse_function_arguments: extract per-argument function
gilles-peskine-arm 84fd799
Support (void) as an argument list of a test function
gilles-peskine-arm 88d56de
parse_function_arguments: stricter type parsing
gilles-peskine-arm 0091624
Support larger integer test arguments: C part
gilles-peskine-arm 99be173
Allow more signed integer types in test function arguments
gilles-peskine-arm 15018cf
Test the line number returned by parse_test_data
gilles-peskine-arm d8476e8
typo
gilles-peskine-arm ad5629d
Adjust code style for pointer types and casts
gilles-peskine-arm b70de43
Add Curve 448 tests
paul-elliott-arm 379f671
Correct max canonical multiplication result
paul-elliott-arm 6105259
Remove unrequired limb size calculation
paul-elliott-arm 6fa83f5
Merge pull request #6716 from gilles-peskine-arm/test-argument-types-…
gilles-peskine-arm 17bbca8
Merge pull request #7490 from paul-elliott-arm/test_ecp_mod_p448
paul-elliott-arm ebef055
Fix input parameter alignment in P256K1 test cases
gabor-mezei-arm ee7aedb
Merge pull request #7399 from lpy4105/issue/7014/certificate-audit-sc…
bensze01 26f0239
cert_audit: Support parsing file with multiple PEMs
lpy4105 12157ba
cert_audit: Merge audit_data for identical X.509 objects
lpy4105 318d696
cert_audit: Sort the outputs by not_valid_after date
lpy4105 fbe2939
cert_audit: Fix bug in check_cryptography_version
lpy4105 2f52f05
cert_audit: Calculate identifier for X.509 objects
lpy4105 f2bb1eb
cert_audit: Output format improvement
lpy4105 beac0bb
cert_audit: Use dictionary to store parsed AuditData
lpy4105 0217808
cert_audit: Remove merge_auditdata
lpy4105 876d933
cert_audit: Fix DER files missed from parsing
lpy4105 96fb3a7
Merge pull request #7482 from gabor-mezei-arm/6029_use_core_api_in_ec…
paul-elliott-arm 6a1358e
bignum_common.py: Addressed minor typos
minosgalanakis 872a5fa
Add test cases to test overflow in the Kobltz reduction
gabor-mezei-arm ef01247
bignum_core.py: Simplified result calculation for `BignumCoreShiftL`
minosgalanakis cf8826c
Add `_raw` function to P192K1
gabor-mezei-arm 9c82445
Add `_raw` function to P224K1
gabor-mezei-arm 1e9020a
Add `_raw` function to P256K1
gabor-mezei-arm 31b3062
Merge pull request #7489 from minosgalanakis/ecp/7246_xtrack_core_shi…
paul-elliott-arm 92e7937
Merge pull request #7565 from gabor-mezei-arm/7263_split_out_Koblitz_…
paul-elliott-arm b93e2ee
ecp.py: Added tests for `mbedtls_ecp_mod_p255_raw`
minosgalanakis 9fd6d1e
ecp.py: Fixed types for `arguments()` overrides.
minosgalanakis 7bb8019
ecp_curves: Minor refactoring of `mbedtls_ecp_mod_p255_raw()`
minosgalanakis 725748a
Merge pull request #7512 from lpy4105/issue/7014/cert_audit-improvement
gilles-peskine-arm 7073ae2
Merge pull request #7591 from minosgalanakis/ecp/6028_xtract_fast_red…
paul-elliott-arm ba37450
Move corner test case into python framework
paul-elliott-arm b7cbaad
Merge pull request #7637 from paul-elliott-arm/fixed_ecp_mod_p448
paul-elliott-arm de1a028
Split out mbedtls_ecp_mod_p448_raw()
paul-elliott-arm e46cde9
test_suite_ecp: Added `MBEDTLS_ECP_NIST_OPTIM` define guards.
minosgalanakis 61af299
Clean up subprocess invocation in get_src_files
gilles-peskine-arm 35de652
Add --since option to check files modified since a given commit
gilles-peskine-arm 31299ca
Handle deleted files correctly
gilles-peskine-arm c69a549
bignum_common.py: Added `bits_to_limbs` method.
minosgalanakis 7fe083e
ecp.py: Extended EcpP224K1Raw tests for 32/64 bit architectures.
minosgalanakis 03b2524
Merge pull request #7822 from gilles-peskine-arm/code-style-since
daverodgman f877ce6
code_size_compare: add logging module and tweak prompt message
bd4f3cc
logging_util: rename argument
537fd3e
Enable DH in generate_psa_tests.py
mpg aa454f6
Shorten DH_FAMILY just like ECC_FAMILY
mpg b8f8019
Fix KeyType.can_do() for DH+FFDH
mpg 56bab4e
Fix warnings from clang-16
gowthamsk-arm 12cd806
Make code_style.py -s more precise
daverodgman 7853f4e
Make code_style.py -s default to -s=development
daverodgman 34b89f9
pylint tidy-up
daverodgman bb2f4d6
whitespace fix
dave-rodgman 86fd07c
Update default variable values for compilers
gowthamsk-arm 08984c0
Add default test cases for add/subtract in bignum
f00f5e4
Use ADD_SUB_DEFAULT as test input for bignum tests
f43c186
Rename ADD_SUB_DEFAULT to ADD_SUB_DATA
abd6cc9
Merge pull request #7968 from gowthamsk-arm/use_earliest_latest_compi…
bensze01 24d635d
Remove trailing whitespace
ecd6281
Merge pull request #8018 from AgathiyanB/add-overflow-test-inputs-bignum
tom-cosgrove-arm f335772
logging_util: support to tweak loglevel directed to stderr/stdout
573d74f
Merge pull request #7937 from yanrayw/code_size_compare_improvement
bensze01 7a19bbc
Move PSA information and dependency automation into their own module
gilles-peskine-arm 496313d
New test suite for the low-level hash interface
gilles-peskine-arm 6ef458a
Fix type annotation
gilles-peskine-arm 567a828
Modify build_tree.py for the PSA Crypto repo
davidhorstmann-arm 7f35b6b
Support psa-crypto repo in psa_storage.py
davidhorstmann-arm 81e8e30
Improve directory coverage in PSA repo detection
davidhorstmann-arm 2abd26d
Merge pull request #1050 from Mbed-TLS/update-restricted-2023-08-30
gilles-peskine-arm 7021408
Merge remote-tracking branch 'upstream-public/development' into devel…
gilles-peskine-arm 7759610
Merge pull request #1090 from Mbed-TLS/mbedtls-3.5.0rc0-pr
minosgalanakis 4ab66b8
Correct styling of Mbed TLS in documentation
tom-daubney-arm 7e479ed
Adapt to new PSA Crypto repo name
ronald-cron-arm 5c899a8
Merge pull request #8327 from ronald-cron-arm/adapt-psa-crypto-repo-name
ronald-cron-arm 2515cfa
add script for server9_bad_saltlen
yuhaoth 432e00e
fix wrong typo and indent issue
yuhaoth 20c91d5
improve document
yuhaoth 07bc4a8
move script to `tests/scripts`
yuhaoth 09146d7
update headers
daverodgman b232974
psa_information.py: generate dep for AES/ARIA/CAMELLIA ECB test case
3652581
Header updates
daverodgman b56cc53
Revert back to v3.5.0
daverodgman 6225c84
Merge remote-tracking branch 'origin/development' into mbedtls-3.5.1-pr
daverodgman e803233
psa_information: compile a regex instead of using string directly
5fd78db
psa_information: improve code readability
0231c7d
Introduce function to return library/core directory
tom-daubney-arm a99caa8
Merge pull request #7649 from yuhaoth/pr/add-command-for-server9-bad-…
gilles-peskine-arm 89032fb
Merge pull request #1122 from gilles-peskine-arm/development-restrict…
gilles-peskine-arm 372e532
Improve implementation of crypto_core_directory
tom-daubney-arm d990342
Rename guess_mbedtls_root to guess_project_root
tom-daubney-arm fef67e9
Merge remote-tracking branch 'origin/development' into support_cipher…
acf4569
Introduce project_crypto_name in build_tree.py
tom-daubney-arm 415486a
Use os.path.join in crypto_core_directory
tom-daubney-arm ebae927
Add documentation for new public functions
tom-daubney-arm ef87f7f
Merge remote-tracking branch 'development' into development-restricted
gilles-peskine-arm f880d03
Rename project_crypto_name
tom-daubney-arm 176d3a6
Improve documentation of crypto_core_directory
tom-daubney-arm d2eedbd
Introduce guess_mbedtls_root
tom-daubney-arm 19da414
Introduce guess_tf_psa_crypto_root
tom-daubney-arm a62109a
Remove trailing whitespace
tom-daubney-arm f8d0313
Modify crypto_core_directory to also return a relative path
tom-daubney-arm ebd3304
Use guess_mbedtls_root in Mbed-TLS-only script
tom-daubney-arm b9c445a
Merge pull request #1121 from gilles-peskine-arm/psa-buffers-test-poison
davidhorstmann-arm f487eea
Merge pull request #8523 from tom-daubney-arm/modify_check_generated_…
gilles-peskine-arm 4bcd102
Fix mixup between secp224r1 and secp224k1 in test scripts
gilles-peskine-arm cee6a06
Add test data for secp192r1
gilles-peskine-arm 903f3aa
Python module to parse function declarations from a header file
gilles-peskine-arm 3621060
C function wrapper generator
gilles-peskine-arm 3e62373
Guard the macro definition
gilles-peskine-arm c4bf74c
Add review exception warning
gilles-peskine-arm d4d4fb6
Fix parsing of C line comments
gilles-peskine-arm 00a325d
tests: add guards for DH groups
valeriosetti 214f077
Merge remote-tracking branch 'restricted/development-restricted' into…
daverodgman eca2a42
Merge pull request #1165 from daverodgman/update-development-r
daverodgman 5a46f42
Merge branch 'development' into buffer-sharing-merge
davidhorstmann-arm aeb4fb5
Check file content to see if it looks auto-generated
daverodgman d2f82ca
line length fix
daverodgman d9f386c
Minor relaxation to auto-gen regex
daverodgman 16deea8
Merge branch 'development' into 'development-restricted'
minosgalanakis f9fc138
Merge pull request #1208 from Mbed-TLS/origin/dev/minosgalanakis/deve…
minosgalanakis ef8b4be
Merge pull request #1213 from Mbed-TLS/mbedtls-3.6.0rc0-pr
minosgalanakis 56e0c15
Merge branch 'scripts-history' into dev/davidhorstmann-arm/move-scripts
davidhorstmann-arm 4765480
Replace old references to 'mbedtls_dev'
davidhorstmann-arm f1ef72a
Remove path import from audit-validity-dates.py
davidhorstmann-arm File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,230 @@ | ||
#!/usr/bin/env python3 | ||
"""Check or fix the code style by running Uncrustify. | ||
|
||
This script must be run from the root of a Git work tree containing Mbed TLS. | ||
""" | ||
# Copyright The Mbed TLS Contributors | ||
# SPDX-License-Identifier: Apache-2.0 OR GPL-2.0-or-later | ||
import argparse | ||
import os | ||
import re | ||
import subprocess | ||
import sys | ||
from typing import FrozenSet, List, Optional | ||
|
||
UNCRUSTIFY_SUPPORTED_VERSION = "0.75.1" | ||
CONFIG_FILE = ".uncrustify.cfg" | ||
UNCRUSTIFY_EXE = "uncrustify" | ||
UNCRUSTIFY_ARGS = ["-c", CONFIG_FILE] | ||
CHECK_GENERATED_FILES = "tests/scripts/check-generated-files.sh" | ||
|
||
def print_err(*args): | ||
print("Error: ", *args, file=sys.stderr) | ||
|
||
# Print the file names that will be skipped and the help message | ||
def print_skip(files_to_skip): | ||
print() | ||
print(*files_to_skip, sep=", SKIP\n", end=", SKIP\n") | ||
print("Warning: The listed files will be skipped because\n" | ||
"they are not known to git.") | ||
print() | ||
|
||
# Match FILENAME(s) in "check SCRIPT (FILENAME...)" | ||
CHECK_CALL_RE = re.compile(r"\n\s*check\s+[^\s#$&*?;|]+([^\n#$&*?;|]+)", | ||
re.ASCII) | ||
def list_generated_files() -> FrozenSet[str]: | ||
"""Return the names of generated files. | ||
|
||
We don't reformat generated files, since the result might be different | ||
from the output of the generator. Ideally the result of the generator | ||
would conform to the code style, but this would be difficult, especially | ||
with respect to the placement of line breaks in long logical lines. | ||
""" | ||
# Parse check-generated-files.sh to get an up-to-date list of | ||
# generated files. Read the file rather than calling it so that | ||
# this script only depends on Git, Python and uncrustify, and not other | ||
# tools such as sh or grep which might not be available on Windows. | ||
# This introduces a limitation: check-generated-files.sh must have | ||
# the expected format and must list the files explicitly, not through | ||
# wildcards or command substitution. | ||
content = open(CHECK_GENERATED_FILES, encoding="utf-8").read() | ||
checks = re.findall(CHECK_CALL_RE, content) | ||
return frozenset(word for s in checks for word in s.split()) | ||
|
||
# Check for comment string indicating an auto-generated file | ||
AUTOGEN_RE = re.compile(r"Warning[ :-]+This file is (now )?auto[ -]?generated", | ||
re.ASCII | re.IGNORECASE) | ||
def is_file_autogenerated(filename): | ||
content = open(filename, encoding="utf-8").read() | ||
return AUTOGEN_RE.search(content) is not None | ||
|
||
def get_src_files(since: Optional[str]) -> List[str]: | ||
""" | ||
Use git to get a list of the source files. | ||
|
||
The optional argument since is a commit, indicating to only list files | ||
that have changed since that commit. Without this argument, list all | ||
files known to git. | ||
|
||
Only C files are included, and certain files (generated, or 3rdparty) | ||
are excluded. | ||
""" | ||
file_patterns = ["*.[hc]", | ||
"tests/suites/*.function", | ||
"scripts/data_files/*.fmt"] | ||
output = subprocess.check_output(["git", "ls-files"] + file_patterns, | ||
universal_newlines=True) | ||
src_files = output.split() | ||
if since: | ||
# get all files changed in commits since the starting point | ||
cmd = ["git", "log", since + "..HEAD", "--name-only", "--pretty=", "--"] + src_files | ||
output = subprocess.check_output(cmd, universal_newlines=True) | ||
committed_changed_files = output.split() | ||
# and also get all files with uncommitted changes | ||
cmd = ["git", "diff", "--name-only", "--"] + src_files | ||
output = subprocess.check_output(cmd, universal_newlines=True) | ||
uncommitted_changed_files = output.split() | ||
src_files = list(set(committed_changed_files + uncommitted_changed_files)) | ||
|
||
generated_files = list_generated_files() | ||
# Don't correct style for third-party files (and, for simplicity, | ||
# companion files in the same subtree), or for automatically | ||
# generated files (we're correcting the templates instead). | ||
src_files = [filename for filename in src_files | ||
if not (filename.startswith("3rdparty/") or | ||
filename in generated_files or | ||
is_file_autogenerated(filename))] | ||
return src_files | ||
|
||
def get_uncrustify_version() -> str: | ||
""" | ||
Get the version string from Uncrustify | ||
""" | ||
result = subprocess.run([UNCRUSTIFY_EXE, "--version"], | ||
stdout=subprocess.PIPE, stderr=subprocess.PIPE, | ||
check=False) | ||
if result.returncode != 0: | ||
print_err("Could not get Uncrustify version:", str(result.stderr, "utf-8")) | ||
return "" | ||
else: | ||
return str(result.stdout, "utf-8") | ||
|
||
def check_style_is_correct(src_file_list: List[str]) -> bool: | ||
""" | ||
Check the code style and output a diff for each file whose style is | ||
incorrect. | ||
""" | ||
style_correct = True | ||
for src_file in src_file_list: | ||
uncrustify_cmd = [UNCRUSTIFY_EXE] + UNCRUSTIFY_ARGS + [src_file] | ||
result = subprocess.run(uncrustify_cmd, stdout=subprocess.PIPE, | ||
stderr=subprocess.PIPE, check=False) | ||
if result.returncode != 0: | ||
print_err("Uncrustify returned " + str(result.returncode) + | ||
" correcting file " + src_file) | ||
return False | ||
|
||
# Uncrustify makes changes to the code and places the result in a new | ||
# file with the extension ".uncrustify". To get the changes (if any) | ||
# simply diff the 2 files. | ||
diff_cmd = ["diff", "-u", src_file, src_file + ".uncrustify"] | ||
cp = subprocess.run(diff_cmd, check=False) | ||
|
||
if cp.returncode == 1: | ||
print(src_file + " changed - code style is incorrect.") | ||
style_correct = False | ||
elif cp.returncode != 0: | ||
raise subprocess.CalledProcessError(cp.returncode, cp.args, | ||
cp.stdout, cp.stderr) | ||
|
||
# Tidy up artifact | ||
os.remove(src_file + ".uncrustify") | ||
|
||
return style_correct | ||
|
||
def fix_style_single_pass(src_file_list: List[str]) -> bool: | ||
""" | ||
Run Uncrustify once over the source files. | ||
""" | ||
code_change_args = UNCRUSTIFY_ARGS + ["--no-backup"] | ||
for src_file in src_file_list: | ||
uncrustify_cmd = [UNCRUSTIFY_EXE] + code_change_args + [src_file] | ||
result = subprocess.run(uncrustify_cmd, check=False) | ||
if result.returncode != 0: | ||
print_err("Uncrustify with file returned: " + | ||
str(result.returncode) + " correcting file " + | ||
src_file) | ||
return False | ||
return True | ||
|
||
def fix_style(src_file_list: List[str]) -> int: | ||
""" | ||
Fix the code style. This takes 2 passes of Uncrustify. | ||
""" | ||
if not fix_style_single_pass(src_file_list): | ||
return 1 | ||
if not fix_style_single_pass(src_file_list): | ||
return 1 | ||
|
||
# Guard against future changes that cause the codebase to require | ||
# more passes. | ||
if not check_style_is_correct(src_file_list): | ||
print_err("Code style still incorrect after second run of Uncrustify.") | ||
return 1 | ||
else: | ||
return 0 | ||
|
||
def main() -> int: | ||
""" | ||
Main with command line arguments. | ||
""" | ||
uncrustify_version = get_uncrustify_version().strip() | ||
if UNCRUSTIFY_SUPPORTED_VERSION not in uncrustify_version: | ||
print("Warning: Using unsupported Uncrustify version '" + | ||
uncrustify_version + "'") | ||
print("Note: The only supported version is " + | ||
UNCRUSTIFY_SUPPORTED_VERSION) | ||
|
||
parser = argparse.ArgumentParser() | ||
parser.add_argument('-f', '--fix', action='store_true', | ||
help=('modify source files to fix the code style ' | ||
'(default: print diff, do not modify files)')) | ||
parser.add_argument('-s', '--since', metavar='COMMIT', const='development', nargs='?', | ||
help=('only check files modified since the specified commit' | ||
' (e.g. --since=HEAD~3 or --since=development). If no' | ||
' commit is specified, default to development.')) | ||
# --subset is almost useless: it only matters if there are no files | ||
# ('code_style.py' without arguments checks all files known to Git, | ||
# 'code_style.py --subset' does nothing). In particular, | ||
# 'code_style.py --fix --subset ...' is intended as a stable ("porcelain") | ||
# way to restyle a possibly empty set of files. | ||
parser.add_argument('--subset', action='store_true', | ||
help='only check the specified files (default with non-option arguments)') | ||
parser.add_argument('operands', nargs='*', metavar='FILE', | ||
help='files to check (files MUST be known to git, if none: check all)') | ||
|
||
args = parser.parse_args() | ||
|
||
covered = frozenset(get_src_files(args.since)) | ||
# We only check files that are known to git | ||
if args.subset or args.operands: | ||
src_files = [f for f in args.operands if f in covered] | ||
skip_src_files = [f for f in args.operands if f not in covered] | ||
if skip_src_files: | ||
print_skip(skip_src_files) | ||
else: | ||
src_files = list(covered) | ||
|
||
if args.fix: | ||
# Fix mode | ||
return fix_style(src_files) | ||
else: | ||
# Check mode | ||
if check_style_is_correct(src_files): | ||
print("Checked {} files, style ok.".format(len(src_files))) | ||
return 0 | ||
else: | ||
return 1 | ||
|
||
if __name__ == '__main__': | ||
sys.exit(main()) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
# This file needs to exist to make framework_dev a package. | ||
# Among other things, this allows modules in this directory to make | ||
# relative imports. |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't think
framework_dev
is right as a package name. Unless that's intended to be a sub-package of somembedtls
package? The idea with calling the directorymbedtls_dev
is that you can use it in a program that isn't specific to Mbed TLS, for example a program that puts multiple crypto libraries together and uses some code frommbedtls_dev
to obtain information about things like supported crypto mechanisms. So the name should keepmbedtls
in it.The current name is
mbedtls_dev
because it's for development of or related to Mbed TLS, as opposed tombedtls
which should be reserved for a Python package that contains wrappers around Mbed TLS's C APIs. We could keep that name here. Or maybe change it tombedtls_framework
?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I am happy with
mbedtls_dev
but I was assuming we'd want to generalise it given that it'll be used in TF-PSA-Crypto. I'll change this back tombedtls_dev
.