From b4f1ee0566b25178c965212f4b48882874815d46 Mon Sep 17 00:00:00 2001 From: Thomas Daubney Date: Mon, 13 Nov 2023 09:50:58 +0000 Subject: [PATCH 01/34] Remove superfluous leading whitespace Signed-off-by: Thomas Daubney --- scripts/lcov.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/scripts/lcov.sh b/scripts/lcov.sh index 9258ba788874..1969b3904428 100755 --- a/scripts/lcov.sh +++ b/scripts/lcov.sh @@ -33,7 +33,7 @@ set -eu # Repository detection in_mbedtls_build_dir () { test -d library - } +} # Collect stats and build a HTML report. lcov_library_report () { From c9f8386a7c09ef302bddecf5f3f95b313c1bb725 Mon Sep 17 00:00:00 2001 From: Thomas Daubney Date: Mon, 13 Nov 2023 10:03:56 +0000 Subject: [PATCH 02/34] Modify check-generated-files.sh to work in both repos Make the script work in both Mbed TLS and TF PSA Crypto. Signed-off-by: Thomas Daubney --- tests/scripts/check-generated-files.sh | 31 +++++++++++++++++--------- 1 file changed, 20 insertions(+), 11 deletions(-) diff --git a/tests/scripts/check-generated-files.sh b/tests/scripts/check-generated-files.sh index 67dedeb26556..0689147f0eef 100755 --- a/tests/scripts/check-generated-files.sh +++ b/tests/scripts/check-generated-files.sh @@ -22,8 +22,12 @@ EOF exit fi -if [ -d library -a -d include -a -d tests ]; then :; else - echo "Must be run from Mbed TLS root" >&2 +IN_MBEDTLS=0 +if [ -d library -a -d include -a -d tests ]; then + IN_MBEDTLS=1 +elif [ -d core -a -d include -a -d tests ]; then :; +else + echo "Must be run from Mbed TLS root or TF-PSA-Crypto root" >&2 exit 1 fi @@ -114,16 +118,21 @@ check() # - **/CMakeLists.txt (to (re)build them with cmake) # - scripts/make_generated_files.bat (to generate them under Windows) -check scripts/generate_errors.pl library/error.c -check scripts/generate_query_config.pl programs/test/query_config.c -check scripts/generate_driver_wrappers.py library/psa_crypto_driver_wrappers.h library/psa_crypto_driver_wrappers_no_static.c -check scripts/generate_features.pl library/version_features.c -check scripts/generate_ssl_debug_helpers.py library/ssl_debug_helpers_generated.c -# generate_visualc_files enumerates source files (library/*.c). It doesn't -# care about their content, but the files must exist. So it must run after -# the step that creates or updates these files. -check scripts/generate_visualc_files.pl visualc/VS2013 +# These checks are common to Mbed TLS and TF PSA Crypto check scripts/generate_psa_constants.py programs/psa/psa_constant_names_generated.c check tests/scripts/generate_bignum_tests.py $(tests/scripts/generate_bignum_tests.py --list) check tests/scripts/generate_ecp_tests.py $(tests/scripts/generate_ecp_tests.py --list) check tests/scripts/generate_psa_tests.py $(tests/scripts/generate_psa_tests.py --list) + +# Additional checks for Mbed TLS only +if [ $IN_MBEDTLS -eq 1 ]; then + check scripts/generate_errors.pl library/error.c + check scripts/generate_query_config.pl programs/test/query_config.c + check scripts/generate_driver_wrappers.py library/psa_crypto_driver_wrappers.h library/psa_crypto_driver_wrappers_no_static.c + check scripts/generate_features.pl library/version_features.c + check scripts/generate_ssl_debug_helpers.py library/ssl_debug_helpers_generated.c + # generate_visualc_files enumerates source files (library/*.c). It doesn't + # care about their content, but the files must exist. So it must run after + # the step that creates or updates these files. + check scripts/generate_visualc_files.pl visualc/VS2013 +fi From b10cc7acc2546e1ccf88e5b641023e8c9e2e583e Mon Sep 17 00:00:00 2001 From: Thomas Daubney Date: Tue, 14 Nov 2023 11:56:02 +0000 Subject: [PATCH 03/34] Modify generate_driver_wrappers.py to work in both repos Add repository detection and conditional setting of library_dir variable. Signed-off-by: Thomas Daubney --- scripts/generate_driver_wrappers.py | 23 +++++++++++++++++++++-- 1 file changed, 21 insertions(+), 2 deletions(-) diff --git a/scripts/generate_driver_wrappers.py b/scripts/generate_driver_wrappers.py index 2fdc4cd0baf0..b510cdf43602 100755 --- a/scripts/generate_driver_wrappers.py +++ b/scripts/generate_driver_wrappers.py @@ -7,7 +7,19 @@ based on template files in script/data_files/driver_templates/. """ # Copyright The Mbed TLS Contributors -# SPDX-License-Identifier: Apache-2.0 OR GPL-2.0-or-later +# SPDX-License-Identifier: Apache-2.0 +# +# Licensed under the Apache License, Version 2.0 (the "License"); you may +# not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT +# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. import sys import os @@ -178,8 +190,15 @@ def main() -> int: mbedtls_root = os.path.abspath(args.mbedtls_root) + library_dir = '' + if build_tree.looks_like_mbedtls_root(mbedtls_root): + library_dir = 'library' + elif build_tree.looks_like_tf_psa_crypto_root(mbedtls_root): + library_dir = 'core' + output_directory = args.output_directory if args.output_directory is not None else \ - os.path.join(mbedtls_root, 'library') + os.path.join(mbedtls_root, library_dir) + template_directory = args.template_dir if args.template_dir is not None else \ os.path.join(mbedtls_root, 'scripts', From d3f844337f95daeb926bb7a3090e1f01d07dd342 Mon Sep 17 00:00:00 2001 From: Thomas Daubney Date: Tue, 14 Nov 2023 11:53:14 +0000 Subject: [PATCH 04/34] Further modify check-generated-files.sh Add further modifications to repo detection and calling the checks. Signed-off-by: Thomas Daubney --- tests/scripts/check-generated-files.sh | 20 +++++++++++++++----- 1 file changed, 15 insertions(+), 5 deletions(-) diff --git a/tests/scripts/check-generated-files.sh b/tests/scripts/check-generated-files.sh index 0689147f0eef..6f92ecd311f3 100755 --- a/tests/scripts/check-generated-files.sh +++ b/tests/scripts/check-generated-files.sh @@ -22,15 +22,25 @@ EOF exit fi -IN_MBEDTLS=0 -if [ -d library -a -d include -a -d tests ]; then - IN_MBEDTLS=1 +# Detect whether we are in one of Mbed TLS or TF-PSA-Crypto and exit if not +if [ -d library -a -d include -a -d tests ]; then :; elif [ -d core -a -d include -a -d tests ]; then :; else echo "Must be run from Mbed TLS root or TF-PSA-Crypto root" >&2 exit 1 fi +# Now we know we are in one of Mbed TLS or TF-PSA-Crypto, determine which one +in_mbedtls_build_dir () { + test -d library +} + +if in_mbedtls_build_dir; then + library_dir='library' +else + library_dir='core' +fi + UPDATE= LIST= while getopts lu OPTLET; do @@ -123,12 +133,12 @@ check scripts/generate_psa_constants.py programs/psa/psa_constant_names_generate check tests/scripts/generate_bignum_tests.py $(tests/scripts/generate_bignum_tests.py --list) check tests/scripts/generate_ecp_tests.py $(tests/scripts/generate_ecp_tests.py --list) check tests/scripts/generate_psa_tests.py $(tests/scripts/generate_psa_tests.py --list) +check scripts/generate_driver_wrappers.py $library_dir/psa_crypto_driver_wrappers.h $library_dir/psa_crypto_driver_wrappers_no_static.c # Additional checks for Mbed TLS only -if [ $IN_MBEDTLS -eq 1 ]; then +if in_mbedtls_build_dir; then check scripts/generate_errors.pl library/error.c check scripts/generate_query_config.pl programs/test/query_config.c - check scripts/generate_driver_wrappers.py library/psa_crypto_driver_wrappers.h library/psa_crypto_driver_wrappers_no_static.c check scripts/generate_features.pl library/version_features.c check scripts/generate_ssl_debug_helpers.py library/ssl_debug_helpers_generated.c # generate_visualc_files enumerates source files (library/*.c). It doesn't From 0bb761cc2f6bb4ea6e2a03ac80cb81bfbddf15ac Mon Sep 17 00:00:00 2001 From: Thomas Daubney Date: Tue, 14 Nov 2023 12:03:10 +0000 Subject: [PATCH 05/34] Remove further extraneous whitespace in lcov script Signed-off-by: Thomas Daubney --- scripts/lcov.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/scripts/lcov.sh b/scripts/lcov.sh index 1969b3904428..0584a0aac744 100755 --- a/scripts/lcov.sh +++ b/scripts/lcov.sh @@ -32,7 +32,7 @@ set -eu # Repository detection in_mbedtls_build_dir () { - test -d library + test -d library } # Collect stats and build a HTML report. From c1750bb23d8b5e3016545ff8413fe6c4b868bb71 Mon Sep 17 00:00:00 2001 From: Thomas Daubney Date: Tue, 14 Nov 2023 15:16:38 +0000 Subject: [PATCH 06/34] Apply correct license to generate_driver_wrappers.py Signed-off-by: Thomas Daubney --- scripts/generate_driver_wrappers.py | 14 +------------- 1 file changed, 1 insertion(+), 13 deletions(-) diff --git a/scripts/generate_driver_wrappers.py b/scripts/generate_driver_wrappers.py index b510cdf43602..e48ec3a52f98 100755 --- a/scripts/generate_driver_wrappers.py +++ b/scripts/generate_driver_wrappers.py @@ -7,19 +7,7 @@ based on template files in script/data_files/driver_templates/. """ # Copyright The Mbed TLS Contributors -# SPDX-License-Identifier: Apache-2.0 -# -# Licensed under the Apache License, Version 2.0 (the "License"); you may -# not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT -# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. +# SPDX-License-Identifier: Apache-2.0 OR GPL-2.0-or-later import sys import os From e58128e2ba4597747e9d7811bc8b516fb8d271f7 Mon Sep 17 00:00:00 2001 From: Thomas Daubney Date: Tue, 14 Nov 2023 15:25:52 +0000 Subject: [PATCH 07/34] Refactor repository detection Signed-off-by: Thomas Daubney --- tests/scripts/check-generated-files.sh | 23 ++++++++++------------- 1 file changed, 10 insertions(+), 13 deletions(-) diff --git a/tests/scripts/check-generated-files.sh b/tests/scripts/check-generated-files.sh index 6f92ecd311f3..92531a8d034d 100755 --- a/tests/scripts/check-generated-files.sh +++ b/tests/scripts/check-generated-files.sh @@ -22,23 +22,20 @@ EOF exit fi -# Detect whether we are in one of Mbed TLS or TF-PSA-Crypto and exit if not -if [ -d library -a -d include -a -d tests ]; then :; -elif [ -d core -a -d include -a -d tests ]; then :; -else - echo "Must be run from Mbed TLS root or TF-PSA-Crypto root" >&2 - exit 1 -fi - -# Now we know we are in one of Mbed TLS or TF-PSA-Crypto, determine which one -in_mbedtls_build_dir () { - test -d library +in_mbedtls_repo () { + test -d include -a -d library -a -d programs -a -d tests } -if in_mbedtls_build_dir; then +in_tf_psa_crypto_repo () { + test -d include -a -d core -a -d drivers -a -d programs -a -d tests +} +if in_mbedtls_repo; then library_dir='library' -else +elif in_tf_psa_crypto_repo; then library_dir='core' +else + echo "Must be run from Mbed TLS root or TF-PSA-Crypto root" >&2 + exit 1 fi UPDATE= From d289b8bdca0584bf9a2cdf7725fc78accecf7013 Mon Sep 17 00:00:00 2001 From: Thomas Daubney Date: Tue, 14 Nov 2023 15:30:07 +0000 Subject: [PATCH 08/34] Stylise TF-PSA-Crypto correctly Signed-off-by: Thomas Daubney --- tests/scripts/check-generated-files.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/scripts/check-generated-files.sh b/tests/scripts/check-generated-files.sh index 92531a8d034d..84fbbda9147a 100755 --- a/tests/scripts/check-generated-files.sh +++ b/tests/scripts/check-generated-files.sh @@ -125,7 +125,7 @@ check() # - **/CMakeLists.txt (to (re)build them with cmake) # - scripts/make_generated_files.bat (to generate them under Windows) -# These checks are common to Mbed TLS and TF PSA Crypto +# These checks are common to Mbed TLS and TF-PSA-Crypto check scripts/generate_psa_constants.py programs/psa/psa_constant_names_generated.c check tests/scripts/generate_bignum_tests.py $(tests/scripts/generate_bignum_tests.py --list) check tests/scripts/generate_ecp_tests.py $(tests/scripts/generate_ecp_tests.py --list) From 0eb2dc11c41934eef53b51d1bdd52e86c375b27e Mon Sep 17 00:00:00 2001 From: Thomas Daubney Date: Tue, 14 Nov 2023 16:56:45 +0000 Subject: [PATCH 09/34] Call the right function Correct erroneous function call Signed-off-by: Thomas Daubney --- tests/scripts/check-generated-files.sh | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/tests/scripts/check-generated-files.sh b/tests/scripts/check-generated-files.sh index 84fbbda9147a..410f44eb05a9 100755 --- a/tests/scripts/check-generated-files.sh +++ b/tests/scripts/check-generated-files.sh @@ -28,7 +28,8 @@ in_mbedtls_repo () { in_tf_psa_crypto_repo () { test -d include -a -d core -a -d drivers -a -d programs -a -d tests -} +} + if in_mbedtls_repo; then library_dir='library' elif in_tf_psa_crypto_repo; then @@ -133,7 +134,7 @@ check tests/scripts/generate_psa_tests.py $(tests/scripts/generate_psa_tests.py check scripts/generate_driver_wrappers.py $library_dir/psa_crypto_driver_wrappers.h $library_dir/psa_crypto_driver_wrappers_no_static.c # Additional checks for Mbed TLS only -if in_mbedtls_build_dir; then +if in_mbedtls_repo; then check scripts/generate_errors.pl library/error.c check scripts/generate_query_config.pl programs/test/query_config.c check scripts/generate_features.pl library/version_features.c From 4291bc27b96f944f66348c11b8df9bf73670f988 Mon Sep 17 00:00:00 2001 From: Thomas Daubney Date: Tue, 14 Nov 2023 18:05:19 +0000 Subject: [PATCH 10/34] Remove trailing whitespace Signed-off-by: Thomas Daubney --- scripts/generate_driver_wrappers.py | 4 ++-- tests/scripts/check-generated-files.sh | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/scripts/generate_driver_wrappers.py b/scripts/generate_driver_wrappers.py index e48ec3a52f98..09beeca49b38 100755 --- a/scripts/generate_driver_wrappers.py +++ b/scripts/generate_driver_wrappers.py @@ -183,10 +183,10 @@ def main() -> int: library_dir = 'library' elif build_tree.looks_like_tf_psa_crypto_root(mbedtls_root): library_dir = 'core' - + output_directory = args.output_directory if args.output_directory is not None else \ os.path.join(mbedtls_root, library_dir) - + template_directory = args.template_dir if args.template_dir is not None else \ os.path.join(mbedtls_root, 'scripts', diff --git a/tests/scripts/check-generated-files.sh b/tests/scripts/check-generated-files.sh index 410f44eb05a9..3fe4e8c63aed 100755 --- a/tests/scripts/check-generated-files.sh +++ b/tests/scripts/check-generated-files.sh @@ -32,7 +32,7 @@ in_tf_psa_crypto_repo () { if in_mbedtls_repo; then library_dir='library' -elif in_tf_psa_crypto_repo; then +elif in_tf_psa_crypto_repo; then library_dir='core' else echo "Must be run from Mbed TLS root or TF-PSA-Crypto root" >&2 From 5556f908cbaa39da0a718686e9e51c2d42baf3bd Mon Sep 17 00:00:00 2001 From: Thomas Daubney Date: Wed, 15 Nov 2023 16:43:02 +0000 Subject: [PATCH 11/34] Rename variables in script Rename some variables in generate_driver_wrappers.py now that the script has to work in two repositories as opposed to just mbed tls. Signed-off-by: Thomas Daubney --- scripts/generate_driver_wrappers.py | 30 ++++++++++++++--------------- 1 file changed, 15 insertions(+), 15 deletions(-) diff --git a/scripts/generate_driver_wrappers.py b/scripts/generate_driver_wrappers.py index 09beeca49b38..538999af8c6d 100755 --- a/scripts/generate_driver_wrappers.py +++ b/scripts/generate_driver_wrappers.py @@ -108,17 +108,17 @@ def load_driver(schemas: Dict[str, Any], driver_file: str) -> Any: return json_data -def load_schemas(mbedtls_root: str) -> Dict[str, Any]: +def load_schemas(repo_root: str) -> Dict[str, Any]: """ Load schemas map """ schema_file_paths = { - 'transparent': os.path.join(mbedtls_root, + 'transparent': os.path.join(repo_root, 'scripts', 'data_files', 'driver_jsons', 'driver_transparent_schema.json'), - 'opaque': os.path.join(mbedtls_root, + 'opaque': os.path.join(repo_root, 'scripts', 'data_files', 'driver_jsons', @@ -131,13 +131,13 @@ def load_schemas(mbedtls_root: str) -> Dict[str, Any]: return driver_schema -def read_driver_descriptions(mbedtls_root: str, +def read_driver_descriptions(repo_root: str, json_directory: str, jsondriver_list: str) -> list: """ Merge driver JSON files into a single ordered JSON after validation. """ - driver_schema = load_schemas(mbedtls_root) + driver_schema = load_schemas(repo_root) with open(file=os.path.join(json_directory, jsondriver_list), mode='r', @@ -163,11 +163,11 @@ def main() -> int: """ Main with command line arguments. """ - def_arg_mbedtls_root = build_tree.guess_mbedtls_root() + def_arg_repo_root = build_tree.guess_mbedtls_root() parser = argparse.ArgumentParser() - parser.add_argument('--mbedtls-root', default=def_arg_mbedtls_root, - help='root directory of mbedtls source code') + parser.add_argument('--repo-root', default=def_arg_repo_root, + help='root directory of repo source code') parser.add_argument('--template-dir', help='directory holding the driver templates') parser.add_argument('--json-dir', @@ -176,31 +176,31 @@ def main() -> int: help='output file\'s location') args = parser.parse_args() - mbedtls_root = os.path.abspath(args.mbedtls_root) + repo_root = os.path.abspath(args.repo_root) library_dir = '' - if build_tree.looks_like_mbedtls_root(mbedtls_root): + if build_tree.looks_like_mbedtls_root(repo_root): library_dir = 'library' - elif build_tree.looks_like_tf_psa_crypto_root(mbedtls_root): + elif build_tree.looks_like_tf_psa_crypto_root(repo_root): library_dir = 'core' output_directory = args.output_directory if args.output_directory is not None else \ - os.path.join(mbedtls_root, library_dir) + os.path.join(repo_root, library_dir) template_directory = args.template_dir if args.template_dir is not None else \ - os.path.join(mbedtls_root, + os.path.join(repo_root, 'scripts', 'data_files', 'driver_templates') json_directory = args.json_dir if args.json_dir is not None else \ - os.path.join(mbedtls_root, + os.path.join(repo_root, 'scripts', 'data_files', 'driver_jsons') try: # Read and validate list of driver jsons from driverlist.json - merged_driver_json = read_driver_descriptions(mbedtls_root, + merged_driver_json = read_driver_descriptions(repo_root, json_directory, 'driverlist.json') except DriverReaderException as e: From 13ecb691a30ff178fbf128711bbff63c508cb68d Mon Sep 17 00:00:00 2001 From: Thomas Daubney Date: Thu, 16 Nov 2023 18:34:58 +0000 Subject: [PATCH 12/34] Introduce function to return library/core directory Add crypto_core_directory in build_tree.py so that the libary/core directory can be returned based on what repository we are in. Signed-off-by: Thomas Daubney --- scripts/mbedtls_dev/build_tree.py | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/scripts/mbedtls_dev/build_tree.py b/scripts/mbedtls_dev/build_tree.py index a657a51383b1..4a42d9a2bab5 100644 --- a/scripts/mbedtls_dev/build_tree.py +++ b/scripts/mbedtls_dev/build_tree.py @@ -21,6 +21,14 @@ def looks_like_mbedtls_root(path: str) -> bool: def looks_like_root(path: str) -> bool: return looks_like_tf_psa_crypto_root(path) or looks_like_mbedtls_root(path) +def crypto_core_directory() -> str: + if looks_like_tf_psa_crypto_root(os.path.curdir): + return "core" + elif looks_like_mbedtls_root(os.path.curdir): + return "library" + else: + raise Exception('Neither Mbed TLS nor TF-PSA-Crypto source tree found') + def check_repo_path(): """ Check that the current working directory is the project root, and throw From 79cae20a025d7a988d00e443331b348b479119e3 Mon Sep 17 00:00:00 2001 From: Thomas Daubney Date: Wed, 22 Nov 2023 15:49:19 +0000 Subject: [PATCH 13/34] Remove useless line Signed-off-by: Thomas Daubney --- scripts/generate_driver_wrappers.py | 1 - 1 file changed, 1 deletion(-) diff --git a/scripts/generate_driver_wrappers.py b/scripts/generate_driver_wrappers.py index 538999af8c6d..de8995947a4d 100755 --- a/scripts/generate_driver_wrappers.py +++ b/scripts/generate_driver_wrappers.py @@ -178,7 +178,6 @@ def main() -> int: repo_root = os.path.abspath(args.repo_root) - library_dir = '' if build_tree.looks_like_mbedtls_root(repo_root): library_dir = 'library' elif build_tree.looks_like_tf_psa_crypto_root(repo_root): From b42c50bd6044b29d00012adf02bd8f607c5a2dc3 Mon Sep 17 00:00:00 2001 From: Thomas Daubney Date: Wed, 22 Nov 2023 15:53:38 +0000 Subject: [PATCH 14/34] Make use of new crypto_core_directory function Signed-off-by: Thomas Daubney --- scripts/generate_driver_wrappers.py | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/scripts/generate_driver_wrappers.py b/scripts/generate_driver_wrappers.py index de8995947a4d..a3c858859792 100755 --- a/scripts/generate_driver_wrappers.py +++ b/scripts/generate_driver_wrappers.py @@ -178,10 +178,7 @@ def main() -> int: repo_root = os.path.abspath(args.repo_root) - if build_tree.looks_like_mbedtls_root(repo_root): - library_dir = 'library' - elif build_tree.looks_like_tf_psa_crypto_root(repo_root): - library_dir = 'core' + library_dir = build_tree.crypto_core_directory(repo_root) output_directory = args.output_directory if args.output_directory is not None else \ os.path.join(repo_root, library_dir) From 772056ccea0535c3b764f9a4d51e844547e1080f Mon Sep 17 00:00:00 2001 From: Thomas Daubney Date: Wed, 22 Nov 2023 16:23:16 +0000 Subject: [PATCH 15/34] Replace repo_root with project_root Signed-off-by: Thomas Daubney --- scripts/generate_driver_wrappers.py | 26 +++++++++++++------------- 1 file changed, 13 insertions(+), 13 deletions(-) diff --git a/scripts/generate_driver_wrappers.py b/scripts/generate_driver_wrappers.py index a3c858859792..709f380cd63d 100755 --- a/scripts/generate_driver_wrappers.py +++ b/scripts/generate_driver_wrappers.py @@ -108,17 +108,17 @@ def load_driver(schemas: Dict[str, Any], driver_file: str) -> Any: return json_data -def load_schemas(repo_root: str) -> Dict[str, Any]: +def load_schemas(project_root: str) -> Dict[str, Any]: """ Load schemas map """ schema_file_paths = { - 'transparent': os.path.join(repo_root, + 'transparent': os.path.join(project_root, 'scripts', 'data_files', 'driver_jsons', 'driver_transparent_schema.json'), - 'opaque': os.path.join(repo_root, + 'opaque': os.path.join(project_root, 'scripts', 'data_files', 'driver_jsons', @@ -131,13 +131,13 @@ def load_schemas(repo_root: str) -> Dict[str, Any]: return driver_schema -def read_driver_descriptions(repo_root: str, +def read_driver_descriptions(project_root: str, json_directory: str, jsondriver_list: str) -> list: """ Merge driver JSON files into a single ordered JSON after validation. """ - driver_schema = load_schemas(repo_root) + driver_schema = load_schemas(project_root) with open(file=os.path.join(json_directory, jsondriver_list), mode='r', @@ -163,10 +163,10 @@ def main() -> int: """ Main with command line arguments. """ - def_arg_repo_root = build_tree.guess_mbedtls_root() + def_arg_project_root = build_tree.guess_mbedtls_root() parser = argparse.ArgumentParser() - parser.add_argument('--repo-root', default=def_arg_repo_root, + parser.add_argument('--project-root', default=def_arg_project_root, help='root directory of repo source code') parser.add_argument('--template-dir', help='directory holding the driver templates') @@ -176,27 +176,27 @@ def main() -> int: help='output file\'s location') args = parser.parse_args() - repo_root = os.path.abspath(args.repo_root) + project_root = os.path.abspath(args.project_root) - library_dir = build_tree.crypto_core_directory(repo_root) + library_dir = build_tree.crypto_core_directory(project_root) output_directory = args.output_directory if args.output_directory is not None else \ - os.path.join(repo_root, library_dir) + os.path.join(project_root, library_dir) template_directory = args.template_dir if args.template_dir is not None else \ - os.path.join(repo_root, + os.path.join(project_root, 'scripts', 'data_files', 'driver_templates') json_directory = args.json_dir if args.json_dir is not None else \ - os.path.join(repo_root, + os.path.join(project_root, 'scripts', 'data_files', 'driver_jsons') try: # Read and validate list of driver jsons from driverlist.json - merged_driver_json = read_driver_descriptions(repo_root, + merged_driver_json = read_driver_descriptions(project_root, json_directory, 'driverlist.json') except DriverReaderException as e: From d35b94b662c4cbbd9cdd7df1acbf8849f833c923 Mon Sep 17 00:00:00 2001 From: Thomas Daubney Date: Wed, 22 Nov 2023 17:00:34 +0000 Subject: [PATCH 16/34] Improve implementation of crypto_core_directory Signed-off-by: Thomas Daubney --- scripts/mbedtls_dev/build_tree.py | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/scripts/mbedtls_dev/build_tree.py b/scripts/mbedtls_dev/build_tree.py index 4a42d9a2bab5..9c0b5ba96467 100644 --- a/scripts/mbedtls_dev/build_tree.py +++ b/scripts/mbedtls_dev/build_tree.py @@ -7,6 +7,7 @@ import os import inspect +from typing import Optional def looks_like_tf_psa_crypto_root(path: str) -> bool: """Whether the given directory looks like the root of the PSA Crypto source tree.""" @@ -21,10 +22,12 @@ def looks_like_mbedtls_root(path: str) -> bool: def looks_like_root(path: str) -> bool: return looks_like_tf_psa_crypto_root(path) or looks_like_mbedtls_root(path) -def crypto_core_directory() -> str: - if looks_like_tf_psa_crypto_root(os.path.curdir): +def crypto_core_directory(root: Optional[str] = None) -> str: + if root is None: + root = guess_mbedtls_root() + if looks_like_tf_psa_crypto_root(root): return "core" - elif looks_like_mbedtls_root(os.path.curdir): + elif looks_like_mbedtls_root(root): return "library" else: raise Exception('Neither Mbed TLS nor TF-PSA-Crypto source tree found') From 755d32117bb031ebb3d7c24fd53f9a48225de671 Mon Sep 17 00:00:00 2001 From: Thomas Daubney Date: Wed, 22 Nov 2023 17:18:22 +0000 Subject: [PATCH 17/34] Rename guess_mbedtls_root to guess_project_root Rename for consistency. Also, replace all calls to this function with correct name. Signed-off-by: Thomas Daubney --- scripts/generate_driver_wrappers.py | 2 +- scripts/generate_ssl_debug_helpers.py | 2 +- scripts/mbedtls_dev/build_tree.py | 10 +++++----- tests/scripts/audit-validity-dates.py | 2 +- 4 files changed, 8 insertions(+), 8 deletions(-) diff --git a/scripts/generate_driver_wrappers.py b/scripts/generate_driver_wrappers.py index 709f380cd63d..5223d459fd7f 100755 --- a/scripts/generate_driver_wrappers.py +++ b/scripts/generate_driver_wrappers.py @@ -163,7 +163,7 @@ def main() -> int: """ Main with command line arguments. """ - def_arg_project_root = build_tree.guess_mbedtls_root() + def_arg_project_root = build_tree.guess_project_root() parser = argparse.ArgumentParser() parser.add_argument('--project-root', default=def_arg_project_root, diff --git a/scripts/generate_ssl_debug_helpers.py b/scripts/generate_ssl_debug_helpers.py index a0544f1537df..af8ef86eed89 100755 --- a/scripts/generate_ssl_debug_helpers.py +++ b/scripts/generate_ssl_debug_helpers.py @@ -367,7 +367,7 @@ def generate_ssl_debug_helpers(output_directory, mbedtls_root): Generate functions of debug helps """ mbedtls_root = os.path.abspath( - mbedtls_root or build_tree.guess_mbedtls_root()) + mbedtls_root or build_tree.guess_project_root()) with open(os.path.join(mbedtls_root, 'include/mbedtls/ssl.h')) as f: source_code = remove_c_comments(f.read()) diff --git a/scripts/mbedtls_dev/build_tree.py b/scripts/mbedtls_dev/build_tree.py index 9c0b5ba96467..da455a7f2c2f 100644 --- a/scripts/mbedtls_dev/build_tree.py +++ b/scripts/mbedtls_dev/build_tree.py @@ -24,7 +24,7 @@ def looks_like_root(path: str) -> bool: def crypto_core_directory(root: Optional[str] = None) -> str: if root is None: - root = guess_mbedtls_root() + root = guess_project_root() if looks_like_tf_psa_crypto_root(root): return "core" elif looks_like_mbedtls_root(root): @@ -55,10 +55,10 @@ def chdir_to_root() -> None: raise Exception('Mbed TLS source tree not found') -def guess_mbedtls_root(): - """Guess mbedTLS source code directory. +def guess_project_root(): + """Guess project source code directory. - Return the first possible mbedTLS root directory + Return the first possible project root directory. """ dirs = set({}) for frame in inspect.stack(): @@ -71,4 +71,4 @@ def guess_mbedtls_root(): dirs.add(d) if looks_like_root(d): return d - raise Exception('Mbed TLS source tree not found') + raise Exception('Neither Mbed TLS nor TF-PSA-Crypto source tree found') diff --git a/tests/scripts/audit-validity-dates.py b/tests/scripts/audit-validity-dates.py index 96b705a281fa..ab09b4a1e695 100755 --- a/tests/scripts/audit-validity-dates.py +++ b/tests/scripts/audit-validity-dates.py @@ -265,7 +265,7 @@ def walk_all(self, @staticmethod def find_test_dir(): """Get the relative path for the Mbed TLS test directory.""" - return os.path.relpath(build_tree.guess_mbedtls_root() + '/tests') + return os.path.relpath(build_tree.guess_project_root() + '/tests') class TestDataAuditor(Auditor): From d0c3076dba98d48dc5ab866f197923ad75615d45 Mon Sep 17 00:00:00 2001 From: Thomas Daubney Date: Thu, 23 Nov 2023 09:59:57 +0000 Subject: [PATCH 18/34] Make use of crypto_core_directory function in script Signed-off-by: Thomas Daubney --- tests/scripts/test_psa_compliance.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/tests/scripts/test_psa_compliance.py b/tests/scripts/test_psa_compliance.py index bed6d849e050..2482d032afc1 100755 --- a/tests/scripts/test_psa_compliance.py +++ b/tests/scripts/test_psa_compliance.py @@ -52,10 +52,10 @@ def main(library_build_dir: str): if in_tf_psa_crypto_repo: crypto_name = 'tfpsacrypto' - library_subdir = 'core' else: crypto_name = 'mbedcrypto' - library_subdir = 'library' + + library_subdir = build_tree.crypto_core_directory() crypto_lib_filename = (library_build_dir + '/' + library_subdir + '/' + From 8932404c456abfde51fac9b818120255018ec303 Mon Sep 17 00:00:00 2001 From: Thomas Daubney Date: Thu, 23 Nov 2023 10:14:12 +0000 Subject: [PATCH 19/34] Introduce project_crypto_name in build_tree.py Add new function to build_tree.py to return the crypto name for the project; either tfpsacrypto or mbedcrypto. Deploy this function where needed. Signed-off-by: Thomas Daubney --- scripts/mbedtls_dev/build_tree.py | 10 ++++++++++ tests/scripts/test_psa_compliance.py | 5 +---- 2 files changed, 11 insertions(+), 4 deletions(-) diff --git a/scripts/mbedtls_dev/build_tree.py b/scripts/mbedtls_dev/build_tree.py index da455a7f2c2f..f506c4142eb2 100644 --- a/scripts/mbedtls_dev/build_tree.py +++ b/scripts/mbedtls_dev/build_tree.py @@ -32,6 +32,16 @@ def crypto_core_directory(root: Optional[str] = None) -> str: else: raise Exception('Neither Mbed TLS nor TF-PSA-Crypto source tree found') +def project_crypto_name(root: Optional[str] = None) -> str: + if root is None: + root = guess_project_root() + if looks_like_tf_psa_crypto_root(root): + return "tfpsacrypto" + elif looks_like_mbedtls_root(root): + return "mbedcrypto" + else: + raise Exception('Neither Mbed TLS nor TF-PSA-Crypto source tree found') + def check_repo_path(): """ Check that the current working directory is the project root, and throw diff --git a/tests/scripts/test_psa_compliance.py b/tests/scripts/test_psa_compliance.py index 2482d032afc1..82cc1b1db87e 100755 --- a/tests/scripts/test_psa_compliance.py +++ b/tests/scripts/test_psa_compliance.py @@ -50,10 +50,7 @@ def main(library_build_dir: str): in_tf_psa_crypto_repo = build_tree.looks_like_tf_psa_crypto_root(root_dir) - if in_tf_psa_crypto_repo: - crypto_name = 'tfpsacrypto' - else: - crypto_name = 'mbedcrypto' + crypto_name = build_tree.project_crypto_name() library_subdir = build_tree.crypto_core_directory() From beec452e3ccb52ca1e585a8e8450d97e9f879472 Mon Sep 17 00:00:00 2001 From: Thomas Daubney Date: Fri, 24 Nov 2023 10:48:44 +0000 Subject: [PATCH 20/34] Use os.path.join in crypto_core_directory Signed-off-by: Thomas Daubney --- scripts/mbedtls_dev/build_tree.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/scripts/mbedtls_dev/build_tree.py b/scripts/mbedtls_dev/build_tree.py index f506c4142eb2..fa309d3e6cfc 100644 --- a/scripts/mbedtls_dev/build_tree.py +++ b/scripts/mbedtls_dev/build_tree.py @@ -26,9 +26,9 @@ def crypto_core_directory(root: Optional[str] = None) -> str: if root is None: root = guess_project_root() if looks_like_tf_psa_crypto_root(root): - return "core" + return os.path.join(root, "core") elif looks_like_mbedtls_root(root): - return "library" + return os.path.join(root, "library") else: raise Exception('Neither Mbed TLS nor TF-PSA-Crypto source tree found') From cdbf2fd64431ba14d0d497a20d8eb073a3814190 Mon Sep 17 00:00:00 2001 From: Thomas Daubney Date: Fri, 24 Nov 2023 10:54:56 +0000 Subject: [PATCH 21/34] Add documentation for new public functions Signed-off-by: Thomas Daubney --- scripts/mbedtls_dev/build_tree.py | 2 ++ 1 file changed, 2 insertions(+) diff --git a/scripts/mbedtls_dev/build_tree.py b/scripts/mbedtls_dev/build_tree.py index fa309d3e6cfc..4e0ae1953190 100644 --- a/scripts/mbedtls_dev/build_tree.py +++ b/scripts/mbedtls_dev/build_tree.py @@ -23,6 +23,7 @@ def looks_like_root(path: str) -> bool: return looks_like_tf_psa_crypto_root(path) or looks_like_mbedtls_root(path) def crypto_core_directory(root: Optional[str] = None) -> str: + """Return the path of the library code for either TF-PSA-Crypto or Mbed TLS.""" if root is None: root = guess_project_root() if looks_like_tf_psa_crypto_root(root): @@ -33,6 +34,7 @@ def crypto_core_directory(root: Optional[str] = None) -> str: raise Exception('Neither Mbed TLS nor TF-PSA-Crypto source tree found') def project_crypto_name(root: Optional[str] = None) -> str: + """Return the crypto library filename for either TF-PSA-Crypto or Mbed TLS.""" if root is None: root = guess_project_root() if looks_like_tf_psa_crypto_root(root): From fc60e9b7bf92698ae13dde72ea21dcc17a71f874 Mon Sep 17 00:00:00 2001 From: Thomas Daubney Date: Fri, 24 Nov 2023 10:56:04 +0000 Subject: [PATCH 22/34] Make function calls consistent Signed-off-by: Thomas Daubney --- tests/scripts/test_psa_compliance.py | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/tests/scripts/test_psa_compliance.py b/tests/scripts/test_psa_compliance.py index 82cc1b1db87e..034949bc6b6b 100755 --- a/tests/scripts/test_psa_compliance.py +++ b/tests/scripts/test_psa_compliance.py @@ -50,9 +50,8 @@ def main(library_build_dir: str): in_tf_psa_crypto_repo = build_tree.looks_like_tf_psa_crypto_root(root_dir) - crypto_name = build_tree.project_crypto_name() - - library_subdir = build_tree.crypto_core_directory() + crypto_name = build_tree.project_crypto_name(root_dir) + library_subdir = build_tree.crypto_core_directory(root_dir) crypto_lib_filename = (library_build_dir + '/' + library_subdir + '/' + From 6130a619f8800e7b41970e89aba3a8c39d784730 Mon Sep 17 00:00:00 2001 From: Thomas Daubney Date: Fri, 24 Nov 2023 10:58:07 +0000 Subject: [PATCH 23/34] Remove unused variable Signed-off-by: Thomas Daubney --- tests/scripts/test_psa_compliance.py | 2 -- 1 file changed, 2 deletions(-) diff --git a/tests/scripts/test_psa_compliance.py b/tests/scripts/test_psa_compliance.py index 034949bc6b6b..e2ccea3de7e7 100755 --- a/tests/scripts/test_psa_compliance.py +++ b/tests/scripts/test_psa_compliance.py @@ -48,8 +48,6 @@ def main(library_build_dir: str): root_dir = os.getcwd() - in_tf_psa_crypto_repo = build_tree.looks_like_tf_psa_crypto_root(root_dir) - crypto_name = build_tree.project_crypto_name(root_dir) library_subdir = build_tree.crypto_core_directory(root_dir) From e8f37893124dca94569a7b0edf9a338d9623e7ea Mon Sep 17 00:00:00 2001 From: Thomas Daubney Date: Fri, 24 Nov 2023 11:41:23 +0000 Subject: [PATCH 24/34] Revert change that removed in_tf_psa_crypto_repo variable Signed-off-by: Thomas Daubney --- tests/scripts/test_psa_compliance.py | 2 ++ 1 file changed, 2 insertions(+) diff --git a/tests/scripts/test_psa_compliance.py b/tests/scripts/test_psa_compliance.py index e2ccea3de7e7..034949bc6b6b 100755 --- a/tests/scripts/test_psa_compliance.py +++ b/tests/scripts/test_psa_compliance.py @@ -48,6 +48,8 @@ def main(library_build_dir: str): root_dir = os.getcwd() + in_tf_psa_crypto_repo = build_tree.looks_like_tf_psa_crypto_root(root_dir) + crypto_name = build_tree.project_crypto_name(root_dir) library_subdir = build_tree.crypto_core_directory(root_dir) From 08c6dc4942cc01e75d1a3ccc9c26104ad428a11a Mon Sep 17 00:00:00 2001 From: Thomas Daubney Date: Thu, 30 Nov 2023 13:56:09 +0000 Subject: [PATCH 25/34] Rename project_crypto_name Signed-off-by: Thomas Daubney --- scripts/mbedtls_dev/build_tree.py | 2 +- tests/scripts/test_psa_compliance.py | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/scripts/mbedtls_dev/build_tree.py b/scripts/mbedtls_dev/build_tree.py index 4e0ae1953190..c2a370d7e60b 100644 --- a/scripts/mbedtls_dev/build_tree.py +++ b/scripts/mbedtls_dev/build_tree.py @@ -33,7 +33,7 @@ def crypto_core_directory(root: Optional[str] = None) -> str: else: raise Exception('Neither Mbed TLS nor TF-PSA-Crypto source tree found') -def project_crypto_name(root: Optional[str] = None) -> str: +def crypto_library_filename(root: Optional[str] = None) -> str: """Return the crypto library filename for either TF-PSA-Crypto or Mbed TLS.""" if root is None: root = guess_project_root() diff --git a/tests/scripts/test_psa_compliance.py b/tests/scripts/test_psa_compliance.py index 034949bc6b6b..984ddf3e17df 100755 --- a/tests/scripts/test_psa_compliance.py +++ b/tests/scripts/test_psa_compliance.py @@ -50,7 +50,7 @@ def main(library_build_dir: str): in_tf_psa_crypto_repo = build_tree.looks_like_tf_psa_crypto_root(root_dir) - crypto_name = build_tree.project_crypto_name(root_dir) + crypto_name = build_tree.crypto_library_filename(root_dir) library_subdir = build_tree.crypto_core_directory(root_dir) crypto_lib_filename = (library_build_dir + '/' + From 46588de8fc6165212a4e9d5fddb0c976231152f5 Mon Sep 17 00:00:00 2001 From: Thomas Daubney Date: Thu, 30 Nov 2023 13:59:30 +0000 Subject: [PATCH 26/34] Improve documentation of crypto_core_directory Signed-off-by: Thomas Daubney --- scripts/mbedtls_dev/build_tree.py | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/scripts/mbedtls_dev/build_tree.py b/scripts/mbedtls_dev/build_tree.py index c2a370d7e60b..ff8d57594d23 100644 --- a/scripts/mbedtls_dev/build_tree.py +++ b/scripts/mbedtls_dev/build_tree.py @@ -23,7 +23,10 @@ def looks_like_root(path: str) -> bool: return looks_like_tf_psa_crypto_root(path) or looks_like_mbedtls_root(path) def crypto_core_directory(root: Optional[str] = None) -> str: - """Return the path of the library code for either TF-PSA-Crypto or Mbed TLS.""" + """ + Return the path of the directory containing the PSA crypto core + for either TF-PSA-Crypto or Mbed TLS. + """ if root is None: root = guess_project_root() if looks_like_tf_psa_crypto_root(root): From 56bee0344ebd81ec1a60f70ca80a87fa5d254b36 Mon Sep 17 00:00:00 2001 From: Thomas Daubney Date: Thu, 30 Nov 2023 14:33:35 +0000 Subject: [PATCH 27/34] Rename variable for better clarity Signed-off-by: Thomas Daubney --- scripts/generate_driver_wrappers.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/scripts/generate_driver_wrappers.py b/scripts/generate_driver_wrappers.py index 5223d459fd7f..edd98a2de480 100755 --- a/scripts/generate_driver_wrappers.py +++ b/scripts/generate_driver_wrappers.py @@ -178,10 +178,10 @@ def main() -> int: project_root = os.path.abspath(args.project_root) - library_dir = build_tree.crypto_core_directory(project_root) + crypto_core_directory = build_tree.crypto_core_directory(project_root) output_directory = args.output_directory if args.output_directory is not None else \ - os.path.join(project_root, library_dir) + os.path.join(project_root, crypto_core_directory) template_directory = args.template_dir if args.template_dir is not None else \ os.path.join(project_root, From d1f2934e7880ab744a1f6fbf9ffc9497d75ccc9e Mon Sep 17 00:00:00 2001 From: Thomas Daubney Date: Thu, 30 Nov 2023 17:25:55 +0000 Subject: [PATCH 28/34] Introduce guess_mbedtls_root Signed-off-by: Thomas Daubney --- scripts/generate_ssl_debug_helpers.py | 2 +- scripts/mbedtls_dev/build_tree.py | 17 ++++++++++++++--- 2 files changed, 15 insertions(+), 4 deletions(-) diff --git a/scripts/generate_ssl_debug_helpers.py b/scripts/generate_ssl_debug_helpers.py index af8ef86eed89..a0544f1537df 100755 --- a/scripts/generate_ssl_debug_helpers.py +++ b/scripts/generate_ssl_debug_helpers.py @@ -367,7 +367,7 @@ def generate_ssl_debug_helpers(output_directory, mbedtls_root): Generate functions of debug helps """ mbedtls_root = os.path.abspath( - mbedtls_root or build_tree.guess_project_root()) + mbedtls_root or build_tree.guess_mbedtls_root()) with open(os.path.join(mbedtls_root, 'include/mbedtls/ssl.h')) as f: source_code = remove_c_comments(f.read()) diff --git a/scripts/mbedtls_dev/build_tree.py b/scripts/mbedtls_dev/build_tree.py index ff8d57594d23..1868a0f892c2 100644 --- a/scripts/mbedtls_dev/build_tree.py +++ b/scripts/mbedtls_dev/build_tree.py @@ -48,8 +48,7 @@ def crypto_library_filename(root: Optional[str] = None) -> str: raise Exception('Neither Mbed TLS nor TF-PSA-Crypto source tree found') def check_repo_path(): - """ - Check that the current working directory is the project root, and throw + """Check that the current working directory is the project root, and throw an exception if not. """ if not all(os.path.isdir(d) for d in ["include", "library", "tests"]): @@ -69,7 +68,6 @@ def chdir_to_root() -> None: return raise Exception('Mbed TLS source tree not found') - def guess_project_root(): """Guess project source code directory. @@ -87,3 +85,16 @@ def guess_project_root(): if looks_like_root(d): return d raise Exception('Neither Mbed TLS nor TF-PSA-Crypto source tree found') + +def guess_mbedtls_root(root: Optional[str] = None) -> str: + """Guess Mbed TLS source code directory. + + Return the first possible Mbed TLS root directory. + Raise an exception if we are not in Mbed TLS. + """ + if root is None: + root = guess_project_root() + if looks_like_mbedtls_root(root): + return root + else: + raise Exception('Mbed TLS source tree not found') From db80b2301c660d54f285ac1c3ac1f5b26983eafd Mon Sep 17 00:00:00 2001 From: Thomas Daubney Date: Thu, 30 Nov 2023 17:33:54 +0000 Subject: [PATCH 29/34] Introduce guess_tf_psa_crypto_root Signed-off-by: Thomas Daubney --- scripts/mbedtls_dev/build_tree.py | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/scripts/mbedtls_dev/build_tree.py b/scripts/mbedtls_dev/build_tree.py index 1868a0f892c2..86c838900024 100644 --- a/scripts/mbedtls_dev/build_tree.py +++ b/scripts/mbedtls_dev/build_tree.py @@ -98,3 +98,16 @@ def guess_mbedtls_root(root: Optional[str] = None) -> str: return root else: raise Exception('Mbed TLS source tree not found') + +def guess_tf_psa_crypto_root(root: Optional[str] = None) -> str: + """Guess TF-PSA-Crypto source code directory. + + Return the first possible TF-PSA-Crypto root directory. + Raise an exception if we are not in TF-PSA-Crypto. + """ + if root is None: + root = guess_project_root() + if looks_like_tf_psa_crypto_root(root): + return root + else: + raise Exception('TF-PSA-Crypto source tree not found') From 99030e2a506cf7edc5611538a137658948d97179 Mon Sep 17 00:00:00 2001 From: Thomas Daubney Date: Fri, 1 Dec 2023 09:52:35 +0000 Subject: [PATCH 30/34] Remove trailing whitespace Signed-off-by: Thomas Daubney --- scripts/mbedtls_dev/build_tree.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/scripts/mbedtls_dev/build_tree.py b/scripts/mbedtls_dev/build_tree.py index 86c838900024..14790fc9cc2e 100644 --- a/scripts/mbedtls_dev/build_tree.py +++ b/scripts/mbedtls_dev/build_tree.py @@ -24,7 +24,7 @@ def looks_like_root(path: str) -> bool: def crypto_core_directory(root: Optional[str] = None) -> str: """ - Return the path of the directory containing the PSA crypto core + Return the path of the directory containing the PSA crypto core for either TF-PSA-Crypto or Mbed TLS. """ if root is None: From 04c446cc2131781303f4b09f80c08a9f418ede2c Mon Sep 17 00:00:00 2001 From: Thomas Daubney Date: Fri, 1 Dec 2023 17:18:38 +0000 Subject: [PATCH 31/34] Modify crypto_core_directory to also return a relative path Signed-off-by: Thomas Daubney --- scripts/mbedtls_dev/build_tree.py | 9 ++++++++- tests/scripts/test_psa_compliance.py | 2 +- 2 files changed, 9 insertions(+), 2 deletions(-) diff --git a/scripts/mbedtls_dev/build_tree.py b/scripts/mbedtls_dev/build_tree.py index 14790fc9cc2e..ec67e4cdfab3 100644 --- a/scripts/mbedtls_dev/build_tree.py +++ b/scripts/mbedtls_dev/build_tree.py @@ -22,16 +22,23 @@ def looks_like_mbedtls_root(path: str) -> bool: def looks_like_root(path: str) -> bool: return looks_like_tf_psa_crypto_root(path) or looks_like_mbedtls_root(path) -def crypto_core_directory(root: Optional[str] = None) -> str: +def crypto_core_directory(root: Optional[str] = None, relative: Optional[bool] = False) -> str: """ Return the path of the directory containing the PSA crypto core for either TF-PSA-Crypto or Mbed TLS. + + Returns either the full path or relative path depending on the + "relative" boolean argument. """ if root is None: root = guess_project_root() if looks_like_tf_psa_crypto_root(root): + if relative: + return "core" return os.path.join(root, "core") elif looks_like_mbedtls_root(root): + if relative: + return "library" return os.path.join(root, "library") else: raise Exception('Neither Mbed TLS nor TF-PSA-Crypto source tree found') diff --git a/tests/scripts/test_psa_compliance.py b/tests/scripts/test_psa_compliance.py index 984ddf3e17df..57e4fbd5266e 100755 --- a/tests/scripts/test_psa_compliance.py +++ b/tests/scripts/test_psa_compliance.py @@ -51,7 +51,7 @@ def main(library_build_dir: str): in_tf_psa_crypto_repo = build_tree.looks_like_tf_psa_crypto_root(root_dir) crypto_name = build_tree.crypto_library_filename(root_dir) - library_subdir = build_tree.crypto_core_directory(root_dir) + library_subdir = build_tree.crypto_core_directory(root_dir, relative = True) crypto_lib_filename = (library_build_dir + '/' + library_subdir + '/' + From 3a0690647e98f40837336ba96dee97ec7b6a3422 Mon Sep 17 00:00:00 2001 From: Thomas Daubney Date: Fri, 1 Dec 2023 18:27:25 +0000 Subject: [PATCH 32/34] Use guess_mbedtls_root in Mbed-TLS-only script Signed-off-by: Thomas Daubney --- tests/scripts/audit-validity-dates.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/scripts/audit-validity-dates.py b/tests/scripts/audit-validity-dates.py index ab09b4a1e695..96b705a281fa 100755 --- a/tests/scripts/audit-validity-dates.py +++ b/tests/scripts/audit-validity-dates.py @@ -265,7 +265,7 @@ def walk_all(self, @staticmethod def find_test_dir(): """Get the relative path for the Mbed TLS test directory.""" - return os.path.relpath(build_tree.guess_project_root() + '/tests') + return os.path.relpath(build_tree.guess_mbedtls_root() + '/tests') class TestDataAuditor(Auditor): From 10769bca9eeafb7b417a76142ee812760b9b82f1 Mon Sep 17 00:00:00 2001 From: Thomas Daubney Date: Fri, 1 Dec 2023 23:47:59 +0000 Subject: [PATCH 33/34] Fix bad whitespace in keyword argument assignment Signed-off-by: Thomas Daubney --- tests/scripts/test_psa_compliance.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/scripts/test_psa_compliance.py b/tests/scripts/test_psa_compliance.py index 57e4fbd5266e..0d56ddfd9740 100755 --- a/tests/scripts/test_psa_compliance.py +++ b/tests/scripts/test_psa_compliance.py @@ -51,7 +51,7 @@ def main(library_build_dir: str): in_tf_psa_crypto_repo = build_tree.looks_like_tf_psa_crypto_root(root_dir) crypto_name = build_tree.crypto_library_filename(root_dir) - library_subdir = build_tree.crypto_core_directory(root_dir, relative = True) + library_subdir = build_tree.crypto_core_directory(root_dir, relative=True) crypto_lib_filename = (library_build_dir + '/' + library_subdir + '/' + From f05b768457dd5088089391d3d350a74a53389ed9 Mon Sep 17 00:00:00 2001 From: Thomas Daubney Date: Fri, 8 Dec 2023 09:47:48 +0000 Subject: [PATCH 34/34] Use existing variable containing full path Signed-off-by: Thomas Daubney --- scripts/generate_driver_wrappers.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/scripts/generate_driver_wrappers.py b/scripts/generate_driver_wrappers.py index edd98a2de480..624ab81df1ad 100755 --- a/scripts/generate_driver_wrappers.py +++ b/scripts/generate_driver_wrappers.py @@ -181,7 +181,7 @@ def main() -> int: crypto_core_directory = build_tree.crypto_core_directory(project_root) output_directory = args.output_directory if args.output_directory is not None else \ - os.path.join(project_root, crypto_core_directory) + crypto_core_directory template_directory = args.template_dir if args.template_dir is not None else \ os.path.join(project_root,