Skip to content
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

Modify check generated files script to work with TF PSA Crypto too #8523

Merged
Show file tree
Hide file tree
Changes from 14 commits
Commits
Show all changes
34 commits
Select commit Hold shift + click to select a range
b4f1ee0
Remove superfluous leading whitespace
tom-daubney-arm Nov 13, 2023
c9f8386
Modify check-generated-files.sh to work in both repos
tom-daubney-arm Nov 13, 2023
b10cc7a
Modify generate_driver_wrappers.py to work in both repos
tom-daubney-arm Nov 14, 2023
d3f8443
Further modify check-generated-files.sh
tom-daubney-arm Nov 14, 2023
0bb761c
Remove further extraneous whitespace in lcov script
tom-daubney-arm Nov 14, 2023
c1750bb
Apply correct license to generate_driver_wrappers.py
tom-daubney-arm Nov 14, 2023
e58128e
Refactor repository detection
tom-daubney-arm Nov 14, 2023
d289b8b
Stylise TF-PSA-Crypto correctly
tom-daubney-arm Nov 14, 2023
0eb2dc1
Call the right function
tom-daubney-arm Nov 14, 2023
4291bc2
Remove trailing whitespace
tom-daubney-arm Nov 14, 2023
5556f90
Rename variables in script
tom-daubney-arm Nov 15, 2023
13ecb69
Introduce function to return library/core directory
tom-daubney-arm Nov 16, 2023
79cae20
Remove useless line
tom-daubney-arm Nov 22, 2023
b42c50b
Make use of new crypto_core_directory function
tom-daubney-arm Nov 22, 2023
772056c
Replace repo_root with project_root
tom-daubney-arm Nov 22, 2023
d35b94b
Improve implementation of crypto_core_directory
tom-daubney-arm Nov 22, 2023
755d321
Rename guess_mbedtls_root to guess_project_root
tom-daubney-arm Nov 22, 2023
d0c3076
Make use of crypto_core_directory function in script
tom-daubney-arm Nov 23, 2023
8932404
Introduce project_crypto_name in build_tree.py
tom-daubney-arm Nov 23, 2023
beec452
Use os.path.join in crypto_core_directory
tom-daubney-arm Nov 24, 2023
cdbf2fd
Add documentation for new public functions
tom-daubney-arm Nov 24, 2023
fc60e9b
Make function calls consistent
tom-daubney-arm Nov 24, 2023
6130a61
Remove unused variable
tom-daubney-arm Nov 24, 2023
e8f3789
Revert change that removed in_tf_psa_crypto_repo variable
tom-daubney-arm Nov 24, 2023
08c6dc4
Rename project_crypto_name
tom-daubney-arm Nov 30, 2023
46588de
Improve documentation of crypto_core_directory
tom-daubney-arm Nov 30, 2023
56bee03
Rename variable for better clarity
tom-daubney-arm Nov 30, 2023
d1f2934
Introduce guess_mbedtls_root
tom-daubney-arm Nov 30, 2023
db80b23
Introduce guess_tf_psa_crypto_root
tom-daubney-arm Nov 30, 2023
99030e2
Remove trailing whitespace
tom-daubney-arm Dec 1, 2023
04c446c
Modify crypto_core_directory to also return a relative path
tom-daubney-arm Dec 1, 2023
3a06906
Use guess_mbedtls_root in Mbed-TLS-only script
tom-daubney-arm Dec 1, 2023
10769bc
Fix bad whitespace in keyword argument assignment
tom-daubney-arm Dec 1, 2023
f05b768
Use existing variable containing full path
tom-daubney-arm Dec 8, 2023
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions scripts/generate_driver_wrappers.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
ronald-cron-arm marked this conversation as resolved.
Show resolved Hide resolved

template_directory = args.template_dir if args.template_dir is not None else \
os.path.join(project_root,
Expand Down
2 changes: 1 addition & 1 deletion scripts/generate_ssl_debug_helpers.py
Original file line number Diff line number Diff line change
Expand Up @@ -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())

Expand Down
50 changes: 43 additions & 7 deletions scripts/mbedtls_dev/build_tree.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,17 +22,29 @@ 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):
return "core"
if relative:
return "core"
return os.path.join(root, "core")
elif looks_like_mbedtls_root(root):
return "library"
if relative:
return "library"
return os.path.join(root, "library")
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()
if looks_like_tf_psa_crypto_root(root):
Expand All @@ -43,8 +55,7 @@ def project_crypto_name(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"]):
Expand All @@ -64,7 +75,6 @@ def chdir_to_root() -> None:
return
raise Exception('Mbed TLS source tree not found')


def guess_project_root():
"""Guess project source code directory.

Expand All @@ -82,3 +92,29 @@ 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
Comment on lines +103 to +105
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This won't find the mbedtls root if called from a TF-PSA-Crypto submodule of mbedtls. That's ok for now, we'll just have to improve it later.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the heads up, and for the review.

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')
2 changes: 1 addition & 1 deletion tests/scripts/audit-validity-dates.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down
5 changes: 2 additions & 3 deletions tests/scripts/test_psa_compliance.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
gilles-peskine-arm marked this conversation as resolved.
Show resolved Hide resolved

crypto_name = build_tree.project_crypto_name()

library_subdir = build_tree.crypto_core_directory()
crypto_name = build_tree.crypto_library_filename(root_dir)
library_subdir = build_tree.crypto_core_directory(root_dir, relative=True)

crypto_lib_filename = (library_build_dir + '/' +
library_subdir + '/' +
Expand Down