mirror of
https://github.com/pocketpy/pocketpy
synced 2025-10-23 13:00:17 +00:00
optimize compile time
This commit is contained in:
parent
8271d0f8bd
commit
1d32d2b42a
File diff suppressed because one or more lines are too long
29
prebuild.py
29
prebuild.py
@ -1,6 +1,6 @@
|
|||||||
import os
|
import os
|
||||||
|
|
||||||
def generate_python_sources():
|
def get_sources():
|
||||||
sources = {}
|
sources = {}
|
||||||
for file in sorted(os.listdir("python")):
|
for file in sorted(os.listdir("python")):
|
||||||
if not file.endswith(".py"):
|
if not file.endswith(".py"):
|
||||||
@ -17,18 +17,31 @@ def generate_python_sources():
|
|||||||
const_char_array.append('0')
|
const_char_array.append('0')
|
||||||
const_char_array = ','.join(const_char_array)
|
const_char_array = ','.join(const_char_array)
|
||||||
sources[key] = '{' + const_char_array + '}'
|
sources[key] = '{' + const_char_array + '}'
|
||||||
|
return sources
|
||||||
|
|
||||||
header = '''#pragma once
|
sources = get_sources()
|
||||||
|
|
||||||
|
# use LF line endings instead of CRLF
|
||||||
|
with open("include/pocketpy/_generated.h", "wt", encoding='utf-8', newline='\n') as f:
|
||||||
|
data = '''#pragma once
|
||||||
// generated by prebuild.py
|
// generated by prebuild.py
|
||||||
|
|
||||||
namespace pkpy{
|
namespace pkpy{
|
||||||
'''
|
'''
|
||||||
for key in sorted(sources.keys()):
|
for key in sorted(sources.keys()):
|
||||||
value = sources[key]
|
value = sources[key]
|
||||||
header += f' inline const char kPythonLibs_{key}[] = {value};\n'
|
data += f' extern const char kPythonLibs_{key}[];\n'
|
||||||
header += '}\n'
|
data += '} // namespace pkpy\n'
|
||||||
return header
|
f.write(data)
|
||||||
|
|
||||||
# use LF line endings instead of CRLF
|
with open("src/_generated.cpp", "wt", encoding='utf-8', newline='\n') as f:
|
||||||
with open("include/pocketpy/_generated.h", "wt", encoding='utf-8', newline='\n') as f:
|
data = '''// generated by prebuild.py
|
||||||
f.write(generate_python_sources())
|
#include "pocketpy/_generated.h"
|
||||||
|
|
||||||
|
namespace pkpy{
|
||||||
|
'''
|
||||||
|
for key in sorted(sources.keys()):
|
||||||
|
value = sources[key]
|
||||||
|
data += f' const char kPythonLibs_{key}[] = {value};\n'
|
||||||
|
data += '} // namespace pkpy\n'
|
||||||
|
f.write(data)
|
||||||
|
20
src/_generated.cpp
Normal file
20
src/_generated.cpp
Normal file
File diff suppressed because one or more lines are too long
Loading…
x
Reference in New Issue
Block a user