2020-03-11 10:55:28 +00:00
|
|
|
import os
|
|
|
|
|
2020-03-30 06:28:32 +00:00
|
|
|
|
2020-03-11 10:55:28 +00:00
|
|
|
def parse_config():
|
2020-03-30 06:28:32 +00:00
|
|
|
em_config_file = os.getenv("EM_CONFIG") or os.path.expanduser("~/.emscripten")
|
2020-03-11 10:55:28 +00:00
|
|
|
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))
|
2020-03-30 06:28:32 +00:00
|
|
|
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")
|
2020-03-11 10:55:28 +00:00
|
|
|
return normalized
|
|
|
|
|
|
|
|
|
|
|
|
def run_closure_compiler(target, source, env, for_signature):
|
|
|
|
cfg = parse_config()
|
2020-03-30 06:28:32 +00:00
|
|
|
cmd = [cfg["NODE_JS"], cfg["CLOSURE_BIN"]]
|
|
|
|
cmd.extend(["--compilation_level", "ADVANCED_OPTIMIZATIONS"])
|
|
|
|
for f in env["JSEXTERNS"]:
|
|
|
|
cmd.extend(["--externs", f.get_abspath()])
|
2020-03-11 10:55:28 +00:00
|
|
|
for f in source:
|
2020-03-30 06:28:32 +00:00
|
|
|
cmd.extend(["--js", f.get_abspath()])
|
|
|
|
cmd.extend(["--js_output_file", target[0].get_abspath()])
|
|
|
|
return " ".join(cmd)
|
2020-03-11 10:55:28 +00:00
|
|
|
|
|
|
|
|
|
|
|
def create_engine_file(env, target, source, externs):
|
2020-03-30 06:28:32 +00:00
|
|
|
if env["use_closure_compiler"]:
|
2020-03-11 10:55:28 +00:00
|
|
|
return env.BuildJS(target, source, JSEXTERNS=externs)
|
|
|
|
return env.Textfile(target, [env.File(s) for s in source])
|