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.
This commit is contained in:
Gilles Peskine 2019-07-29 23:43:20 +02:00
parent 6cf3127527
commit 208e4ec5d3

View file

@ -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:
@ -237,12 +238,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'