[PATCH] D110019: [gn build] improve write_cmake_config to be truthy and exception friendly
yaozhongxiao via Phabricator via llvm-commits
llvm-commits at lists.llvm.org
Sat Sep 18 02:26:26 PDT 2021
zhongxiao.yzx updated this revision to Diff 373399.
zhongxiao.yzx added a comment.
- reorder the import statement
- remove unused pass statement of try-except
CHANGES SINCE LAST ACTION
https://reviews.llvm.org/D110019/new/
https://reviews.llvm.org/D110019
Files:
llvm/utils/gn/build/write_cmake_config.py
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
@@ -33,13 +33,13 @@
"""
from __future__ import print_function
+from distutils.util import strtobool
import argparse
import os
import re
import sys
-
def main():
parser = argparse.ArgumentParser(
epilog=__doc__,
@@ -69,16 +69,16 @@
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
+ 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 +88,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)
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D110019.373399.patch
Type: text/x-patch
Size: 1833 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20210918/b055ae90/attachment.bin>
More information about the llvm-commits
mailing list