Improve implementation of crypto_core_directory

Signed-off-by: Thomas Daubney <thomas.daubney@arm.com>
This commit is contained in:
Thomas Daubney 2023-11-22 17:00:34 +00:00
parent 772056ccea
commit d35b94b662

View file

@ -7,6 +7,7 @@
import os import os
import inspect import inspect
from typing import Optional
def looks_like_tf_psa_crypto_root(path: str) -> bool: def looks_like_tf_psa_crypto_root(path: str) -> bool:
"""Whether the given directory looks like the root of the PSA Crypto source tree.""" """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: def looks_like_root(path: str) -> bool:
return looks_like_tf_psa_crypto_root(path) or looks_like_mbedtls_root(path) return looks_like_tf_psa_crypto_root(path) or looks_like_mbedtls_root(path)
def crypto_core_directory() -> str: def crypto_core_directory(root: Optional[str] = None) -> str:
if looks_like_tf_psa_crypto_root(os.path.curdir): if root is None:
root = guess_mbedtls_root()
if looks_like_tf_psa_crypto_root(root):
return "core" return "core"
elif looks_like_mbedtls_root(os.path.curdir): elif looks_like_mbedtls_root(root):
return "library" return "library"
else: else:
raise Exception('Neither Mbed TLS nor TF-PSA-Crypto source tree found') raise Exception('Neither Mbed TLS nor TF-PSA-Crypto source tree found')