mirror of
https://github.com/Mbed-TLS/mbedtls-framework.git
synced 2026-08-25 04:29:53 +00:00
Merge pull request #212 from gilles-peskine-arm/config-checks-generator-framework-fix-check-generated_files
Fix generate_config_checks.py not satisfying make_generated_files --check --root
This commit is contained in:
@@ -24,10 +24,11 @@ class GenerationScript:
|
||||
"""
|
||||
Representation of a script generating a configuration independent file.
|
||||
"""
|
||||
# pylint: disable=too-few-public-methods
|
||||
# pylint: disable=too-few-public-methods,too-many-arguments
|
||||
def __init__(self, script: Path, files: List[Path],
|
||||
output_dir_option: Optional[str] = None,
|
||||
output_file_option: Optional[str] = None):
|
||||
output_file_option: Optional[str] = None,
|
||||
optional: bool = False):
|
||||
# Path from the root of Mbed TLS or TF-PSA-Crypto of the generation script
|
||||
self.script = script
|
||||
|
||||
@@ -49,6 +50,12 @@ class GenerationScript:
|
||||
# positional argument.
|
||||
self.output_file_option = output_file_option
|
||||
|
||||
# Optional files are skipped in --check mode if they don't exist.
|
||||
# This normally shouldn't happen, but it can happen during transition
|
||||
# periods where we're adding a new script or a new file, and a
|
||||
# consuming repository hasn't been updated yet.
|
||||
self.optional = optional
|
||||
|
||||
def get_generation_script_files(generation_script: str):
|
||||
"""
|
||||
Get the list of the default paths of the files that a given script
|
||||
@@ -77,7 +84,8 @@ if os.path.exists("scripts/generate_config_checks.py"):
|
||||
COMMON_GENERATION_SCRIPTS.append(GenerationScript(
|
||||
Path("scripts/generate_config_checks.py"),
|
||||
get_generation_script_files("scripts/generate_config_checks.py"),
|
||||
"", None))
|
||||
output_dir_option="",
|
||||
optional=True))
|
||||
|
||||
if build_tree.looks_like_tf_psa_crypto_root("."):
|
||||
TF_PSA_CRYPTO_GENERATION_SCRIPTS = [
|
||||
@@ -205,6 +213,15 @@ def check_generated_files(generation_scripts: List[GenerationScript], root: Path
|
||||
for generation_script in generation_scripts:
|
||||
for file in generation_script.files:
|
||||
file = root / file
|
||||
if not file.exists():
|
||||
# If the script is just being added, allow its files not
|
||||
# to exist. This can happen, at least, when adding a new
|
||||
# generation script in crypto: until mbedtls is updated,
|
||||
# the files from that script won't be present when
|
||||
# the updated crypto is built from mbedtls development.
|
||||
if generation_script.optional:
|
||||
continue
|
||||
raise Exception(f"Expected generated file does not exist: {file}")
|
||||
bak_file = file.with_name(file.name + ".bak")
|
||||
if bak_file.exists():
|
||||
bak_file.unlink()
|
||||
@@ -222,6 +239,10 @@ def check_generated_files(generation_scripts: List[GenerationScript], root: Path
|
||||
for file in generation_script.files:
|
||||
file = root / file
|
||||
bak_file = file.with_name(file.name + ".bak")
|
||||
if generation_script.optional and not bak_file.exists():
|
||||
# This file is optional and didn't exist before, so
|
||||
# there's nothing to compare to, or clean up.
|
||||
continue
|
||||
if not filecmp.cmp(file, bak_file):
|
||||
ref_file = file.with_name(file.name + ".ref")
|
||||
ref_file = root / ref_file
|
||||
|
||||
@@ -208,6 +208,17 @@ def generate_header_files(branch_data: BranchData,
|
||||
|
||||
def main(branch_data: BranchData) -> None:
|
||||
root = build_tree.guess_project_root()
|
||||
# Is root the current directory? The safe default is no, so compare
|
||||
# the paths, rather than calling `os.samefile()` which can have false
|
||||
# positives and can fail in edge cases.
|
||||
if root == os.getcwd():
|
||||
# Be nice and use a relative path when it's simple to do so.
|
||||
# (build_tree.guess_project_root() should probably do this, actually.)
|
||||
# This is not only nice to humans, but also necessary for
|
||||
# `make_generated_files.py --root DIR --check`: it calls
|
||||
# this script with `--list` and expects a path that is relative
|
||||
# to DIR, not an absolute path that is under the project root.
|
||||
root = os.curdir
|
||||
parser = argparse.ArgumentParser(description=__doc__)
|
||||
parser.add_argument('--list', action='store_true',
|
||||
help='List generated files and exit')
|
||||
|
||||
Reference in New Issue
Block a user