Index: llvm/utils/gn/build/write_cmake_config.py =================================================================== --- llvm/utils/gn/build/write_cmake_config.py +++ llvm/utils/gn/build/write_cmake_config.py @@ -38,7 +38,7 @@ import os import re import sys - +from distutils.util import strtobool def main(): parser = argparse.ArgumentParser( @@ -69,16 +69,17 @@ def repl(m): key = m.group(1) or m.group(2) unused_values.discard(key) - return values[key] + return values.get(key) in_line = var_re.sub(repl, in_line) if in_line.startswith('#cmakedefine01 '): _, var = in_line.split() - if values[var] == '0': - print('error: "%s=0" used with #cmakedefine01 %s' % (var, var)) - print(" '0' evaluates as truthy with #cmakedefine01") - print(' use "%s=" instead' % var) - return 1 - in_line = '#define %s %d\n' % (var, 1 if values[var] else 0) + bool_value = values.get(var) + try: + bool_value = strtobool(bool_value) + except: + bool_value = None + pass + in_line = '#define %s %d\n' % (var, 1 if bool_value else 0) unused_values.discard(var) elif in_line.startswith('#cmakedefine '): _, var = in_line.split(None, 1) @@ -88,7 +89,7 @@ except: var = var.rstrip() in_line = '#define %s\n' % var - if not values[var]: + if not values.get(var): in_line = '/* #undef %s */\n' % var unused_values.discard(var) out_lines.append(in_line)