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

Side by Side Diff: compile

Issue 29398655: Issue 5062 - [emscripten] Allow generation of custom bindings code (Closed) Base URL: https://hg.adblockplus.org/adblockpluscore
Patch Set: Rebased Created April 13, 2017, 1:06 p.m.
Left:
Right:
Use n/p to move between diff chunks; N/P to move between comments.
Jump to:
View unified diff | Download patch
« no previous file with comments | « README.md ('k') | compiled/bindings.cpp » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 #!/usr/bin/env python 1 #!/usr/bin/env python
2 2
3 # This file is part of Adblock Plus <https://adblockplus.org/>, 3 # This file is part of Adblock Plus <https://adblockplus.org/>,
4 # Copyright (C) 2006-2017 Eyeo GmbH 4 # Copyright (C) 2006-2017 Eyeo GmbH
5 # 5 #
6 # Adblock Plus is free software: you can redistribute it and/or modify 6 # Adblock Plus is free software: you can redistribute it and/or modify
7 # it under the terms of the GNU General Public License version 3 as 7 # it under the terms of the GNU General Public License version 3 as
8 # published by the Free Software Foundation. 8 # published by the Free Software Foundation.
9 # 9 #
10 # Adblock Plus is distributed in the hope that it will be useful, 10 # Adblock Plus is distributed in the hope that it will be useful,
(...skipping 10 matching lines...) Expand all
21 import sys 21 import sys
22 22
23 BASE_DIR = os.path.dirname(__file__) 23 BASE_DIR = os.path.dirname(__file__)
24 SOURCE_DIR = os.path.join(BASE_DIR, 'compiled') 24 SOURCE_DIR = os.path.join(BASE_DIR, 'compiled')
25 SOURCE_FILES = [ 25 SOURCE_FILES = [
26 os.path.join(path, f) 26 os.path.join(path, f)
27 for (path, dirs, files) in os.walk(SOURCE_DIR) 27 for (path, dirs, files) in os.walk(SOURCE_DIR)
28 for f in files 28 for f in files
29 if f.endswith('.cpp') 29 if f.endswith('.cpp')
30 ] 30 ]
31 BINDINGS_FILE = os.path.join(SOURCE_DIR, 'bindings.cpp')
32 BINDINGS_GENERATOR = os.path.join(SOURCE_DIR, 'bindings.cpp.js') 31 BINDINGS_GENERATOR = os.path.join(SOURCE_DIR, 'bindings.cpp.js')
33 BINDINGS_OUTPUT = os.path.join(SOURCE_DIR, 'bindings.js') 32 BINDINGS_OUTPUT = os.path.join(SOURCE_DIR, 'bindings.js')
34 COMPILER_OUTPUT = os.path.join(BASE_DIR, 'lib', 'compiled.js') 33 COMPILER_OUTPUT = os.path.join(BASE_DIR, 'lib', 'compiled.js')
35 GENERATION_PARAMS = { 34 GENERATION_PARAMS = {
36 'SHELL_FILE': "'{}'".format(os.path.abspath(os.path.join(SOURCE_DIR, 35 'SHELL_FILE': "'{}'".format(os.path.abspath(os.path.join(SOURCE_DIR,
37 'shell.js'))), 36 'shell.js'))),
38 'ASM_JS': 2, # "almost asm" 37 'ASM_JS': 2, # "almost asm"
39 'TOTAL_MEMORY': 16*1024*1024, 38 'TOTAL_MEMORY': 16*1024*1024,
40 'TOTAL_STACK': 1*1024*1024, 39 'TOTAL_STACK': 1*1024*1024,
41 'ALLOW_MEMORY_GROWTH': 1, 40 'ALLOW_MEMORY_GROWTH': 1,
(...skipping 17 matching lines...) Expand all
59 'EM_CONFIG': emscripten_config, 58 'EM_CONFIG': emscripten_config,
60 'EMSCRIPTEN': scope['EMSCRIPTEN_ROOT'], 59 'EMSCRIPTEN': scope['EMSCRIPTEN_ROOT'],
61 'PYTHON': scope.get('PYTHON', sys.executable), 60 'PYTHON': scope.get('PYTHON', sys.executable),
62 'NODE_JS': scope.get('NODE_JS', 'node'), 61 'NODE_JS': scope.get('NODE_JS', 'node'),
63 }) 62 })
64 return env 63 return env
65 64
66 65
67 def generate_bindings(env): 66 def generate_bindings(env):
68 params = [ 67 params = [
69 env['PYTHON'], os.path.join(env['EMSCRIPTEN'], 'emcc'), BINDINGS_FILE, 68 env['PYTHON'], os.path.join(env['EMSCRIPTEN'], 'emcc'),
70 '-o', BINDINGS_GENERATOR, '-std=gnu++14', '-DPRINT_BINDINGS', 69 '-o', BINDINGS_GENERATOR, '-std=gnu++14', '-DPRINT_BINDINGS',
71 '-s', 'WARN_ON_UNDEFINED_SYMBOLS=0', 70 ] + SOURCE_FILES
72 ]
73 subprocess.check_call(params, env=env) 71 subprocess.check_call(params, env=env)
74 72
75 with open(BINDINGS_OUTPUT, 'w') as file: 73 with open(BINDINGS_OUTPUT, 'w') as file:
76 subprocess.check_call([env['NODE_JS'], BINDINGS_GENERATOR], 74 subprocess.check_call([env['NODE_JS'], BINDINGS_GENERATOR],
77 stdout=file) 75 stdout=file)
78 76
79 77
80 def run_compiler(env, debug=False, tracing=False): 78 def run_compiler(env, debug=False, tracing=False):
81 params = [ 79 params = [
82 env['PYTHON'], os.path.join(env['EMSCRIPTEN'], 'emcc'), 80 env['PYTHON'], os.path.join(env['EMSCRIPTEN'], 'emcc'),
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after
115 parser.add_argument( 113 parser.add_argument(
116 '-t', '--tracing', 114 '-t', '--tracing',
117 action='store_true', 115 action='store_true',
118 help='Enable memory tracing' 116 help='Enable memory tracing'
119 ) 117 )
120 args = parser.parse_args() 118 args = parser.parse_args()
121 119
122 env = getenv(args.emscripten_config) 120 env = getenv(args.emscripten_config)
123 generate_bindings(env) 121 generate_bindings(env)
124 run_compiler(env, debug=args.debug, tracing=args.tracing) 122 run_compiler(env, debug=args.debug, tracing=args.tracing)
OLDNEW
« no previous file with comments | « README.md ('k') | compiled/bindings.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld