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

Unified Diff: compile

Issue 29410617: Issue 5131 - [emscripten] Clean separation of bindings code and runtime code (Closed) Base URL: https://hg.adblockplus.org/adblockpluscore
Patch Set: Created April 12, 2017, 2:07 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 | compiled/bindings/generator.h » ('j') | compiled/bindings/generator.h » ('J')
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: compile
===================================================================
--- a/compile
+++ b/compile
@@ -17,22 +17,16 @@
import argparse
import os
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')
-]
BINDINGS_GENERATOR = os.path.join(SOURCE_DIR, 'bindings.cpp.js')
BINDINGS_OUTPUT = os.path.join(SOURCE_DIR, 'bindings.js')
COMPILER_OUTPUT = os.path.join(BASE_DIR, 'lib', 'compiled.js')
GENERATION_PARAMS = {
'SHELL_FILE': "'{}'".format(os.path.abspath(os.path.join(SOURCE_DIR,
'shell.js'))),
'ASM_JS': 2, # "almost asm"
'TOTAL_MEMORY': 16*1024*1024,
@@ -45,16 +39,29 @@ 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 get_source_files(phase):
+ for (path, dirs, files) in os.walk(SOURCE_DIR):
+ for f in files:
+ if os.path.splitext(f)[1] != '.cpp':
+ continue
+ if (
+ phase != 'bindings' and
+ os.path.basename(path) == 'bindings' and
+ not f.startswith('runtime_')
+ ):
+ continue
+ yield os.path.join(path, f)
+
def getenv(emscripten_config):
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),
@@ -62,33 +69,33 @@ def getenv(emscripten_config):
})
return env
def generate_bindings(env):
params = [
env['PYTHON'], os.path.join(env['EMSCRIPTEN'], 'emcc'),
'-o', BINDINGS_GENERATOR, '-std=gnu++14', '-DPRINT_BINDINGS',
- ] + SOURCE_FILES
+ ] + list(get_source_files('bindings'))
subprocess.check_call(params, env=env)
with open(BINDINGS_OUTPUT, 'w') as file:
subprocess.check_call([env['NODE_JS'], BINDINGS_GENERATOR],
stdout=file)
def run_compiler(env, debug=False, tracing=False):
params = [
env['PYTHON'], os.path.join(env['EMSCRIPTEN'], 'emcc'),
'-o', COMPILER_OUTPUT,
'--post-js', BINDINGS_OUTPUT,
]
# Order matters. We sort source files so that we always get the same
# results for the same source code.
- params.extend(sorted(SOURCE_FILES))
+ params.extend(sorted(get_source_files('compile')))
params.extend('-D' + flag for flag in DEFINES)
for key, value in GENERATION_PARAMS.iteritems():
params.extend(['-s', '{}={}'.format(key, str(value))])
if debug:
params.append('-g3')
if tracing:
params.append('--tracing')
params.extend(ADDITIONAL_PARAMS)
« no previous file with comments | « no previous file | compiled/bindings/generator.h » ('j') | compiled/bindings/generator.h » ('J')

Powered by Google App Engine
This is Rietveld