@@ -24,10 +24,11 @@ class GenerationScript:
2424 """
2525 Representation of a script generating a configuration independent file.
2626 """
27- # pylint: disable=too-few-public-methods
27+ # pylint: disable=too-few-public-methods,too-many-arguments
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+
5259def 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
8290if build_tree .looks_like_tf_psa_crypto_root ("." ):
8391 TF_PSA_CRYPTO_GENERATION_SCRIPTS = [
@@ -205,6 +213,15 @@ def check_generated_files(generation_scripts: List[GenerationScript], root: Path
205213 for generation_script in generation_scripts :
206214 for file in generation_script .files :
207215 file = root / file
216+ 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
224+ raise Exception (f"Expected generated file does not exist: { file } " )
208225 bak_file = file .with_name (file .name + ".bak" )
209226 if bak_file .exists ():
210227 bak_file .unlink ()
@@ -222,6 +239,10 @@ def check_generated_files(generation_scripts: List[GenerationScript], root: Path
222239 for file in generation_script .files :
223240 file = root / file
224241 bak_file = file .with_name (file .name + ".bak" )
242+ if generation_script .optional and not bak_file .exists ():
243+ # This file is optional and didn't exist before, so
244+ # there's nothing to compare to, or clean up.
245+ continue
225246 if not filecmp .cmp (file , bak_file ):
226247 ref_file = file .with_name (file .name + ".ref" )
227248 ref_file = root / ref_file
0 commit comments