From 567a8289c46c6d4492fa2d24ffdd6beeb474ad13 Mon Sep 17 00:00:00 2001 From: David Horstmann Date: Tue, 18 Jul 2023 17:03:03 +0100 Subject: [PATCH 1/3] Modify build_tree.py for the PSA Crypto repo When detecting the root dir, look both for PSA Crypto and Mbed TLS directories. Signed-off-by: David Horstmann --- scripts/framework_dev/build_tree.py | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/scripts/framework_dev/build_tree.py b/scripts/framework_dev/build_tree.py index f52b785d9..864085748 100644 --- a/scripts/framework_dev/build_tree.py +++ b/scripts/framework_dev/build_tree.py @@ -19,12 +19,19 @@ import os import inspect +def looks_like_psa_crypto_root(path: str) -> bool: + """Whether the given directory looks like the root of the PSA Crypto source tree.""" + return all(os.path.isdir(os.path.join(path, subdir)) + for subdir in ['include', 'core', 'tests']) def looks_like_mbedtls_root(path: str) -> bool: """Whether the given directory looks like the root of the Mbed TLS source tree.""" return all(os.path.isdir(os.path.join(path, subdir)) for subdir in ['include', 'library', 'programs', 'tests']) +def looks_like_root(path: str) -> bool: + return looks_like_psa_crypto_root(path) or looks_like_mbedtls_root(path) + def check_repo_path(): """ Check that the current working directory is the project root, and throw @@ -42,7 +49,7 @@ def chdir_to_root() -> None: for d in [os.path.curdir, os.path.pardir, os.path.join(os.path.pardir, os.path.pardir)]: - if looks_like_mbedtls_root(d): + if looks_like_root(d): os.chdir(d) return raise Exception('Mbed TLS source tree not found') @@ -62,6 +69,6 @@ def guess_mbedtls_root(): if d in dirs: continue dirs.add(d) - if looks_like_mbedtls_root(d): + if looks_like_root(d): return d raise Exception('Mbed TLS source tree not found') From 7f35b6bcbf250bfc8945a2960cc71b1ce0e5bf5b Mon Sep 17 00:00:00 2001 From: David Horstmann Date: Tue, 18 Jul 2023 17:53:01 +0100 Subject: [PATCH 2/3] Support psa-crypto repo in psa_storage.py Signed-off-by: David Horstmann --- scripts/framework_dev/psa_storage.py | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/scripts/framework_dev/psa_storage.py b/scripts/framework_dev/psa_storage.py index bae99383d..a2e4c74a4 100644 --- a/scripts/framework_dev/psa_storage.py +++ b/scripts/framework_dev/psa_storage.py @@ -27,6 +27,7 @@ from typing import Dict, List, Optional, Set, Union import unittest from . import c_build_helper +from . import build_tree class Expr: @@ -51,13 +52,16 @@ class Expr: def update_cache(self) -> None: """Update `value_cache` for expressions registered in `unknown_values`.""" expressions = sorted(self.unknown_values) + includes = ['include'] + if build_tree.looks_like_psa_crypto_root('.'): + includes.append('drivers/builtin/include') values = c_build_helper.get_c_expression_values( 'unsigned long', '%lu', expressions, header=""" #include """, - include_path=['include']) #type: List[str] + include_path=includes) #type: List[str] for e, v in zip(expressions, values): self.value_cache[e] = int(v, 0) self.unknown_values.clear() From 81e8e304d1eaa139e8fcc11e5dd046b32062af1c Mon Sep 17 00:00:00 2001 From: David Horstmann Date: Tue, 29 Aug 2023 09:48:39 +0100 Subject: [PATCH 3/3] Improve directory coverage in PSA repo detection Check for the 'drivers' and 'programs' directories additionally to the ones that are already there. Signed-off-by: David Horstmann --- scripts/framework_dev/build_tree.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/scripts/framework_dev/build_tree.py b/scripts/framework_dev/build_tree.py index 864085748..b48a27711 100644 --- a/scripts/framework_dev/build_tree.py +++ b/scripts/framework_dev/build_tree.py @@ -22,7 +22,7 @@ import inspect def looks_like_psa_crypto_root(path: str) -> bool: """Whether the given directory looks like the root of the PSA Crypto source tree.""" return all(os.path.isdir(os.path.join(path, subdir)) - for subdir in ['include', 'core', 'tests']) + for subdir in ['include', 'core', 'drivers', 'programs', 'tests']) def looks_like_mbedtls_root(path: str) -> bool: """Whether the given directory looks like the root of the Mbed TLS source tree."""