forked from godotjs/javascript
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathSCsub
74 lines (66 loc) · 3.17 KB
/
SCsub
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
#!/usr/bin/env python
import platform, os, sys
Import('env')
Import('env_modules')
env_module = env_modules.Clone()
JS_ENGINE = 'quickjs'
def open_file(path, mode):
if platform.python_version() > '3':
return open(path, mode, encoding='utf8')
else:
return open(path, mode)
def dump_text_file_to_cpp(file):
source = open_file(file, 'r').read()
lines = source.split('\n')
source = ""
length = len(lines)
for i in range(length):
line = lines[i].replace('"', '\\"')
line = '\t"' + line + '\\n"'
if i < length -1:
line += "\n"
source += line
return source
if JS_ENGINE == 'quickjs':
# generate builtin binding code
import generate_builtin_api
generate_builtin_api.generate_api_json(os.path.join(GetLaunchDir(), "modules", os.path.basename(os.getcwd())))
import quickjs.builtin_binding_generator
quickjs.builtin_binding_generator.generate_builtin_bindings()
# build quickjs source
version = open('quickjs/quickjs/VERSION', 'r').read().split('\n')[0]
env_module.Append(CPPDEFINES={"QUICKJS_CONFIG_VERSION": '"'+ version +'"'})
env_module.Append(CPPDEFINES=["CONFIG_BIGNUM"])
if env_module['target'] != 'release':
env_module.Append(CPPDEFINES={"DUMP_LEAKS": 1})
env_module.Append(CPPDEFINES={"QUICKJS_WITH_DEBUGGER": 1})
env_module.Append(CPPPATH=["quickjs/quickjs"])
env_module.add_source_files(env.modules_sources, 'quickjs/*.cpp')
env_module.add_source_files(env.modules_sources, 'quickjs/quickjs/*.c')
# Binding script to run at engine initializing
with open("misc/godot.binding_script.gen.cpp", "w") as f:
text = '/* THIS FILE IS GENERATED DO NOT EDIT */\n#include "../ecmascript_binder.h"\nString ECMAScriptBinder::BINDING_SCRIPT_CONTENT = \n${source};'
f.write(text.replace('${source}', dump_text_file_to_cpp("misc/binding_script.js")))
sources = [
'register_types.cpp',
'ecmascript_language.cpp',
'ecmascript_instance.cpp',
'ecmascript.cpp',
'misc/godot.binding_script.gen.cpp',
]
if env['tools']:
with open_file("tools/godot.d.ts.gen.cpp", "w") as f:
text = '/* THIS FILE IS GENERATED DO NOT EDIT */\n#include "editor_tools.h"\nString ECMAScriptPlugin::BUILTIN_DECLARATION_TEXT = \n${source};'
f.write(text.replace('${source}', dump_text_file_to_cpp("misc/godot.d.ts")))
with open_file("tools/tsconfig.json.gen.cpp", "w") as f:
text = '/* THIS FILE IS GENERATED DO NOT EDIT */\n#include "editor_tools.h"\nString ECMAScriptPlugin::TSCONFIG_CONTENT = \n${source};'
f.write(text.replace('${source}', dump_text_file_to_cpp("misc/tsconfig.json")))
with open_file("tools/decorators.ts.gen.cpp", "w") as f:
text = '/* THIS FILE IS GENERATED DO NOT EDIT */\n#include "editor_tools.h"\nString ECMAScriptPlugin::TS_DECORATORS_CONTENT = \n${source};'
f.write(text.replace('${source}', dump_text_file_to_cpp("misc/decorators.ts")))
with open_file("tools/package.json.gen.cpp", "w") as f:
text = '/* THIS FILE IS GENERATED DO NOT EDIT */\n#include "editor_tools.h"\nString ECMAScriptPlugin::PACKAGE_JSON_CONTENT = \n${source};'
f.write(text.replace('${source}', dump_text_file_to_cpp("misc/package.json")))
env_module.add_source_files(env.modules_sources, 'tools/*.cpp')
env_module.Append(CPPPATH=["#modules/ECMAScript"])
env_module.add_source_files(env.modules_sources, sources)