mirror of
https://github.com/Mbed-TLS/mbedtls-framework.git
synced 2026-06-06 05:25:18 +00:00
Add missing type annotations
mypy only checks types in functions that have a return type annotation. In `check_generated_files`, change from returning `None` to returning a boolean, since the function is supposed to check some boolean-valued assertion. So far, the function always returns `True`. In `main`, explicitly return an `int` value as expected by the caller. When calling `check_generated_files`, convert the boolean result into an exit status. Signed-off-by: Gilles Peskine <Gilles.Peskine@arm.com>
This commit is contained in:
@@ -27,7 +27,7 @@ class GenerationScript:
|
||||
def __init__(self, script: Path, files: List[Path],
|
||||
output_dir_option: Optional[str] = None,
|
||||
output_file_option: Optional[str] = None,
|
||||
optional: bool = False):
|
||||
optional: bool = False) -> None:
|
||||
# Path from the root of Mbed TLS or TF-PSA-Crypto of the generation script
|
||||
self.script = script
|
||||
|
||||
@@ -55,7 +55,7 @@ class GenerationScript:
|
||||
# consuming repository hasn't been updated yet.
|
||||
self.optional = optional
|
||||
|
||||
def get_generation_script_files(generation_script: str):
|
||||
def get_generation_script_files(generation_script: str) -> List[Path]:
|
||||
"""
|
||||
Get the list of the default paths of the files that a given script
|
||||
generates. It is assumed that the script supports the "--list" option.
|
||||
@@ -182,7 +182,7 @@ if build_tree.looks_like_mbedtls_root(".") and not build_tree.is_mbedtls_3_6():
|
||||
get_generation_script_files("scripts/generate_visualc_files.pl"),
|
||||
"--directory", None))
|
||||
|
||||
def get_generated_files(generation_scripts: List[GenerationScript]):
|
||||
def get_generated_files(generation_scripts: List[GenerationScript]) -> List[Path]:
|
||||
"""
|
||||
List the generated files in Mbed TLS or TF-PSA-Crypto. The path from root
|
||||
is returned for each generated files.
|
||||
@@ -193,7 +193,7 @@ def get_generated_files(generation_scripts: List[GenerationScript]):
|
||||
|
||||
return files
|
||||
|
||||
def make_generated_files(generation_scripts: List[GenerationScript]):
|
||||
def make_generated_files(generation_scripts: List[GenerationScript]) -> None:
|
||||
"""
|
||||
Generate the configuration independent files in their default location in
|
||||
the Mbed TLS or TF-PSA-Crypto tree.
|
||||
@@ -201,11 +201,13 @@ def make_generated_files(generation_scripts: List[GenerationScript]):
|
||||
for generation_script in generation_scripts:
|
||||
subprocess.run([generation_script.exe, str(generation_script.script)], check=True)
|
||||
|
||||
def check_generated_files(generation_scripts: List[GenerationScript], root: Path):
|
||||
def check_generated_files(generation_scripts: List[GenerationScript],
|
||||
root: Path) -> bool:
|
||||
"""
|
||||
Check that the given root directory contains the generated files as expected/
|
||||
generated by this script.
|
||||
"""
|
||||
ok = True
|
||||
for generation_script in generation_scripts:
|
||||
for file in generation_script.files:
|
||||
file = root / file
|
||||
@@ -248,8 +250,9 @@ def check_generated_files(generation_scripts: List[GenerationScript], root: Path
|
||||
print(f"Generated file {file} not identical to the reference one {ref_file}.")
|
||||
file.unlink()
|
||||
bak_file.rename(file)
|
||||
return ok
|
||||
|
||||
def main():
|
||||
def main() -> int:
|
||||
"""
|
||||
Main function of this program
|
||||
"""
|
||||
@@ -280,10 +283,13 @@ def main():
|
||||
files = get_generated_files(generation_scripts)
|
||||
for file in files:
|
||||
print(str(file))
|
||||
return 0
|
||||
elif args.check:
|
||||
check_generated_files(generation_scripts, Path(args.root or "."))
|
||||
ok = check_generated_files(generation_scripts, Path(args.root or "."))
|
||||
return 0 if ok else 1
|
||||
else:
|
||||
make_generated_files(generation_scripts)
|
||||
return 0 # Any error causes an exception
|
||||
|
||||
if __name__ == "__main__":
|
||||
sys.exit(main())
|
||||
|
||||
Reference in New Issue
Block a user