Left: | ||
Right: |
LEFT | RIGHT |
---|---|
1 #!/usr/bin/env python | 1 #!/usr/bin/env python |
2 | 2 |
3 import os | 3 import os |
4 import re | 4 import re |
5 import subprocess | 5 import subprocess |
6 | 6 |
7 BASE_DIR = os.path.dirname(__file__) or os.getcwd() | 7 BASE_DIR = os.path.dirname(__file__) |
Vasily Kuznetsov
2017/03/21 18:01:42
BASE_DIR (which I suppose is the path to the direc
Wladimir Palant
2017/03/22 08:44:20
It's fine to have relative paths for almost all pu
Vasily Kuznetsov
2017/03/22 09:52:58
I guess I'm missing some part of the picture here.
Wladimir Palant
2017/03/22 14:59:29
See SHELL_FILE key in GENERATION_PARAMS below. It
Vasily Kuznetsov
2017/03/22 19:16:01
Ah, ok, now I get it. But then we don't really nee
Wladimir Palant
2017/03/23 11:55:28
Fair enough, I verified that os.path.join('', 'foo
| |
8 EMSCRIPTEN_PATH = os.path.join(BASE_DIR, '..', 'emscripten') | 8 EMSCRIPTEN_PATH = os.path.join(BASE_DIR, '..', 'emscripten') |
9 SOURCE_DIR = os.path.join(BASE_DIR, 'compiled') | 9 SOURCE_DIR = os.path.join(BASE_DIR, 'compiled') |
10 SOURCE_FILES = [ | 10 SOURCE_FILES = [ |
11 os.path.join(path, f) | 11 os.path.join(path, f) |
12 for (path, dirs, files) in os.walk(SOURCE_DIR) | 12 for (path, dirs, files) in os.walk(SOURCE_DIR) |
13 for f in files | 13 for f in files |
14 if f.endswith('.cpp') | 14 if f.endswith('.cpp') |
15 ] | 15 ] |
16 BINDINGS_FILE = os.path.join(SOURCE_DIR, 'bindings.cpp') | 16 BINDINGS_FILE = os.path.join(SOURCE_DIR, 'bindings.cpp') |
17 BINDINGS_GENERATOR = os.path.join(SOURCE_DIR, 'bindings.cpp.js') | 17 BINDINGS_GENERATOR = os.path.join(SOURCE_DIR, 'bindings.cpp.js') |
18 BINDINGS_OUTPUT = os.path.join(SOURCE_DIR, 'bindings.js') | 18 BINDINGS_OUTPUT = os.path.join(SOURCE_DIR, 'bindings.js') |
19 COMPILER_OUTPUT = os.path.join(BASE_DIR, 'lib', 'compiled.js') | 19 COMPILER_OUTPUT = os.path.join(BASE_DIR, 'lib', 'compiled.js') |
20 GENERATION_PARAMS = { | 20 GENERATION_PARAMS = { |
21 'SHELL_FILE': "'%s'" % os.path.abspath(os.path.join(SOURCE_DIR, | 21 'SHELL_FILE': "'{}'".format(os.path.abspath(os.path.join(SOURCE_DIR, |
22 'shell.js')), | 22 'shell.js'))), |
23 'ASM_JS': 2, # "almost asm" | 23 'ASM_JS': 2, # "almost asm" |
24 'TOTAL_MEMORY': 16*1024*1024, | 24 'TOTAL_MEMORY': 16*1024*1024, |
25 'TOTAL_STACK': 1*1024*1024, | 25 'TOTAL_STACK': 1*1024*1024, |
26 'ALLOW_MEMORY_GROWTH': 1, | 26 'ALLOW_MEMORY_GROWTH': 1, |
27 'NO_EXIT_RUNTIME': 1, | 27 'NO_EXIT_RUNTIME': 1, |
28 'NO_DYNAMIC_EXECUTION': 1, | 28 'NO_DYNAMIC_EXECUTION': 1, |
29 'NO_FILESYSTEM': 1, | 29 'NO_FILESYSTEM': 1, |
30 'INVOKE_RUN': 0, | 30 'INVOKE_RUN': 0, |
31 'TEXTDECODER': 0, | 31 'TEXTDECODER': 0, |
32 'EXPORTED_RUNTIME_METHODS': ['cwrap', 'ccall', 'stringToAscii'], | 32 'EXPORTED_RUNTIME_METHODS': ['cwrap', 'ccall', 'stringToAscii'], |
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
68 | 68 |
69 def run_compiler(env): | 69 def run_compiler(env): |
70 params = [ | 70 params = [ |
71 os.path.join(env['EMSCRIPTEN'], 'emcc'), | 71 os.path.join(env['EMSCRIPTEN'], 'emcc'), |
72 '-o', COMPILER_OUTPUT, | 72 '-o', COMPILER_OUTPUT, |
73 '--post-js', BINDINGS_OUTPUT, | 73 '--post-js', BINDINGS_OUTPUT, |
74 ] | 74 ] |
75 params.extend(SOURCE_FILES) | 75 params.extend(SOURCE_FILES) |
76 params.extend('-D' + flag for flag in DEFINES) | 76 params.extend('-D' + flag for flag in DEFINES) |
77 for key, value in GENERATION_PARAMS.iteritems(): | 77 for key, value in GENERATION_PARAMS.iteritems(): |
78 params.extend(['-s', '%s=%s' % (key, str(value))]) | 78 params.extend(['-s', '{}={}'.format(key, str(value))]) |
79 params.extend(ADDITIONAL_PARAMS) | 79 params.extend(ADDITIONAL_PARAMS) |
80 subprocess.check_call(params, env=env) | 80 subprocess.check_call(params, env=env) |
81 | 81 |
82 | 82 |
83 if __name__ == '__main__': | 83 if __name__ == '__main__': |
84 env = getenv() | 84 env = getenv() |
85 generate_bindings(env) | 85 generate_bindings(env) |
86 run_compiler(env) | 86 run_compiler(env) |
LEFT | RIGHT |