| Left: | ||
| Right: |
| OLD | NEW |
|---|---|
| 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 SOURCE_FILES = [ | |
| 26 os.path.join(path, f) | |
| 27 for (path, dirs, files) in os.walk(SOURCE_DIR) | |
| 28 for f in files | |
| 29 if f.endswith('.cpp') | |
| 30 ] | |
| 31 BINDINGS_GENERATOR = os.path.join(SOURCE_DIR, 'bindings.cpp.js') | 25 BINDINGS_GENERATOR = os.path.join(SOURCE_DIR, 'bindings.cpp.js') |
| 32 BINDINGS_OUTPUT = os.path.join(SOURCE_DIR, 'bindings.js') | 26 BINDINGS_OUTPUT = os.path.join(SOURCE_DIR, 'bindings.js') |
| 33 COMPILER_OUTPUT = os.path.join(BASE_DIR, 'lib', 'compiled.js') | 27 COMPILER_OUTPUT = os.path.join(BASE_DIR, 'lib', 'compiled.js') |
| 34 GENERATION_PARAMS = { | 28 GENERATION_PARAMS = { |
| 35 'SHELL_FILE': "'{}'".format(os.path.abspath(os.path.join(SOURCE_DIR, | 29 'SHELL_FILE': "'{}'".format(os.path.abspath(os.path.join(SOURCE_DIR, |
| 36 'shell.js'))), | 30 'shell.js'))), |
| 37 'ASM_JS': 2, # "almost asm" | 31 'ASM_JS': 2, # "almost asm" |
| 38 'TOTAL_MEMORY': 16*1024*1024, | 32 'TOTAL_MEMORY': 16*1024*1024, |
| 39 'TOTAL_STACK': 1*1024*1024, | 33 'TOTAL_STACK': 1*1024*1024, |
| 40 'ALLOW_MEMORY_GROWTH': 1, | 34 'ALLOW_MEMORY_GROWTH': 1, |
| 41 'NO_EXIT_RUNTIME': 1, | 35 'NO_EXIT_RUNTIME': 1, |
| 42 'NO_DYNAMIC_EXECUTION': 1, | 36 'NO_DYNAMIC_EXECUTION': 1, |
| 43 'NO_FILESYSTEM': 1, | 37 'NO_FILESYSTEM': 1, |
| 44 'INVOKE_RUN': 0, | 38 'INVOKE_RUN': 0, |
| 45 'TEXTDECODER': 0, | 39 'TEXTDECODER': 0, |
| 46 'EXPORTED_RUNTIME_METHODS': ['cwrap', 'ccall', 'stringToAscii'], | 40 'EXPORTED_RUNTIME_METHODS': ['cwrap', 'ccall', 'stringToAscii'], |
| 47 } | 41 } |
| 48 DEFINES = [] | 42 DEFINES = [] |
| 49 ADDITIONAL_PARAMS = ['-O3', '-m32', '-std=gnu++14', '--memory-init-file', '0', | 43 ADDITIONAL_PARAMS = ['-O3', '-m32', '-std=gnu++14', '--memory-init-file', '0', |
| 50 '--emit-symbol-map', '-Wall', '-Werror', '-fno-exceptions'] | 44 '--emit-symbol-map', '-Wall', '-Werror', '-fno-exceptions'] |
| 51 | 45 |
| 52 | 46 |
| 47 def get_source_files(phase): | |
| 48 for (path, dirs, files) in os.walk(SOURCE_DIR): | |
| 49 for f in files: | |
| 50 if os.path.splitext(f)[1] != '.cpp': | |
| 51 continue | |
| 52 if ( | |
| 53 phase != 'bindings' and | |
| 54 os.path.basename(path) == 'bindings' and | |
| 55 not f.startswith('runtime_') | |
|
sergei
2017/04/18 10:46:09
I expected bindings/runtime_utils.cpp and files fo
Wladimir Palant
2017/04/18 11:01:37
I know. However, IMHO code locality is more import
| |
| 56 ): | |
| 57 continue | |
| 58 yield os.path.join(path, f) | |
| 59 | |
| 53 def getenv(emscripten_config): | 60 def getenv(emscripten_config): |
| 54 scope = {} | 61 scope = {} |
| 55 execfile(emscripten_config, scope, scope) | 62 execfile(emscripten_config, scope, scope) |
| 56 env = os.environ.copy() | 63 env = os.environ.copy() |
| 57 env.update({ | 64 env.update({ |
| 58 'EM_CONFIG': emscripten_config, | 65 'EM_CONFIG': emscripten_config, |
| 59 'EMSCRIPTEN': scope['EMSCRIPTEN_ROOT'], | 66 'EMSCRIPTEN': scope['EMSCRIPTEN_ROOT'], |
| 60 'PYTHON': scope.get('PYTHON', sys.executable), | 67 'PYTHON': scope.get('PYTHON', sys.executable), |
| 61 'NODE_JS': scope.get('NODE_JS', 'node'), | 68 'NODE_JS': scope.get('NODE_JS', 'node'), |
| 62 }) | 69 }) |
| 63 return env | 70 return env |
| 64 | 71 |
| 65 | 72 |
| 66 def generate_bindings(env): | 73 def generate_bindings(env): |
| 67 params = [ | 74 params = [ |
| 68 env['PYTHON'], os.path.join(env['EMSCRIPTEN'], 'emcc'), | 75 env['PYTHON'], os.path.join(env['EMSCRIPTEN'], 'emcc'), |
| 69 '-o', BINDINGS_GENERATOR, '-std=gnu++14', '-DPRINT_BINDINGS', | 76 '-o', BINDINGS_GENERATOR, '-std=gnu++14', '-DPRINT_BINDINGS', |
| 70 ] + SOURCE_FILES | 77 ] + list(get_source_files('bindings')) |
| 71 subprocess.check_call(params, env=env) | 78 subprocess.check_call(params, env=env) |
| 72 | 79 |
| 73 with open(BINDINGS_OUTPUT, 'w') as file: | 80 with open(BINDINGS_OUTPUT, 'w') as file: |
| 74 subprocess.check_call([env['NODE_JS'], BINDINGS_GENERATOR], | 81 subprocess.check_call([env['NODE_JS'], BINDINGS_GENERATOR], |
| 75 stdout=file) | 82 stdout=file) |
| 76 | 83 |
| 77 | 84 |
| 78 def run_compiler(env, debug=False, tracing=False): | 85 def run_compiler(env, debug=False, tracing=False): |
| 79 params = [ | 86 params = [ |
| 80 env['PYTHON'], os.path.join(env['EMSCRIPTEN'], 'emcc'), | 87 env['PYTHON'], os.path.join(env['EMSCRIPTEN'], 'emcc'), |
| 81 '-o', COMPILER_OUTPUT, | 88 '-o', COMPILER_OUTPUT, |
| 82 '--post-js', BINDINGS_OUTPUT, | 89 '--post-js', BINDINGS_OUTPUT, |
| 83 ] | 90 ] |
| 84 # Order matters. We sort source files so that we always get the same | 91 # Order matters. We sort source files so that we always get the same |
| 85 # results for the same source code. | 92 # results for the same source code. |
| 86 params.extend(sorted(SOURCE_FILES)) | 93 params.extend(sorted(get_source_files('compile'))) |
| 87 params.extend('-D' + flag for flag in DEFINES) | 94 params.extend('-D' + flag for flag in DEFINES) |
| 88 for key, value in GENERATION_PARAMS.iteritems(): | 95 for key, value in GENERATION_PARAMS.iteritems(): |
| 89 params.extend(['-s', '{}={}'.format(key, str(value))]) | 96 params.extend(['-s', '{}={}'.format(key, str(value))]) |
| 90 if debug: | 97 if debug: |
| 91 params.append('-g3') | 98 params.append('-g3') |
| 92 if tracing: | 99 if tracing: |
| 93 params.append('--tracing') | 100 params.append('--tracing') |
| 94 params.extend(ADDITIONAL_PARAMS) | 101 params.extend(ADDITIONAL_PARAMS) |
| 95 subprocess.check_call(params, env=env) | 102 subprocess.check_call(params, env=env) |
| 96 | 103 |
| (...skipping 16 matching lines...) Expand all Loading... | |
| 113 parser.add_argument( | 120 parser.add_argument( |
| 114 '-t', '--tracing', | 121 '-t', '--tracing', |
| 115 action='store_true', | 122 action='store_true', |
| 116 help='Enable memory tracing' | 123 help='Enable memory tracing' |
| 117 ) | 124 ) |
| 118 args = parser.parse_args() | 125 args = parser.parse_args() |
| 119 | 126 |
| 120 env = getenv(args.emscripten_config) | 127 env = getenv(args.emscripten_config) |
| 121 generate_bindings(env) | 128 generate_bindings(env) |
| 122 run_compiler(env, debug=args.debug, tracing=args.tracing) | 129 run_compiler(env, debug=args.debug, tracing=args.tracing) |
| OLD | NEW |