0.2.0-dev Download ZIP
158 lines ·5.7 KB Raw
| 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 allow in ["header", "callback"]: |
| 19 | cmd.extend(["--extra_annotation_name", allow]) |
| 20 | if env["warnings"] != "none": |
| 21 | if env["werror"]: |
| 22 | cmd.append("--jscomp_error='*'") |
| 23 | else: |
| 24 | cmd.append("--jscomp_warning='*'") |
| 25 | for f in env["JSEXTERNS"]: |
| 26 | cmd.extend(["--externs", f.get_abspath()]) |
| 27 | for f in source: |
| 28 | cmd.extend(["--js", f.get_abspath()]) |
| 29 | cmd.extend(["--js_output_file", target[0].get_abspath()]) |
| 30 | return " ".join(cmd) |
| 31 | |
| 32 | |
| 33 | def create_engine_file(env, target, source, externs, threads_enabled): |
| 34 | if env["use_closure_compiler"]: |
| 35 | return env.BuildJS(target, source, JSEXTERNS=externs) |
| 36 | subst_dict = {"___GODOT_THREADS_ENABLED": "true" if threads_enabled else "false"} |
| 37 | return env.Substfile(target=target, source=[env.File(s) for s in source], SUBST_DICT=subst_dict) |
| 38 | |
| 39 | |
| 40 | def create_template_zip(env, js, wasm, side): |
| 41 | binary_name = "godot.editor" if env.editor_build else "godot" |
| 42 | zip_dir = env.Dir(env.GetTemplateZipPath()) |
| 43 | in_files = [ |
| 44 | js, |
| 45 | wasm, |
| 46 | "#platform/web/js/libs/audio.worklet.js", |
| 47 | "#platform/web/js/libs/audio.position.worklet.js", |
| 48 | ] |
| 49 | out_files = [ |
| 50 | zip_dir.File(binary_name + ".js"), |
| 51 | zip_dir.File(binary_name + ".wasm"), |
| 52 | zip_dir.File(binary_name + ".audio.worklet.js"), |
| 53 | zip_dir.File(binary_name + ".audio.position.worklet.js"), |
| 54 | ] |
| 55 | # Dynamic linking (extensions) specific. |
| 56 | if env["dlink_enabled"]: |
| 57 | in_files.append(side) # Side wasm (contains the actual Godot code). |
| 58 | out_files.append(zip_dir.File(binary_name + ".side.wasm")) |
| 59 | |
| 60 | service_worker = "#misc/dist/html/service-worker.js" |
| 61 | if env.editor_build: |
| 62 | # HTML |
| 63 | html = "#misc/dist/html/editor.html" |
| 64 | cache = [ |
| 65 | "godot.editor.html", |
| 66 | "godot.editor.iframe.html", |
| 67 | "offline.html", |
| 68 | "godot.editor.js", |
| 69 | "godot.editor.audio.worklet.js", |
| 70 | "godot.editor.audio.position.worklet.js", |
| 71 | "logo.svg", |
| 72 | "favicon.png", |
| 73 | "inter-regular.woff2", |
| 74 | "inter-bold.woff2", |
| 75 | ] |
| 76 | opt_cache = ["godot.editor.wasm"] |
| 77 | |
| 78 | env["GODOT_WEB_FILESIZES"] = lambda: json.dumps({"godot.editor.wasm": wasm.get_size()}) |
| 79 | subst_dict = { |
| 80 | "___GODOT_VERSION___": get_build_version(False), |
| 81 | "___GODOT_NAME___": "GodotEngine", |
| 82 | "___GODOT_CACHE___": json.dumps(cache), |
| 83 | "___GODOT_OPT_CACHE___": json.dumps(opt_cache), |
| 84 | "___GODOT_OFFLINE_PAGE___": "offline.html", |
| 85 | "___GODOT_THREADS_ENABLED___": "true" if env["threads"] else "false", |
| 86 | "___GODOT_ENSURE_CROSSORIGIN_ISOLATION_HEADERS___": "true", |
| 87 | } |
| 88 | subst_dict_sizes = dict(subst_dict) |
| 89 | subst_dict_sizes["___GODOT_EDITOR_FILESIZES___"] = "${GODOT_WEB_FILESIZES()}" |
| 90 | html = env.Substfile(target="#bin/godot${PROGSUFFIX}.html", source=html, SUBST_DICT=subst_dict_sizes) |
| 91 | env.Depends(html, wasm) |
| 92 | in_files.append(html) |
| 93 | out_files.append(zip_dir.File(binary_name + ".html")) |
| 94 | iframe = env.Textfile( |
| 95 | target="#bin/godot${PROGSUFFIX}.iframe.html", |
| 96 | source='<!DOCTYPE html>\n<html lang="en"><head><title></title></head></html>', |
| 97 | ) |
| 98 | in_files.append(iframe) |
| 99 | out_files.append(zip_dir.File(binary_name + ".iframe.html")) |
| 100 | # And logo/favicon |
| 101 | in_files.append("#misc/dist/html/logo.svg") |
| 102 | out_files.append(zip_dir.File("logo.svg")) |
| 103 | in_files.append("#misc/logo/icon.png") |
| 104 | out_files.append(zip_dir.File("favicon.png")) |
| 105 | # PWA |
| 106 | service_worker = env.Substfile( |
| 107 | target="#bin/godot${PROGSUFFIX}.service.worker.js", |
| 108 | source=service_worker, |
| 109 | SUBST_DICT=subst_dict, |
| 110 | ) |
| 111 | in_files.append(service_worker) |
| 112 | out_files.append(zip_dir.File("service.worker.js")) |
| 113 | in_files.append("#misc/dist/html/manifest.json") |
| 114 | out_files.append(zip_dir.File("manifest.json")) |
| 115 | in_files.append("#misc/dist/html/offline.html") |
| 116 | out_files.append(zip_dir.File("offline.html")) |
| 117 | in_files.append("#thirdparty/fonts/Inter_Regular.woff2") |
| 118 | out_files.append(zip_dir.File("inter-regular.woff2")) |
| 119 | in_files.append("#thirdparty/fonts/Inter_Bold.woff2") |
| 120 | out_files.append(zip_dir.File("inter-bold.woff2")) |
| 121 | else: |
| 122 | # HTML |
| 123 | in_files.append("#misc/dist/html/full-size.html") |
| 124 | out_files.append(zip_dir.File(binary_name + ".html")) |
| 125 | in_files.append(service_worker) |
| 126 | out_files.append(zip_dir.File(binary_name + ".service.worker.js")) |
| 127 | in_files.append("#misc/dist/html/offline-export.html") |
| 128 | out_files.append(zip_dir.File("godot.offline.html")) |
| 129 | |
| 130 | zip_files = env.NoCache(env.InstallAs(out_files, in_files)) |
| 131 | env.NoCache( |
| 132 | env.Zip( |
| 133 | "#bin/godot", |
| 134 | zip_files, |
| 135 | ZIPROOT=zip_dir, |
| 136 | ZIPSUFFIX="${PROGSUFFIX}${ZIPSUFFIX}", |
| 137 | ) |
| 138 | ) |
| 139 | |
| 140 | |
| 141 | def get_template_zip_path(env): |
| 142 | return "#bin/.web_zip" |
| 143 | |
| 144 | |
| 145 | def add_js_libraries(env, libraries): |
| 146 | env.Append(JS_LIBS=env.File(libraries)) |
| 147 | |
| 148 | |
| 149 | def add_js_pre(env, js_pre): |
| 150 | env.Append(JS_PRE=env.File(js_pre)) |
| 151 | |
| 152 | |
| 153 | def add_js_post(env, js_post): |
| 154 | env.Append(JS_POST=env.File(js_post)) |
| 155 | |
| 156 | |
| 157 | def add_js_externs(env, externs): |
| 158 | env.Append(JS_EXTERNS=env.File(externs)) |