electron/build/generate_node_defines.py
trop[bot] e95e6fac0d
build: fix python warnings "SyntaxWarning: invalid escape sequence '\w'" (#44660)
* fix: SyntaxWarning: invalid escape sequence '\w'

Co-authored-by: Charles Kerr <charles@charleskerr.com>

* chore: remove some unused imports

Co-authored-by: Charles Kerr <charles@charleskerr.com>

* fix: E711 warning 'Comparison to should be '

Co-authored-by: Charles Kerr <charles@charleskerr.com>

---------

Co-authored-by: trop[bot] <37223003+trop[bot]@users.noreply.github.com>
Co-authored-by: Charles Kerr <charles@charleskerr.com>
2024-11-14 07:28:08 -06: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:])