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

Unified Diff: compile

Issue 29390663: Issue 5020 - Part 3: Add command line options to compile script (Closed) Base URL: https://hg.adblockplus.org/adblockpluscore
Patch Set: Created March 21, 2017, 11:22 a.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,16 +1,16 @@
#!/usr/bin/env python
+import argparse
import os
import re
import subprocess
BASE_DIR = os.path.dirname(__file__) or os.getcwd()
-EMSCRIPTEN_PATH = os.path.join(BASE_DIR, '..', 'emscripten')
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')
]
BINDINGS_FILE = os.path.join(SOURCE_DIR, 'bindings.cpp')
@@ -31,21 +31,21 @@ 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():
+def getenv(emscripten_path):
path = []
env = {}
output = subprocess.check_output([
- '/bin/bash', '-c', os.path.join(EMSCRIPTEN_PATH, 'emsdk_env.sh')
+ '/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)
@@ -76,11 +76,37 @@ def run_compiler(env):
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)
if __name__ == '__main__':
- env = getenv()
+ parser = argparse.ArgumentParser(
+ description='Compile Emscripten-based C++ code to JavaScript'
+ )
+ parser.add_argument(
+ '--emscripten',
+ metavar='DIR',
+ default=os.path.join(BASE_DIR, '..', '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()
+
+ if args.debug:
+ 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
+ if args.tracing:
+ ADDITIONAL_PARAMS.append('--tracing')
+
+ env = getenv(args.emscripten)
generate_bindings(env)
run_compiler(env)
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld