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

Delta Between Two Patch Sets: compile

Issue 29390663: Issue 5020 - Part 3: Add command line options to compile script (Closed) Base URL: https://hg.adblockplus.org/adblockpluscore
Left Patch Set: Created March 21, 2017, 11:22 a.m.
Right Patch Set: Improved the way compiler parameters are passed Created March 22, 2017, 8:51 a.m.
Left:
Right:
Use n/p to move between diff chunks; N/P to move between comments.
Jump to:
Left: Side by side diff | Download
Right: Side by side diff | Download
« no previous file with change/comment | « no previous file | no next file » | no next file with change/comment »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
LEFTRIGHT
1 #!/usr/bin/env python 1 #!/usr/bin/env python
2 2
3 import argparse 3 import argparse
4 import os 4 import os
5 import re 5 import re
6 import subprocess 6 import subprocess
7 7
8 BASE_DIR = os.path.dirname(__file__) or os.getcwd() 8 BASE_DIR = os.path.dirname(__file__) or os.getcwd()
9 SOURCE_DIR = os.path.join(BASE_DIR, 'compiled') 9 SOURCE_DIR = os.path.join(BASE_DIR, 'compiled')
10 SOURCE_FILES = [ 10 SOURCE_FILES = [
11 os.path.join(path, f) 11 os.path.join(path, f)
12 for (path, dirs, files) in os.walk(SOURCE_DIR) 12 for (path, dirs, files) in os.walk(SOURCE_DIR)
13 for f in files 13 for f in files
14 if f.endswith('.cpp') 14 if f.endswith('.cpp')
15 ] 15 ]
16 BINDINGS_FILE = os.path.join(SOURCE_DIR, 'bindings.cpp') 16 BINDINGS_FILE = os.path.join(SOURCE_DIR, 'bindings.cpp')
17 BINDINGS_GENERATOR = os.path.join(SOURCE_DIR, 'bindings.cpp.js') 17 BINDINGS_GENERATOR = os.path.join(SOURCE_DIR, 'bindings.cpp.js')
18 BINDINGS_OUTPUT = os.path.join(SOURCE_DIR, 'bindings.js') 18 BINDINGS_OUTPUT = os.path.join(SOURCE_DIR, 'bindings.js')
19 COMPILER_OUTPUT = os.path.join(BASE_DIR, 'lib', 'compiled.js') 19 COMPILER_OUTPUT = os.path.join(BASE_DIR, 'lib', 'compiled.js')
20 GENERATION_PARAMS = { 20 GENERATION_PARAMS = {
21 'SHELL_FILE': "'%s'" % os.path.abspath(os.path.join(SOURCE_DIR, 21 'SHELL_FILE': "'{}'".format(os.path.abspath(os.path.join(SOURCE_DIR,
22 'shell.js')), 22 'shell.js'))),
23 'ASM_JS': 2, # "almost asm" 23 'ASM_JS': 2, # "almost asm"
24 'TOTAL_MEMORY': 16*1024*1024, 24 'TOTAL_MEMORY': 16*1024*1024,
25 'TOTAL_STACK': 1*1024*1024, 25 'TOTAL_STACK': 1*1024*1024,
26 'ALLOW_MEMORY_GROWTH': 1, 26 'ALLOW_MEMORY_GROWTH': 1,
27 'NO_EXIT_RUNTIME': 1, 27 'NO_EXIT_RUNTIME': 1,
28 'NO_DYNAMIC_EXECUTION': 1, 28 'NO_DYNAMIC_EXECUTION': 1,
29 'NO_FILESYSTEM': 1, 29 'NO_FILESYSTEM': 1,
30 'INVOKE_RUN': 0, 30 'INVOKE_RUN': 0,
31 'TEXTDECODER': 0, 31 'TEXTDECODER': 0,
32 'EXPORTED_RUNTIME_METHODS': ['cwrap', 'ccall', 'stringToAscii'], 32 'EXPORTED_RUNTIME_METHODS': ['cwrap', 'ccall', 'stringToAscii'],
(...skipping 26 matching lines...) Expand all
59 '-o', BINDINGS_GENERATOR, '-std=gnu++14', '-DPRINT_BINDINGS', 59 '-o', BINDINGS_GENERATOR, '-std=gnu++14', '-DPRINT_BINDINGS',
60 '-s', 'WARN_ON_UNDEFINED_SYMBOLS=0', 60 '-s', 'WARN_ON_UNDEFINED_SYMBOLS=0',
61 ] 61 ]
62 subprocess.check_call(params, env=env) 62 subprocess.check_call(params, env=env)
63 63
64 node = subprocess.check_output('which node', env=env, shell=True).strip() 64 node = subprocess.check_output('which node', env=env, shell=True).strip()
65 with open(BINDINGS_OUTPUT, 'w') as file: 65 with open(BINDINGS_OUTPUT, 'w') as file:
66 subprocess.check_call([node, BINDINGS_GENERATOR], env=env, stdout=file) 66 subprocess.check_call([node, BINDINGS_GENERATOR], env=env, stdout=file)
67 67
68 68
69 def run_compiler(env): 69 def run_compiler(env, debug=False, tracing=False):
70 params = [ 70 params = [
71 os.path.join(env['EMSCRIPTEN'], 'emcc'), 71 os.path.join(env['EMSCRIPTEN'], 'emcc'),
72 '-o', COMPILER_OUTPUT, 72 '-o', COMPILER_OUTPUT,
73 '--post-js', BINDINGS_OUTPUT, 73 '--post-js', BINDINGS_OUTPUT,
74 ] 74 ]
75 params.extend(SOURCE_FILES) 75 params.extend(SOURCE_FILES)
76 params.extend('-D' + flag for flag in DEFINES) 76 params.extend('-D' + flag for flag in DEFINES)
77 for key, value in GENERATION_PARAMS.iteritems(): 77 for key, value in GENERATION_PARAMS.iteritems():
78 params.extend(['-s', '%s=%s' % (key, str(value))]) 78 params.extend(['-s', '{}={}'.format(key, str(value))])
79 if debug:
80 params.append('-g1')
81 if tracing:
82 params.append('--tracing')
79 params.extend(ADDITIONAL_PARAMS) 83 params.extend(ADDITIONAL_PARAMS)
80 subprocess.check_call(params, env=env) 84 subprocess.check_call(params, env=env)
81 85
82 86
83 if __name__ == '__main__': 87 if __name__ == '__main__':
84 parser = argparse.ArgumentParser( 88 parser = argparse.ArgumentParser(
85 description='Compile Emscripten-based C++ code to JavaScript' 89 description='Compile Emscripten-based C++ code to JavaScript'
86 ) 90 )
87 parser.add_argument( 91 parser.add_argument(
88 '--emscripten', 92 '--emscripten',
89 metavar='DIR', 93 metavar='DIR',
90 default=os.path.join(BASE_DIR, '..', 'emscripten'), 94 default=os.path.join(BASE_DIR, '..', 'emscripten'),
91 help='Emscripten installation directory' 95 help='Emscripten installation directory'
92 ) 96 )
93 parser.add_argument( 97 parser.add_argument(
94 '-d', '--debug', 98 '-d', '--debug',
95 action='store_true', 99 action='store_true',
96 help='Disable code minification' 100 help='Disable code minification'
97 ) 101 )
98 parser.add_argument( 102 parser.add_argument(
99 '-t', '--tracing', 103 '-t', '--tracing',
100 action='store_true', 104 action='store_true',
101 help='Enable memory tracing' 105 help='Enable memory tracing'
102 ) 106 )
103 args = parser.parse_args() 107 args = parser.parse_args()
104 108
105 if args.debug:
106 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
107 if args.tracing:
108 ADDITIONAL_PARAMS.append('--tracing')
109
110 env = getenv(args.emscripten) 109 env = getenv(args.emscripten)
111 generate_bindings(env) 110 generate_bindings(env)
112 run_compiler(env) 111 run_compiler(env, debug=args.debug, tracing=args.tracing)
LEFTRIGHT
« no previous file | no next file » | Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Toggle Comments ('s')

Powered by Google App Engine
This is Rietveld