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: Created March 23, 2017, 2 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,44 @@ 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):
+ scope = {}
+ execfile(emscripten_config, scope, scope)
+ env = os.environ.copy()
+ env.update({
+ 'EM_CONFIG': emscripten_config,
Wladimir Palant 2017/03/23 14:10:57 It seems that Emscripten itself only needs this en
+ 'EMSCRIPTEN': scope['EMSCRIPTEN_ROOT'],
+ 'PYTHON': scope.get('PYTHON', sys.executable),
+ 'NODE_JS': scope.get('NODE_JS', 'node'),
Wladimir Palant 2017/03/23 14:10:57 This will typically be misconfigured on Windows, s
+ })
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,
'-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], 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'),
'-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 +79,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',
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