Rietveld Code Review Tool
Help | Bug tracker | Discussion group | Source code

Unified Diff: compile

Issue 29392768: Issue 5020 - [emscripten] Part 4: Make compile script Windows-compatible (Closed) Base URL: https://hg.adblockplus.org/adblockpluscore
Patch Set: Fixed line length Created March 23, 2017, 2:53 p.m.
Use n/p to move between diff chunks; N/P to move between comments.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: compile
===================================================================
--- a/compile
+++ b/compile
@@ -1,14 +1,14 @@
#!/usr/bin/env python
import argparse
import os
-import re
import subprocess
+import sys
BASE_DIR = os.path.dirname(__file__)
SOURCE_DIR = os.path.join(BASE_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')
@@ -31,49 +31,45 @@ GENERATION_PARAMS = {
'TEXTDECODER': 0,
'EXPORTED_RUNTIME_METHODS': ['cwrap', 'ccall', 'stringToAscii'],
}
DEFINES = []
ADDITIONAL_PARAMS = ['-O3', '-m32', '-std=gnu++14', '--memory-init-file', '0',
'--emit-symbol-map']
-def getenv(emscripten_path):
- 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)
+def getenv(emscripten_config):
Vasily Kuznetsov 2017/03/23 19:26:53 Instead of running `emsdk_env.sh` located at `emsc
+ scope = {}
+ execfile(emscripten_config, scope, scope)
+ env = os.environ.copy()
+ env.update({
+ 'EM_CONFIG': emscripten_config,
+ 'EMSCRIPTEN': scope['EMSCRIPTEN_ROOT'],
+ 'PYTHON': scope.get('PYTHON', sys.executable),
+ 'NODE_JS': scope.get('NODE_JS', 'node'),
+ })
return env
def generate_bindings(env):
params = [
- os.path.join(env['EMSCRIPTEN'], 'emcc'), BINDINGS_FILE,
+ env['PYTHON'], os.path.join(env['EMSCRIPTEN'], 'emcc'), BINDINGS_FILE,
Vasily Kuznetsov 2017/03/23 19:26:53 We use python interpreter configured in emscripten
Wladimir Palant 2017/03/24 06:20:41 There is emcc.bat on Windows but it relies on Pyth
'-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)
+ subprocess.check_call([env['NODE_JS'], BINDINGS_GENERATOR],
Vasily Kuznetsov 2017/03/23 19:26:53 We use the path to node from emscripten config (de
Wladimir Palant 2017/03/24 06:20:41 The drawback here is that Emscripten comes with a
+ stdout=file)
def run_compiler(env, debug=False, tracing=False):
params = [
- os.path.join(env['EMSCRIPTEN'], 'emcc'),
+ env['PYTHON'], os.path.join(env['EMSCRIPTEN'], 'emcc'),
Vasily Kuznetsov 2017/03/23 19:26:53 Again invoke python script with a python interpret
'-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', '{}={}'.format(key, str(value))])
if debug:
@@ -84,28 +80,28 @@ def run_compiler(env, debug=False, traci
subprocess.check_call(params, env=env)
if __name__ == '__main__':
parser = argparse.ArgumentParser(
description='Compile Emscripten-based C++ code to JavaScript'
)
parser.add_argument(
- '--emscripten',
+ '--emscripten-config',
Vasily Kuznetsov 2017/03/23 19:26:53 We switch to using emscripten config instead of us
Wladimir Palant 2017/03/24 06:20:41 emsdk construct_env (which is what we have been ca
metavar='DIR',
- default=os.path.join(BASE_DIR, '..', 'emscripten'),
+ default=os.path.expanduser('~/.emscripten'),
help='Emscripten installation directory'
)
parser.add_argument(
'-d', '--debug',
action='store_true',
help='Disable code minification'
)
parser.add_argument(
'-t', '--tracing',
action='store_true',
help='Enable memory tracing'
)
args = parser.parse_args()
- env = getenv(args.emscripten)
+ env = getenv(args.emscripten_config)
generate_bindings(env)
run_compiler(env, debug=args.debug, tracing=args.tracing)
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld