Left: | ||
Right: |
OLD | NEW |
---|---|
1 #!/usr/bin/env python | 1 #!/usr/bin/env python |
2 | 2 |
3 import argparse | |
3 import os | 4 import os |
4 import re | 5 import re |
5 import subprocess | 6 import subprocess |
6 | 7 |
7 BASE_DIR = os.path.dirname(__file__) or os.getcwd() | 8 BASE_DIR = os.path.dirname(__file__) or os.getcwd() |
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') |
(...skipping 10 matching lines...) Expand all Loading... | |
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'], |
33 } | 33 } |
34 DEFINES = [] | 34 DEFINES = [] |
35 ADDITIONAL_PARAMS = ['-O3', '-m32', '-std=gnu++14', '--memory-init-file', '0', | 35 ADDITIONAL_PARAMS = ['-O3', '-m32', '-std=gnu++14', '--memory-init-file', '0', |
36 '--emit-symbol-map'] | 36 '--emit-symbol-map'] |
37 | 37 |
38 | 38 |
39 def getenv(): | 39 def getenv(emscripten_path): |
40 path = [] | 40 path = [] |
41 env = {} | 41 env = {} |
42 output = subprocess.check_output([ | 42 output = subprocess.check_output([ |
43 '/bin/bash', '-c', os.path.join(EMSCRIPTEN_PATH, 'emsdk_env.sh') | 43 '/bin/bash', '-c', os.path.join(emscripten_path, 'emsdk_env.sh') |
44 ]) | 44 ]) |
45 for line in output.splitlines(): | 45 for line in output.splitlines(): |
46 match = re.search(r'^\s*PATH\s*\+=\s*(.*)', line) | 46 match = re.search(r'^\s*PATH\s*\+=\s*(.*)', line) |
47 if match: | 47 if match: |
48 path.append(match.group(1)) | 48 path.append(match.group(1)) |
49 match = re.search(r'^\s*(\w+)\s*=\s*(.*)', line) | 49 match = re.search(r'^\s*(\w+)\s*=\s*(.*)', line) |
50 if match: | 50 if match: |
51 env[match.group(1)] = match.group(2) | 51 env[match.group(1)] = match.group(2) |
52 env['PATH'] = os.pathsep.join([os.environ['PATH']] + path) | 52 env['PATH'] = os.pathsep.join([os.environ['PATH']] + path) |
53 return env | 53 return env |
(...skipping 20 matching lines...) Expand all Loading... | |
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', '%s=%s' % (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 parser = argparse.ArgumentParser( |
85 description='Compile Emscripten-based C++ code to JavaScript' | |
86 ) | |
87 parser.add_argument( | |
88 '--emscripten', | |
89 metavar='DIR', | |
90 default=os.path.join(BASE_DIR, '..', 'emscripten'), | |
91 help='Emscripten installation directory' | |
92 ) | |
93 parser.add_argument( | |
94 '-d', '--debug', | |
95 action='store_true', | |
96 help='Disable code minification' | |
97 ) | |
98 parser.add_argument( | |
99 '-t', '--tracing', | |
100 action='store_true', | |
101 help='Enable memory tracing' | |
102 ) | |
103 args = parser.parse_args() | |
104 | |
105 if args.debug: | |
106 ADDITIONAL_PARAMS.append('-g1') | |
Vasily Kuznetsov
2017/03/21 18:38:19
Isn't it a bit misleading that ADDITIONAL_PARAMETE
Wladimir Palant
2017/03/22 08:52:12
I have been wondering the same thing. Yes, let's d
| |
107 if args.tracing: | |
108 ADDITIONAL_PARAMS.append('--tracing') | |
109 | |
110 env = getenv(args.emscripten) | |
85 generate_bindings(env) | 111 generate_bindings(env) |
86 run_compiler(env) | 112 run_compiler(env) |
OLD | NEW |