Skip to content

Commit e2c15fb

Browse files
Allow some generated files not to exist
When we add a new generation script in crypto, there is a transition period when mbedtls does not yet know that it has to run this script. For this transition period, we can declare the script as optional, and `make_generated_files.py --check` will not complain if the files are missing. Apply this, right now, to `scripts/generate_config_checks.py`, which is being introduced in TF-PSA-Crypto. Signed-off-by: Gilles Peskine <Gilles.Peskine@arm.com>
1 parent 06f9c84 commit e2c15fb

File tree

1 file changed

+17
-2
lines changed

1 file changed

+17
-2
lines changed

scripts/make_generated_files.py

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,8 @@ class GenerationScript:
2727
# pylint: disable=too-few-public-methods
2828
def __init__(self, script: Path, files: List[Path],
2929
output_dir_option: Optional[str] = None,
30-
output_file_option: Optional[str] = None):
30+
output_file_option: Optional[str] = None,
31+
optional: bool = False):
3132
# Path from the root of Mbed TLS or TF-PSA-Crypto of the generation script
3233
self.script = script
3334

@@ -49,6 +50,12 @@ def __init__(self, script: Path, files: List[Path],
4950
# positional argument.
5051
self.output_file_option = output_file_option
5152

53+
# Optional files are skipped in --check mode if they don't exist.
54+
# This normally shouldn't happen, but it can happen during transition
55+
# periods where we're adding a new script or a new file, and a
56+
# consuming repository hasn't been updated yet.
57+
self.optional = optional
58+
5259
def get_generation_script_files(generation_script: str):
5360
"""
5461
Get the list of the default paths of the files that a given script
@@ -77,7 +84,8 @@ def get_generation_script_files(generation_script: str):
7784
COMMON_GENERATION_SCRIPTS.append(GenerationScript(
7885
Path("scripts/generate_config_checks.py"),
7986
get_generation_script_files("scripts/generate_config_checks.py"),
80-
"", None))
87+
output_dir_option="",
88+
optional=True))
8189

8290
if build_tree.looks_like_tf_psa_crypto_root("."):
8391
TF_PSA_CRYPTO_GENERATION_SCRIPTS = [
@@ -206,6 +214,13 @@ def check_generated_files(generation_scripts: List[GenerationScript], root: Path
206214
for file in generation_script.files:
207215
file = root / file
208216
if not file.exists():
217+
# If the script is just being added, allow its files not
218+
# to exist. This can happen, at least, when adding a new
219+
# generation script in crypto: until mbedtls is updated,
220+
# the files from that script won't be present when
221+
# the updated crypto is built from mbedtls development.
222+
if generation_script.optional:
223+
continue
209224
raise Exception(f"Expected generated file does not exist: {file}")
210225
bak_file = file.with_name(file.name + ".bak")
211226
if bak_file.exists():

0 commit comments

Comments
 (0)