File: emscripten_helpers.py

package info (click to toggle)
godot 3.2.3-stable-1
  • links: PTS, VCS
  • area: main
  • in suites: bookworm, bullseye
  • size: 121,308 kB
  • sloc: cpp: 804,285; ansic: 597,434; xml: 77,823; asm: 17,127; cs: 13,535; lisp: 12,017; python: 9,376; java: 7,474; sh: 973; javascript: 659; perl: 264; pascal: 203; objc: 116; makefile: 105
file content (38 lines) | stat: -rw-r--r-- 1,524 bytes parent folder | download
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
import os


def parse_config():
    em_config_file = os.getenv("EM_CONFIG") or os.path.expanduser("~/.emscripten")
    if not os.path.exists(em_config_file):
        raise RuntimeError("Emscripten configuration file '%s' does not exist" % em_config_file)

    normalized = {}
    em_config = {}
    with open(em_config_file) as f:
        try:
            # Emscripten configuration file is a Python file with simple assignments.
            exec(f.read(), em_config)
        except StandardError as e:
            raise RuntimeError("Emscripten configuration file '%s' is invalid:\n%s" % (em_config_file, e))
    normalized["EMCC_ROOT"] = em_config.get("EMSCRIPTEN_ROOT")
    normalized["NODE_JS"] = em_config.get("NODE_JS")
    normalized["CLOSURE_BIN"] = os.path.join(normalized["EMCC_ROOT"], "node_modules", ".bin", "google-closure-compiler")
    return normalized


def run_closure_compiler(target, source, env, for_signature):
    cfg = parse_config()
    cmd = [cfg["NODE_JS"], cfg["CLOSURE_BIN"]]
    cmd.extend(["--compilation_level", "ADVANCED_OPTIMIZATIONS"])
    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):
    if env["use_closure_compiler"]:
        return env.BuildJS(target, source, JSEXTERNS=externs)
    return env.Textfile(target, [env.File(s) for s in source])