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

Side by Side Diff: compile

Issue 29425555: Issue 5201 - [emscripten] Replace EM_ASM calls by a custom JavaScript library (Closed) Base URL: https://hg.adblockplus.org/adblockpluscore
Patch Set: Created April 30, 2017, 6:54 a.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 | « no previous file | compiled/FilterNotifier.h » ('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,
11 # but WITHOUT ANY WARRANTY; without even the implied warranty of 11 # but WITHOUT ANY WARRANTY; without even the implied warranty of
12 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 # GNU General Public License for more details. 13 # GNU General Public License for more details.
14 # 14 #
15 # You should have received a copy of the GNU General Public License 15 # You should have received a copy of the GNU General Public License
16 # along with Adblock Plus. If not, see <http://www.gnu.org/licenses/>. 16 # along with Adblock Plus. If not, see <http://www.gnu.org/licenses/>.
17 17
18 import argparse 18 import argparse
19 import os 19 import os
20 import subprocess 20 import subprocess
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 JS_LIBRARY = os.path.join(SOURCE_DIR, 'library.js')
25 BINDINGS_GENERATOR = os.path.join(SOURCE_DIR, 'bindings.cpp.js') 26 BINDINGS_GENERATOR = os.path.join(SOURCE_DIR, 'bindings.cpp.js')
26 BINDINGS_OUTPUT = os.path.join(SOURCE_DIR, 'bindings.js') 27 BINDINGS_OUTPUT = os.path.join(SOURCE_DIR, 'bindings.js')
27 COMPILER_OUTPUT = os.path.join(BASE_DIR, 'lib', 'compiled.js') 28 COMPILER_OUTPUT = os.path.join(BASE_DIR, 'lib', 'compiled.js')
28 GENERATION_PARAMS = { 29 GENERATION_PARAMS = {
29 'SHELL_FILE': "'{}'".format(os.path.abspath(os.path.join(SOURCE_DIR, 30 'SHELL_FILE': "'{}'".format(os.path.abspath(os.path.join(SOURCE_DIR,
30 'shell.js'))), 31 'shell.js'))),
31 'ASM_JS': 2, # "almost asm" 32 'ASM_JS': 2, # "almost asm"
32 'TOTAL_MEMORY': 16*1024*1024, 33 'TOTAL_MEMORY': 16*1024*1024,
33 'TOTAL_STACK': 1*1024*1024, 34 'TOTAL_STACK': 1*1024*1024,
34 'ALLOW_MEMORY_GROWTH': 1, 35 'ALLOW_MEMORY_GROWTH': 1,
35 'NO_EXIT_RUNTIME': 1, 36 'NO_EXIT_RUNTIME': 1,
36 'NO_DYNAMIC_EXECUTION': 1, 37 'NO_DYNAMIC_EXECUTION': 1,
37 'NO_FILESYSTEM': 1, 38 'NO_FILESYSTEM': 1,
38 'INVOKE_RUN': 0, 39 'INVOKE_RUN': 0,
39 'TEXTDECODER': 0, 40 'TEXTDECODER': 0,
40 'EXPORTED_RUNTIME_METHODS': ['cwrap', 'ccall', 'stringToAscii'], 41 'EXPORTED_RUNTIME_METHODS': ['cwrap', 'ccall', 'stringToAscii'],
41 } 42 }
42 DEFINES = [] 43 DEFINES = []
43 ADDITIONAL_PARAMS = ['-O3', '-m32', '-std=gnu++14', '--memory-init-file', '0', 44 ADDITIONAL_PARAMS = ['-O3', '-m32', '-std=gnu++14', '--memory-init-file', '0',
44 '--emit-symbol-map', '-Wall', '-Werror', '-fno-exceptions', 45 '--emit-symbol-map', '-Wall', '-Werror', '-fno-exceptions',
45 '-fno-rtti'] 46 '-fno-rtti', '--js-library', JS_LIBRARY]
46 47
47 48
48 def get_source_files(phase): 49 def get_source_files(phase):
49 for (path, dirs, files) in os.walk(SOURCE_DIR): 50 for (path, dirs, files) in os.walk(SOURCE_DIR):
50 for f in files: 51 for f in files:
51 if os.path.splitext(f)[1] != '.cpp': 52 if os.path.splitext(f)[1] != '.cpp':
52 continue 53 continue
53 if ( 54 if (
54 phase != 'bindings' and 55 phase != 'bindings' and
55 os.path.basename(path) == 'bindings' and 56 os.path.basename(path) == 'bindings' and
(...skipping 11 matching lines...) Expand all
67 'EMSCRIPTEN': scope['EMSCRIPTEN_ROOT'], 68 'EMSCRIPTEN': scope['EMSCRIPTEN_ROOT'],
68 'PYTHON': scope.get('PYTHON', sys.executable), 69 'PYTHON': scope.get('PYTHON', sys.executable),
69 'NODE_JS': scope.get('NODE_JS', 'node'), 70 'NODE_JS': scope.get('NODE_JS', 'node'),
70 }) 71 })
71 return env 72 return env
72 73
73 74
74 def generate_bindings(env): 75 def generate_bindings(env):
75 params = [ 76 params = [
76 env['PYTHON'], os.path.join(env['EMSCRIPTEN'], 'emcc'), 77 env['PYTHON'], os.path.join(env['EMSCRIPTEN'], 'emcc'),
77 '-o', BINDINGS_GENERATOR, '-std=gnu++14', '-DPRINT_BINDINGS', 78 '-o', BINDINGS_GENERATOR, '-std=gnu++14', '--js-library', JS_LIBRARY,
78 ] + list(get_source_files('bindings')) 79 ] + list(get_source_files('bindings'))
79 subprocess.check_call(params, env=env) 80 subprocess.check_call(params, env=env)
80 81
81 with open(BINDINGS_OUTPUT, 'w') as file: 82 with open(BINDINGS_OUTPUT, 'w') as file:
82 subprocess.check_call([env['NODE_JS'], BINDINGS_GENERATOR], 83 subprocess.check_call([env['NODE_JS'], BINDINGS_GENERATOR],
83 stdout=file) 84 stdout=file)
84 85
85 86
86 def run_compiler(env, debug=False, tracing=False): 87 def run_compiler(env, debug=False, tracing=False):
87 params = [ 88 params = [
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after
121 parser.add_argument( 122 parser.add_argument(
122 '-t', '--tracing', 123 '-t', '--tracing',
123 action='store_true', 124 action='store_true',
124 help='Enable memory tracing' 125 help='Enable memory tracing'
125 ) 126 )
126 args = parser.parse_args() 127 args = parser.parse_args()
127 128
128 env = getenv(args.emscripten_config) 129 env = getenv(args.emscripten_config)
129 generate_bindings(env) 130 generate_bindings(env)
130 run_compiler(env, debug=args.debug, tracing=args.tracing) 131 run_compiler(env, debug=args.debug, tracing=args.tracing)
OLDNEW
« no previous file with comments | « no previous file | compiled/FilterNotifier.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld