diff --git a/scripts/config.py b/scripts/config.py index 58be3b289..e01b9d541 100755 --- a/scripts/config.py +++ b/scripts/config.py @@ -302,10 +302,22 @@ class ConfigFile(Config): where is "#define ". """ setting = self.settings[name] + value = setting.value + if value is None: + value = '' + # Normally the whitespace to separte the symbol name from the + # value is part of middle, and there's no whitespace for a symbol + # with no value. But if a symbol has been changed from having a + # value to not having one, the whitespace is wrong, so fix it. + if value: + if middle[-1] not in '\t ': + middle += ' ' + else: + middle = middle.rstrip() return ''.join([indent, '' if setting.active else '//', middle, - setting.value]).rstrip() + value]).rstrip() def write_to_stream(self, output): """Write the whole configuration to output.""" diff --git a/tests/scripts/test_config_script.py b/tests/scripts/test_config_script.py index a71b35792..dd3ecbbdb 100755 --- a/tests/scripts/test_config_script.py +++ b/tests/scripts/test_config_script.py @@ -129,6 +129,7 @@ def run_one(options, args): TEST_SYMBOLS = [ 'CUSTOM_OPTION', 'MBEDTLS_AES_C', + 'MBEDTLS_MPI_MAX_SIZE', 'MBEDTLS_NO_UDBL_DIVISION', 'MBEDTLS_PLATFORM_ZEROIZE_ALT', ] @@ -136,6 +137,7 @@ TEST_SYMBOLS = [ ### A list of symbols to test with set with a value. TEST_SYMBOLS_WITH_VALUE = [ 'CUSTOM_VALUE', + 'MBEDTLS_AES_C', 'MBEDTLS_MPI_MAX_SIZE', ] @@ -151,6 +153,7 @@ def run_all(options): for symbol in TEST_SYMBOLS_WITH_VALUE: run_one(options, ['set', symbol, 'value']) run_one(options, ['--force', 'set', symbol, 'value']) + run_one(options, ['unset', symbol]) def main(): """Command line entry point."""