Skip to content

Commit 45290bc

Browse files
Make *_config_checks_*.h automatically generated files
For the time being, only do this if the generation script `scripts/generate_config_checks.py` exists in the consuming repository. This way we can use this framework revision before the scripts are added to the consuming repositories. Signed-off-by: Gilles Peskine <Gilles.Peskine@arm.com>
1 parent bc55f06 commit 45290bc

File tree

2 files changed

+35
-10
lines changed

2 files changed

+35
-10
lines changed

scripts/make_generated_files.py

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
"""
1111
import argparse
1212
import filecmp
13+
import os
1314
import shutil
1415
import subprocess
1516
import sys
@@ -66,6 +67,18 @@ def get_generation_script_files(generation_script: str):
6667

6768
return files
6869

70+
COMMON_GENERATION_SCRIPTS = [
71+
]
72+
73+
# Once the script has been added to both Mbed TLS and TF-PSA-Crypto,
74+
# we can include this unconditionally.
75+
# https://github.com/Mbed-TLS/mbedtls/issues/10305
76+
if os.path.exists("scripts/generate_config_checks.py"):
77+
COMMON_GENERATION_SCRIPTS.append(GenerationScript(
78+
Path("scripts/generate_config_checks.py"),
79+
get_generation_script_files("scripts/generate_config_checks.py"),
80+
"", None))
81+
6982
if build_tree.looks_like_tf_psa_crypto_root("."):
7083
TF_PSA_CRYPTO_GENERATION_SCRIPTS = [
7184
GenerationScript(
@@ -244,6 +257,7 @@ def main():
244257
generation_scripts = MBEDTLS_GENERATION_SCRIPTS
245258
else:
246259
raise Exception("No support for Mbed TLS 3.6")
260+
generation_scripts += COMMON_GENERATION_SCRIPTS
247261

248262
if args.list:
249263
files = get_generated_files(generation_scripts)

scripts/mbedtls_framework/config_checks_generator.py

Lines changed: 21 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -189,6 +189,16 @@ def __init__(self, branch_data: BranchData, position: Position) -> None:
189189
self.prefix = branch_data.project_cpp_prefix + '_CONFIG_CHECK'
190190
self.bypass_checks = self.prefix + '_BYPASS'
191191

192+
@staticmethod
193+
def filename(root: str,
194+
branch_data: BranchData,
195+
position: Position) -> str:
196+
"""The file name for this header, under the given root."""
197+
suffix = f'config_check_{position.name.lower()}.h'
198+
return os.path.join(root,
199+
branch_data.header_directory,
200+
branch_data.header_prefix + suffix)
201+
192202
def write_stanza(self, out: typing_util.Writable, checker: Checker) -> None:
193203
"""Write the part of the output corresponding to one config option."""
194204
code = checker.code(self.position, self.prefix)
@@ -199,8 +209,9 @@ def write_content(self, out: typing_util.Writable) -> None:
199209
for checker in self.branch_data.checkers:
200210
self.write_stanza(out, checker)
201211

202-
def write(self, filename: str) -> None:
212+
def write(self, root: str) -> None:
203213
"""Write the whole output file."""
214+
filename = self.filename(root, self.branch_data, self.position)
204215
with open(filename, 'w') as out:
205216
out.write(f"""\
206217
/* {os.path.basename(filename)}: checks before including the user configuration file. */
@@ -223,19 +234,19 @@ def write(self, filename: str) -> None:
223234
def generate_header_files(root: str, branch_data: BranchData) -> None:
224235
"""Generate the header files to include before and after *config.h."""
225236
before_generator = HeaderGenerator(branch_data, Position.BEFORE)
226-
before_generator.write(os.path.join(root,
227-
branch_data.header_directory,
228-
branch_data.header_prefix +
229-
'config_check_before.h'))
237+
before_generator.write(root)
230238
after_generator = HeaderGenerator(branch_data, Position.AFTER)
231-
after_generator.write(os.path.join(root,
232-
branch_data.header_directory,
233-
branch_data.header_prefix +
234-
'config_check_after.h'))
239+
after_generator.write(root)
235240

236241

237242
def main(branch_data: BranchData) -> None:
238243
parser = argparse.ArgumentParser(description=__doc__)
239-
_options = parser.parse_args()
244+
parser.add_argument('--list', action='store_true',
245+
help='List generated files and exit')
246+
options = parser.parse_args()
240247
root = build_tree.guess_project_root()
248+
if options.list:
249+
for position in [Position.BEFORE, Position.AFTER]:
250+
print(HeaderGenerator.filename(root, branch_data, position))
251+
return
241252
generate_header_files(root, branch_data)

0 commit comments

Comments
 (0)