electron/build/generate_node_defines.py
Charles Kerr 8a67e77f03
build: fix python warnings "SyntaxWarning: invalid escape sequence '\w'" (#44650)
* fix: SyntaxWarning: invalid escape sequence '\w'

* chore: remove some unused imports

* fix: E711 warning 'Comparison to  should be '
2024-11-14 12:27:20 +01:00

34 lines
915 B
Python
Executable file

import os
import re
import sys
DEFINE_EXTRACT_REGEX = re.compile(r'^ *# *define (\w*)', re.MULTILINE)
def main(out_dir, headers):
defines = []
for filename in headers:
with open(filename, 'r') as f:
content = f.read()
defines += read_defines(content)
push_and_undef = ''
for define in defines:
push_and_undef += '#pragma push_macro("%s")\n' % define
push_and_undef += '#undef %s\n' % define
with open(os.path.join(out_dir, 'push_and_undef_node_defines.h'), 'w') as o:
o.write(push_and_undef)
pop = ''
for define in defines:
pop += '#pragma pop_macro("%s")\n' % define
with open(os.path.join(out_dir, 'pop_node_defines.h'), 'w') as o:
o.write(pop)
def read_defines(content):
defines = []
for match in DEFINE_EXTRACT_REGEX.finditer(content):
defines.append(match.group(1))
return defines
if __name__ == '__main__':
main(sys.argv[1], sys.argv[2:])