From b03e60a836547f6696974c7972a17998f6e0cfae Mon Sep 17 00:00:00 2001 From: Gilles Peskine Date: Tue, 16 Sep 2025 22:07:19 +0200 Subject: [PATCH] Have --list print a relative path in the common case When the current directory is the project root, have `--list` print relative paths, rather than absolute paths that start with `build_treeguess_project_root()`. 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. Signed-off-by: Gilles Peskine --- scripts/mbedtls_framework/config_checks_generator.py | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/scripts/mbedtls_framework/config_checks_generator.py b/scripts/mbedtls_framework/config_checks_generator.py index 40b720e45..f55c061cb 100644 --- a/scripts/mbedtls_framework/config_checks_generator.py +++ b/scripts/mbedtls_framework/config_checks_generator.py @@ -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')