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

Side by Side Diff: compile

Issue 29392768: Issue 5020 - [emscripten] Part 4: Make compile script Windows-compatible (Closed) Base URL: https://hg.adblockplus.org/adblockpluscore
Patch Set: Fixed line length Created March 23, 2017, 2:53 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 | « no previous file | no next file » | 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 import argparse 3 import argparse
4 import os 4 import os
5 import re
6 import subprocess 5 import subprocess
6 import sys
7 7
8 BASE_DIR = os.path.dirname(__file__) 8 BASE_DIR = os.path.dirname(__file__)
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')
(...skipping 12 matching lines...) Expand all
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'],
33 } 33 }
34 DEFINES = [] 34 DEFINES = []
35 ADDITIONAL_PARAMS = ['-O3', '-m32', '-std=gnu++14', '--memory-init-file', '0', 35 ADDITIONAL_PARAMS = ['-O3', '-m32', '-std=gnu++14', '--memory-init-file', '0',
36 '--emit-symbol-map'] 36 '--emit-symbol-map']
37 37
38 38
39 def getenv(emscripten_path): 39 def getenv(emscripten_config):
Vasily Kuznetsov 2017/03/23 19:26:53 Instead of running `emsdk_env.sh` located at `emsc
40 path = [] 40 scope = {}
41 env = {} 41 execfile(emscripten_config, scope, scope)
42 output = subprocess.check_output([ 42 env = os.environ.copy()
43 '/bin/bash', '-c', os.path.join(emscripten_path, 'emsdk_env.sh') 43 env.update({
44 ]) 44 'EM_CONFIG': emscripten_config,
45 for line in output.splitlines(): 45 'EMSCRIPTEN': scope['EMSCRIPTEN_ROOT'],
46 match = re.search(r'^\s*PATH\s*\+=\s*(.*)', line) 46 'PYTHON': scope.get('PYTHON', sys.executable),
47 if match: 47 'NODE_JS': scope.get('NODE_JS', 'node'),
48 path.append(match.group(1)) 48 })
49 match = re.search(r'^\s*(\w+)\s*=\s*(.*)', line)
50 if match:
51 env[match.group(1)] = match.group(2)
52 env['PATH'] = os.pathsep.join([os.environ['PATH']] + path)
53 return env 49 return env
54 50
55 51
56 def generate_bindings(env): 52 def generate_bindings(env):
57 params = [ 53 params = [
58 os.path.join(env['EMSCRIPTEN'], 'emcc'), BINDINGS_FILE, 54 env['PYTHON'], os.path.join(env['EMSCRIPTEN'], 'emcc'), BINDINGS_FILE,
Vasily Kuznetsov 2017/03/23 19:26:53 We use python interpreter configured in emscripten
Wladimir Palant 2017/03/24 06:20:41 There is emcc.bat on Windows but it relies on Pyth
59 '-o', BINDINGS_GENERATOR, '-std=gnu++14', '-DPRINT_BINDINGS', 55 '-o', BINDINGS_GENERATOR, '-std=gnu++14', '-DPRINT_BINDINGS',
60 '-s', 'WARN_ON_UNDEFINED_SYMBOLS=0', 56 '-s', 'WARN_ON_UNDEFINED_SYMBOLS=0',
61 ] 57 ]
62 subprocess.check_call(params, env=env) 58 subprocess.check_call(params, env=env)
63 59
64 node = subprocess.check_output('which node', env=env, shell=True).strip()
65 with open(BINDINGS_OUTPUT, 'w') as file: 60 with open(BINDINGS_OUTPUT, 'w') as file:
66 subprocess.check_call([node, BINDINGS_GENERATOR], env=env, stdout=file) 61 subprocess.check_call([env['NODE_JS'], BINDINGS_GENERATOR],
Vasily Kuznetsov 2017/03/23 19:26:53 We use the path to node from emscripten config (de
Wladimir Palant 2017/03/24 06:20:41 The drawback here is that Emscripten comes with a
62 stdout=file)
67 63
68 64
69 def run_compiler(env, debug=False, tracing=False): 65 def run_compiler(env, debug=False, tracing=False):
70 params = [ 66 params = [
71 os.path.join(env['EMSCRIPTEN'], 'emcc'), 67 env['PYTHON'], os.path.join(env['EMSCRIPTEN'], 'emcc'),
Vasily Kuznetsov 2017/03/23 19:26:53 Again invoke python script with a python interpret
72 '-o', COMPILER_OUTPUT, 68 '-o', COMPILER_OUTPUT,
73 '--post-js', BINDINGS_OUTPUT, 69 '--post-js', BINDINGS_OUTPUT,
74 ] 70 ]
75 params.extend(SOURCE_FILES) 71 params.extend(SOURCE_FILES)
76 params.extend('-D' + flag for flag in DEFINES) 72 params.extend('-D' + flag for flag in DEFINES)
77 for key, value in GENERATION_PARAMS.iteritems(): 73 for key, value in GENERATION_PARAMS.iteritems():
78 params.extend(['-s', '{}={}'.format(key, str(value))]) 74 params.extend(['-s', '{}={}'.format(key, str(value))])
79 if debug: 75 if debug:
80 params.append('-g1') 76 params.append('-g1')
81 if tracing: 77 if tracing:
82 params.append('--tracing') 78 params.append('--tracing')
83 params.extend(ADDITIONAL_PARAMS) 79 params.extend(ADDITIONAL_PARAMS)
84 subprocess.check_call(params, env=env) 80 subprocess.check_call(params, env=env)
85 81
86 82
87 if __name__ == '__main__': 83 if __name__ == '__main__':
88 parser = argparse.ArgumentParser( 84 parser = argparse.ArgumentParser(
89 description='Compile Emscripten-based C++ code to JavaScript' 85 description='Compile Emscripten-based C++ code to JavaScript'
90 ) 86 )
91 parser.add_argument( 87 parser.add_argument(
92 '--emscripten', 88 '--emscripten-config',
Vasily Kuznetsov 2017/03/23 19:26:53 We switch to using emscripten config instead of us
Wladimir Palant 2017/03/24 06:20:41 emsdk construct_env (which is what we have been ca
93 metavar='DIR', 89 metavar='DIR',
94 default=os.path.join(BASE_DIR, '..', 'emscripten'), 90 default=os.path.expanduser('~/.emscripten'),
95 help='Emscripten installation directory' 91 help='Emscripten installation directory'
96 ) 92 )
97 parser.add_argument( 93 parser.add_argument(
98 '-d', '--debug', 94 '-d', '--debug',
99 action='store_true', 95 action='store_true',
100 help='Disable code minification' 96 help='Disable code minification'
101 ) 97 )
102 parser.add_argument( 98 parser.add_argument(
103 '-t', '--tracing', 99 '-t', '--tracing',
104 action='store_true', 100 action='store_true',
105 help='Enable memory tracing' 101 help='Enable memory tracing'
106 ) 102 )
107 args = parser.parse_args() 103 args = parser.parse_args()
108 104
109 env = getenv(args.emscripten) 105 env = getenv(args.emscripten_config)
110 generate_bindings(env) 106 generate_bindings(env)
111 run_compiler(env, debug=args.debug, tracing=args.tracing) 107 run_compiler(env, debug=args.debug, tracing=args.tracing)
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld