Index: compile |
=================================================================== |
--- a/compile |
+++ b/compile |
@@ -1,80 +1,85 @@ |
#!/usr/bin/env python |
-import json |
import os |
import re |
import subprocess |
-import warnings |
EMSCRIPTEN_PATH = '../emscripten' |
SOURCE_DIR = './compiled' |
SOURCE_FILES = [ |
- os.path.join(path, f) |
- for (path, dirs, files) in os.walk(SOURCE_DIR) |
- for f in files |
- if f.endswith('.cpp') |
+ os.path.join(path, f) |
+ for (path, dirs, files) in os.walk(SOURCE_DIR) |
+ for f in files |
+ if f.endswith('.cpp') |
] |
BINDINGS_FILE = os.path.join(SOURCE_DIR, 'bindings.cpp') |
BINDINGS_GENERATOR = os.path.join(SOURCE_DIR, 'bindings.cpp.js') |
BINDINGS_OUTPUT = os.path.join(SOURCE_DIR, 'bindings.js') |
COMPILER_OUTPUT = './lib/compiled.js' |
GENERATION_PARAMS = { |
- 'SHELL_FILE': "'%s'" % os.path.abspath(os.path.join(SOURCE_DIR, 'shell.js')), |
- 'ASM_JS': 2, # "almost asm" |
- 'TOTAL_MEMORY': 16*1024*1024, |
- 'TOTAL_STACK': 1*1024*1024, |
- 'ALLOW_MEMORY_GROWTH': 1, |
- 'NO_EXIT_RUNTIME': 1, |
- 'NO_DYNAMIC_EXECUTION': 1, |
- 'NO_FILESYSTEM': 1, |
- 'INVOKE_RUN': 0, |
- 'TEXTDECODER': 0, |
- 'EXPORTED_RUNTIME_METHODS': ['cwrap', 'ccall', 'stringToAscii'], |
+ 'SHELL_FILE': "'%s'" % os.path.abspath(os.path.join(SOURCE_DIR, |
Vasily Kuznetsov
2017/03/21 13:49:35
Funnily enough here flake8-abp doesn't complain ab
|
+ 'shell.js')), |
+ 'ASM_JS': 2, # "almost asm" |
+ 'TOTAL_MEMORY': 16*1024*1024, |
+ 'TOTAL_STACK': 1*1024*1024, |
+ 'ALLOW_MEMORY_GROWTH': 1, |
+ 'NO_EXIT_RUNTIME': 1, |
+ 'NO_DYNAMIC_EXECUTION': 1, |
+ 'NO_FILESYSTEM': 1, |
+ 'INVOKE_RUN': 0, |
+ 'TEXTDECODER': 0, |
+ 'EXPORTED_RUNTIME_METHODS': ['cwrap', 'ccall', 'stringToAscii'], |
} |
DEFINES = [] |
ADDITIONAL_PARAMS = ['-O3', '-m32', '-std=gnu++14', '--memory-init-file', '0', |
- '--emit-symbol-map'] |
+ '--emit-symbol-map'] |
+ |
def getenv(): |
- path = [] |
- env = {} |
- output = subprocess.check_output([ |
- '/bin/bash', '-c', os.path.join(EMSCRIPTEN_PATH, 'emsdk_env.sh')]) |
- for line in output.splitlines(): |
- match = re.search(r'^\s*PATH\s*\+=\s*(.*)', line) |
- if match: |
- path.append(match.group(1)) |
- match = re.search(r'^\s*(\w+)\s*=\s*(.*)', line) |
- if match: |
- env[match.group(1)] = match.group(2) |
- env['PATH'] = os.pathsep.join([os.environ['PATH']] + path) |
- return env |
+ path = [] |
+ env = {} |
+ output = subprocess.check_output([ |
+ '/bin/bash', '-c', os.path.join(EMSCRIPTEN_PATH, 'emsdk_env.sh') |
Sebastian Noack
2017/03/21 12:41:01
Unrelated of coding style changes but note that su
Wladimir Palant
2017/03/21 13:33:11
While I generally dislike relying on PATH, this co
|
+ ]) |
+ for line in output.splitlines(): |
+ match = re.search(r'^\s*PATH\s*\+=\s*(.*)', line) |
+ if match: |
+ path.append(match.group(1)) |
+ match = re.search(r'^\s*(\w+)\s*=\s*(.*)', line) |
+ if match: |
+ env[match.group(1)] = match.group(2) |
+ env['PATH'] = os.pathsep.join([os.environ['PATH']] + path) |
+ return env |
+ |
def generate_bindings(env): |
- params = [os.path.join(env['EMSCRIPTEN'], 'emcc'), BINDINGS_FILE, |
- '-o', BINDINGS_GENERATOR, '-std=gnu++14', '-DPRINT_BINDINGS', |
- '-s', 'WARN_ON_UNDEFINED_SYMBOLS=0', |
- ] |
- subprocess.check_call(params, env=env) |
+ params = [ |
+ os.path.join(env['EMSCRIPTEN'], 'emcc'), BINDINGS_FILE, |
+ '-o', BINDINGS_GENERATOR, '-std=gnu++14', '-DPRINT_BINDINGS', |
+ '-s', 'WARN_ON_UNDEFINED_SYMBOLS=0', |
+ ] |
+ subprocess.check_call(params, env=env) |
- node = subprocess.check_output('which node', env=env, shell=True).strip(); |
- with open(BINDINGS_OUTPUT, 'w') as file: |
- subprocess.check_call([node, BINDINGS_GENERATOR], env=env, stdout=file) |
+ node = subprocess.check_output('which node', env=env, shell=True).strip() |
+ with open(BINDINGS_OUTPUT, 'w') as file: |
+ subprocess.check_call([node, BINDINGS_GENERATOR], env=env, stdout=file) |
+ |
def run_compiler(env): |
- params = [ |
- os.path.join(env['EMSCRIPTEN'], 'emcc'), |
- '-o', COMPILER_OUTPUT, |
- '--post-js', BINDINGS_OUTPUT, |
- ] |
- params.extend(SOURCE_FILES) |
- params.extend('-D' + flag for flag in DEFINES) |
- for key, value in GENERATION_PARAMS.iteritems(): |
- params.extend(['-s', '%s=%s' % (key, str(value))]) |
- params.extend(ADDITIONAL_PARAMS) |
- subprocess.check_call(params, env=env) |
+ params = [ |
+ os.path.join(env['EMSCRIPTEN'], 'emcc'), |
+ '-o', COMPILER_OUTPUT, |
+ '--post-js', BINDINGS_OUTPUT, |
+ ] |
+ params.extend(SOURCE_FILES) |
+ params.extend('-D' + flag for flag in DEFINES) |
+ for key, value in GENERATION_PARAMS.iteritems(): |
+ params.extend(['-s', '%s=%s' % (key, str(value))]) |
Sebastian Noack
2017/03/21 12:41:01
Please use format instead of % when for string for
Wladimir Palant
2017/03/21 13:33:11
Done.
Vasily Kuznetsov
2017/03/21 13:49:35
I have done it and it only gives A107 on this line
|
+ params.extend(ADDITIONAL_PARAMS) |
+ subprocess.check_call(params, env=env) |
+ |
if __name__ == '__main__': |
- env = getenv() |
- generate_bindings(env) |
- run_compiler(env) |
+ env = getenv() |
+ generate_bindings(env) |
+ run_compiler(env) |