| 1 |
import json |
| 2 |
import os |
| 3 |
|
| 4 |
from SCons.Util import WhereIs |
| 5 |
|
| 6 |
from platform_methods import get_build_version |
| 7 |
|
| 8 |
|
| 9 |
def run_closure_compiler(target, source, env, for_signature): |
| 10 |
closure_bin = os.path.join( |
| 11 |
os.path.dirname(WhereIs("emcc")), |
| 12 |
"node_modules", |
| 13 |
".bin", |
| 14 |
"google-closure-compiler", |
| 15 |
) |
| 16 |
cmd = [WhereIs("node"), closure_bin] |
| 17 |
cmd.extend(["--compilation_level", "ADVANCED_OPTIMIZATIONS"]) |
| 18 |
for f in env["JSEXTERNS"]: |
| 19 |
cmd.extend(["--externs", f.get_abspath()]) |
| 20 |
for f in source: |
| 21 |
cmd.extend(["--js", f.get_abspath()]) |
| 22 |
cmd.extend(["--js_output_file", target[0].get_abspath()]) |
| 23 |
return " ".join(cmd) |
| 24 |
|
| 25 |
|
| 26 |
def create_engine_file(env, target, source, externs, threads_enabled): |
| 27 |
if env["use_closure_compiler"]: |
| 28 |
return env.BuildJS(target, source, JSEXTERNS=externs) |
| 29 |
subst_dict = {"___GODOT_THREADS_ENABLED": "true" if threads_enabled else "false"} |
| 30 |
return env.Substfile(target=target, source=[env.File(s) for s in source], SUBST_DICT=subst_dict) |
| 31 |
|
| 32 |
|
| 33 |
def create_template_zip(env, js, wasm, side): |
| 34 |
binary_name = "godot.editor" if env.editor_build else "godot" |
| 35 |
zip_dir = env.Dir(env.GetTemplateZipPath()) |
| 36 |
in_files = [ |
| 37 |
js, |
| 38 |
wasm, |
| 39 |
"#platform/web/js/libs/audio.worklet.js", |
| 40 |
"#platform/web/js/libs/audio.position.worklet.js", |
| 41 |
] |
| 42 |
out_files = [ |
| 43 |
zip_dir.File(binary_name + ".js"), |
| 44 |
zip_dir.File(binary_name + ".wasm"), |
| 45 |
zip_dir.File(binary_name + ".audio.worklet.js"), |
| 46 |
zip_dir.File(binary_name + ".audio.position.worklet.js"), |
| 47 |
] |
| 48 |
|
| 49 |
if env["dlink_enabled"]: |
| 50 |
in_files.append(side) |
| 51 |
out_files.append(zip_dir.File(binary_name + ".side.wasm")) |
| 52 |
|
| 53 |
service_worker = "#misc/dist/html/service-worker.js" |
| 54 |
if env.editor_build: |
| 55 |
|
| 56 |
html = "#misc/dist/html/editor.html" |
| 57 |
cache = [ |
| 58 |
"godot.editor.html", |
| 59 |
"offline.html", |
| 60 |
"godot.editor.js", |
| 61 |
"godot.editor.audio.worklet.js", |
| 62 |
"godot.editor.audio.position.worklet.js", |
| 63 |
"logo.svg", |
| 64 |
"favicon.png", |
| 65 |
] |
| 66 |
opt_cache = ["godot.editor.wasm"] |
| 67 |
subst_dict = { |
| 68 |
"___GODOT_VERSION___": get_build_version(False), |
| 69 |
"___GODOT_NAME___": "GodotEngine", |
| 70 |
"___GODOT_CACHE___": json.dumps(cache), |
| 71 |
"___GODOT_OPT_CACHE___": json.dumps(opt_cache), |
| 72 |
"___GODOT_OFFLINE_PAGE___": "offline.html", |
| 73 |
"___GODOT_THREADS_ENABLED___": "true" if env["threads"] else "false", |
| 74 |
"___GODOT_ENSURE_CROSSORIGIN_ISOLATION_HEADERS___": "true", |
| 75 |
} |
| 76 |
html = env.Substfile(target="#bin/godot${PROGSUFFIX}.html", source=html, SUBST_DICT=subst_dict) |
| 77 |
in_files.append(html) |
| 78 |
out_files.append(zip_dir.File(binary_name + ".html")) |
| 79 |
|
| 80 |
in_files.append("#misc/dist/html/logo.svg") |
| 81 |
out_files.append(zip_dir.File("logo.svg")) |
| 82 |
in_files.append("#icon.png") |
| 83 |
out_files.append(zip_dir.File("favicon.png")) |
| 84 |
|
| 85 |
service_worker = env.Substfile( |
| 86 |
target="#bin/godot${PROGSUFFIX}.service.worker.js", |
| 87 |
source=service_worker, |
| 88 |
SUBST_DICT=subst_dict, |
| 89 |
) |
| 90 |
in_files.append(service_worker) |
| 91 |
out_files.append(zip_dir.File("service.worker.js")) |
| 92 |
in_files.append("#misc/dist/html/manifest.json") |
| 93 |
out_files.append(zip_dir.File("manifest.json")) |
| 94 |
in_files.append("#misc/dist/html/offline.html") |
| 95 |
out_files.append(zip_dir.File("offline.html")) |
| 96 |
else: |
| 97 |
|
| 98 |
in_files.append("#misc/dist/html/full-size.html") |
| 99 |
out_files.append(zip_dir.File(binary_name + ".html")) |
| 100 |
in_files.append(service_worker) |
| 101 |
out_files.append(zip_dir.File(binary_name + ".service.worker.js")) |
| 102 |
in_files.append("#misc/dist/html/offline-export.html") |
| 103 |
out_files.append(zip_dir.File("godot.offline.html")) |
| 104 |
|
| 105 |
zip_files = env.NoCache(env.InstallAs(out_files, in_files)) |
| 106 |
env.NoCache( |
| 107 |
env.Zip( |
| 108 |
"#bin/godot", |
| 109 |
zip_files, |
| 110 |
ZIPROOT=zip_dir, |
| 111 |
ZIPSUFFIX="${PROGSUFFIX}${ZIPSUFFIX}", |
| 112 |
) |
| 113 |
) |
| 114 |
|
| 115 |
|
| 116 |
def get_template_zip_path(env): |
| 117 |
return "#bin/.web_zip" |
| 118 |
|
| 119 |
|
| 120 |
def add_js_libraries(env, libraries): |
| 121 |
env.Append(JS_LIBS=env.File(libraries)) |
| 122 |
|
| 123 |
|
| 124 |
def add_js_pre(env, js_pre): |
| 125 |
env.Append(JS_PRE=env.File(js_pre)) |
| 126 |
|
| 127 |
|
| 128 |
def add_js_post(env, js_post): |
| 129 |
env.Append(JS_POST=env.File(js_post)) |
| 130 |
|
| 131 |
|
| 132 |
def add_js_externs(env, externs): |
| 133 |
env.Append(JS_EXTERNS=env.File(externs)) |