From 812f185bc8114b32bedd0937cf7e2e0eb61213a2 Mon Sep 17 00:00:00 2001 From: Gilles Peskine Date: Mon, 29 Jul 2019 23:43:20 +0200 Subject: [PATCH] Also search config.h near the script By default, this script looks for include/mbedtls/config.h relative to the current directory. This allows running config.py from outside the build tree. To support out-of-tree builds where config.h and config.py are in the source tree and the current directory is in the build tree, also try DIRECTORY_CONTAINING_SCRIPT/../include/mbedtls/config.h, and the equivalent with symbolic links traversed. --- scripts/config.py | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/scripts/config.py b/scripts/config.py index 9d8184343..8fd335a49 100755 --- a/scripts/config.py +++ b/scripts/config.py @@ -24,6 +24,7 @@ Basic usage, to read the Mbed TLS or Mbed Crypto configuration: ## ## This file is part of Mbed TLS (https://tls.mbed.org) +import os import re class Setting: @@ -230,12 +231,20 @@ class ConfigFile(Config): and modify the configuration. """ - default_path = 'include/mbedtls/config.h' + _path_in_tree = 'include/mbedtls/config.h' + default_path = [_path_in_tree, + os.path.join(os.path.dirname(__file__), + os.pardir, + _path_in_tree), + os.path.join(os.path.dirname(os.path.abspath(os.path.dirname(__file__))), + _path_in_tree)] def __init__(self, filename=None): """Read the Mbed TLS configuration file.""" if filename is None: - filename = self.default_path + for filename in self.default_path: + if os.path.lexists(filename): + break super().__init__() self.filename = filename self.current_section = 'header'