Merge pull request #8523 from tom-daubney-arm/modify_check_generated_files_script
Modify check generated files script to work with TF PSA Crypto too
This commit is contained in:
commit
b4362d2cc7
5 changed files with 112 additions and 39 deletions
|
@ -108,17 +108,17 @@ def load_driver(schemas: Dict[str, Any], driver_file: str) -> Any:
|
||||||
return json_data
|
return json_data
|
||||||
|
|
||||||
|
|
||||||
def load_schemas(mbedtls_root: str) -> Dict[str, Any]:
|
def load_schemas(project_root: str) -> Dict[str, Any]:
|
||||||
"""
|
"""
|
||||||
Load schemas map
|
Load schemas map
|
||||||
"""
|
"""
|
||||||
schema_file_paths = {
|
schema_file_paths = {
|
||||||
'transparent': os.path.join(mbedtls_root,
|
'transparent': os.path.join(project_root,
|
||||||
'scripts',
|
'scripts',
|
||||||
'data_files',
|
'data_files',
|
||||||
'driver_jsons',
|
'driver_jsons',
|
||||||
'driver_transparent_schema.json'),
|
'driver_transparent_schema.json'),
|
||||||
'opaque': os.path.join(mbedtls_root,
|
'opaque': os.path.join(project_root,
|
||||||
'scripts',
|
'scripts',
|
||||||
'data_files',
|
'data_files',
|
||||||
'driver_jsons',
|
'driver_jsons',
|
||||||
|
@ -131,13 +131,13 @@ def load_schemas(mbedtls_root: str) -> Dict[str, Any]:
|
||||||
return driver_schema
|
return driver_schema
|
||||||
|
|
||||||
|
|
||||||
def read_driver_descriptions(mbedtls_root: str,
|
def read_driver_descriptions(project_root: str,
|
||||||
json_directory: str,
|
json_directory: str,
|
||||||
jsondriver_list: str) -> list:
|
jsondriver_list: str) -> list:
|
||||||
"""
|
"""
|
||||||
Merge driver JSON files into a single ordered JSON after validation.
|
Merge driver JSON files into a single ordered JSON after validation.
|
||||||
"""
|
"""
|
||||||
driver_schema = load_schemas(mbedtls_root)
|
driver_schema = load_schemas(project_root)
|
||||||
|
|
||||||
with open(file=os.path.join(json_directory, jsondriver_list),
|
with open(file=os.path.join(json_directory, jsondriver_list),
|
||||||
mode='r',
|
mode='r',
|
||||||
|
@ -163,11 +163,11 @@ def main() -> int:
|
||||||
"""
|
"""
|
||||||
Main with command line arguments.
|
Main with command line arguments.
|
||||||
"""
|
"""
|
||||||
def_arg_mbedtls_root = build_tree.guess_mbedtls_root()
|
def_arg_project_root = build_tree.guess_project_root()
|
||||||
|
|
||||||
parser = argparse.ArgumentParser()
|
parser = argparse.ArgumentParser()
|
||||||
parser.add_argument('--mbedtls-root', default=def_arg_mbedtls_root,
|
parser.add_argument('--project-root', default=def_arg_project_root,
|
||||||
help='root directory of mbedtls source code')
|
help='root directory of repo source code')
|
||||||
parser.add_argument('--template-dir',
|
parser.add_argument('--template-dir',
|
||||||
help='directory holding the driver templates')
|
help='directory holding the driver templates')
|
||||||
parser.add_argument('--json-dir',
|
parser.add_argument('--json-dir',
|
||||||
|
@ -176,24 +176,27 @@ def main() -> int:
|
||||||
help='output file\'s location')
|
help='output file\'s location')
|
||||||
args = parser.parse_args()
|
args = parser.parse_args()
|
||||||
|
|
||||||
mbedtls_root = os.path.abspath(args.mbedtls_root)
|
project_root = os.path.abspath(args.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 \
|
output_directory = args.output_directory if args.output_directory is not None else \
|
||||||
os.path.join(mbedtls_root, 'library')
|
crypto_core_directory
|
||||||
|
|
||||||
template_directory = args.template_dir if args.template_dir is not None else \
|
template_directory = args.template_dir if args.template_dir is not None else \
|
||||||
os.path.join(mbedtls_root,
|
os.path.join(project_root,
|
||||||
'scripts',
|
'scripts',
|
||||||
'data_files',
|
'data_files',
|
||||||
'driver_templates')
|
'driver_templates')
|
||||||
json_directory = args.json_dir if args.json_dir is not None else \
|
json_directory = args.json_dir if args.json_dir is not None else \
|
||||||
os.path.join(mbedtls_root,
|
os.path.join(project_root,
|
||||||
'scripts',
|
'scripts',
|
||||||
'data_files',
|
'data_files',
|
||||||
'driver_jsons')
|
'driver_jsons')
|
||||||
|
|
||||||
try:
|
try:
|
||||||
# Read and validate list of driver jsons from driverlist.json
|
# Read and validate list of driver jsons from driverlist.json
|
||||||
merged_driver_json = read_driver_descriptions(mbedtls_root,
|
merged_driver_json = read_driver_descriptions(project_root,
|
||||||
json_directory,
|
json_directory,
|
||||||
'driverlist.json')
|
'driverlist.json')
|
||||||
except DriverReaderException as e:
|
except DriverReaderException as e:
|
||||||
|
|
|
@ -33,7 +33,7 @@ set -eu
|
||||||
# Repository detection
|
# Repository detection
|
||||||
in_mbedtls_build_dir () {
|
in_mbedtls_build_dir () {
|
||||||
test -d library
|
test -d library
|
||||||
}
|
}
|
||||||
|
|
||||||
# Collect stats and build a HTML report.
|
# Collect stats and build a HTML report.
|
||||||
lcov_library_report () {
|
lcov_library_report () {
|
||||||
|
|
|
@ -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,9 +22,40 @@ 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 check_repo_path():
|
def crypto_core_directory(root: Optional[str] = None, relative: Optional[bool] = False) -> str:
|
||||||
"""
|
"""
|
||||||
Check that the current working directory is the project root, and throw
|
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')
|
||||||
|
|
||||||
|
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):
|
||||||
|
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
|
||||||
an exception if not.
|
an exception if not.
|
||||||
"""
|
"""
|
||||||
if not all(os.path.isdir(d) for d in ["include", "library", "tests"]):
|
if not all(os.path.isdir(d) for d in ["include", "library", "tests"]):
|
||||||
|
@ -43,11 +75,10 @@ def chdir_to_root() -> None:
|
||||||
return
|
return
|
||||||
raise Exception('Mbed TLS source tree not found')
|
raise Exception('Mbed TLS source tree not found')
|
||||||
|
|
||||||
|
def guess_project_root():
|
||||||
|
"""Guess project source code directory.
|
||||||
|
|
||||||
def guess_mbedtls_root():
|
Return the first possible project root directory.
|
||||||
"""Guess mbedTLS source code directory.
|
|
||||||
|
|
||||||
Return the first possible mbedTLS root directory
|
|
||||||
"""
|
"""
|
||||||
dirs = set({})
|
dirs = set({})
|
||||||
for frame in inspect.stack():
|
for frame in inspect.stack():
|
||||||
|
@ -60,4 +91,30 @@ def guess_mbedtls_root():
|
||||||
dirs.add(d)
|
dirs.add(d)
|
||||||
if looks_like_root(d):
|
if looks_like_root(d):
|
||||||
return 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')
|
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')
|
||||||
|
|
|
@ -22,8 +22,20 @@ EOF
|
||||||
exit
|
exit
|
||||||
fi
|
fi
|
||||||
|
|
||||||
if [ -d library -a -d include -a -d tests ]; then :; else
|
in_mbedtls_repo () {
|
||||||
echo "Must be run from Mbed TLS root" >&2
|
test -d include -a -d library -a -d programs -a -d tests
|
||||||
|
}
|
||||||
|
|
||||||
|
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
|
||||||
|
library_dir='core'
|
||||||
|
else
|
||||||
|
echo "Must be run from Mbed TLS root or TF-PSA-Crypto root" >&2
|
||||||
exit 1
|
exit 1
|
||||||
fi
|
fi
|
||||||
|
|
||||||
|
@ -114,16 +126,21 @@ check()
|
||||||
# - **/CMakeLists.txt (to (re)build them with cmake)
|
# - **/CMakeLists.txt (to (re)build them with cmake)
|
||||||
# - scripts/make_generated_files.bat (to generate them under Windows)
|
# - scripts/make_generated_files.bat (to generate them under Windows)
|
||||||
|
|
||||||
check scripts/generate_errors.pl library/error.c
|
# These checks are common to Mbed TLS and TF-PSA-Crypto
|
||||||
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
|
|
||||||
check scripts/generate_psa_constants.py programs/psa/psa_constant_names_generated.c
|
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_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_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 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_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
|
||||||
|
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
|
||||||
|
|
|
@ -50,12 +50,8 @@ def main(library_build_dir: str):
|
||||||
|
|
||||||
in_tf_psa_crypto_repo = build_tree.looks_like_tf_psa_crypto_root(root_dir)
|
in_tf_psa_crypto_repo = build_tree.looks_like_tf_psa_crypto_root(root_dir)
|
||||||
|
|
||||||
if in_tf_psa_crypto_repo:
|
crypto_name = build_tree.crypto_library_filename(root_dir)
|
||||||
crypto_name = 'tfpsacrypto'
|
library_subdir = build_tree.crypto_core_directory(root_dir, relative=True)
|
||||||
library_subdir = 'core'
|
|
||||||
else:
|
|
||||||
crypto_name = 'mbedcrypto'
|
|
||||||
library_subdir = 'library'
|
|
||||||
|
|
||||||
crypto_lib_filename = (library_build_dir + '/' +
|
crypto_lib_filename = (library_build_dir + '/' +
|
||||||
library_subdir + '/' +
|
library_subdir + '/' +
|
||||||
|
|
Loading…
Reference in a new issue