import json import os from SCons.Util import WhereIs from platform_methods import get_build_version def run_closure_compiler(target, source, env, for_signature): closure_bin = os.path.join( os.path.dirname(WhereIs("emcc")), "node_modules", ".bin", "google-closure-compiler", ) cmd = [WhereIs("node"), closure_bin] cmd.extend(["--compilation_level", "ADVANCED_OPTIMIZATIONS"]) for allow in ["header", "callback"]: cmd.extend(["--extra_annotation_name", allow]) if env["warnings"] != "none": if env["werror"]: cmd.append("--jscomp_error='*'") else: cmd.append("--jscomp_warning='*'") for f in env["JSEXTERNS"]: cmd.extend(["--externs", f.get_abspath()]) for f in source: cmd.extend(["--js", f.get_abspath()]) cmd.extend(["--js_output_file", target[0].get_abspath()]) return " ".join(cmd) def create_engine_file(env, target, source, externs, threads_enabled): if env["use_closure_compiler"]: return env.BuildJS(target, source, JSEXTERNS=externs) subst_dict = {"___GODOT_THREADS_ENABLED": "true" if threads_enabled else "false"} return env.Substfile(target=target, source=[env.File(s) for s in source], SUBST_DICT=subst_dict) def create_template_zip(env, js, wasm, side): binary_name = "godot.editor" if env.editor_build else "godot" zip_dir = env.Dir(env.GetTemplateZipPath()) in_files = [ js, wasm, "#platform/web/js/libs/audio.worklet.js", "#platform/web/js/libs/audio.position.worklet.js", ] out_files = [ zip_dir.File(binary_name + ".js"), zip_dir.File(binary_name + ".wasm"), zip_dir.File(binary_name + ".audio.worklet.js"), zip_dir.File(binary_name + ".audio.position.worklet.js"), ] # Dynamic linking (extensions) specific. if env["dlink_enabled"]: in_files.append(side) # Side wasm (contains the actual Godot code). out_files.append(zip_dir.File(binary_name + ".side.wasm")) service_worker = "#misc/dist/html/service-worker.js" if env.editor_build: # HTML html = "#misc/dist/html/editor.html" cache = [ "godot.editor.html", "godot.editor.iframe.html", "offline.html", "godot.editor.js", "godot.editor.audio.worklet.js", "godot.editor.audio.position.worklet.js", "logo.svg", "favicon.png", "inter-regular.woff2", "inter-bold.woff2", ] opt_cache = ["godot.editor.wasm"] env["GODOT_WEB_FILESIZES"] = lambda: json.dumps({"godot.editor.wasm": wasm.get_size()}) subst_dict = { "___GODOT_VERSION___": get_build_version(False), "___GODOT_NAME___": "GodotEngine", "___GODOT_CACHE___": json.dumps(cache), "___GODOT_OPT_CACHE___": json.dumps(opt_cache), "___GODOT_OFFLINE_PAGE___": "offline.html", "___GODOT_THREADS_ENABLED___": "true" if env["threads"] else "false", "___GODOT_ENSURE_CROSSORIGIN_ISOLATION_HEADERS___": "true", } subst_dict_sizes = dict(subst_dict) subst_dict_sizes["___GODOT_EDITOR_FILESIZES___"] = "${GODOT_WEB_FILESIZES()}" html = env.Substfile(target="#bin/godot${PROGSUFFIX}.html", source=html, SUBST_DICT=subst_dict_sizes) env.Depends(html, wasm) in_files.append(html) out_files.append(zip_dir.File(binary_name + ".html")) iframe = env.Textfile( target="#bin/godot${PROGSUFFIX}.iframe.html", source='\n