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

Delta Between Two Patch Sets: compile

Issue 29390650: Issue 5020 - Part 1: Make compile script PEP8-compliant (Closed) Base URL: https://hg.adblockplus.org/adblockpluscore
Left Patch Set: Created March 21, 2017, 11:22 a.m.
Right Patch Set: Fixed string formatting Created March 21, 2017, 1:32 p.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 os 3 import os
4 import re 4 import re
5 import subprocess 5 import subprocess
6 6
7 EMSCRIPTEN_PATH = '../emscripten' 7 EMSCRIPTEN_PATH = '../emscripten'
8 SOURCE_DIR = './compiled' 8 SOURCE_DIR = './compiled'
9 SOURCE_FILES = [ 9 SOURCE_FILES = [
10 os.path.join(path, f) 10 os.path.join(path, f)
11 for (path, dirs, files) in os.walk(SOURCE_DIR) 11 for (path, dirs, files) in os.walk(SOURCE_DIR)
12 for f in files 12 for f in files
13 if f.endswith('.cpp') 13 if f.endswith('.cpp')
14 ] 14 ]
15 BINDINGS_FILE = os.path.join(SOURCE_DIR, 'bindings.cpp') 15 BINDINGS_FILE = os.path.join(SOURCE_DIR, 'bindings.cpp')
16 BINDINGS_GENERATOR = os.path.join(SOURCE_DIR, 'bindings.cpp.js') 16 BINDINGS_GENERATOR = os.path.join(SOURCE_DIR, 'bindings.cpp.js')
17 BINDINGS_OUTPUT = os.path.join(SOURCE_DIR, 'bindings.js') 17 BINDINGS_OUTPUT = os.path.join(SOURCE_DIR, 'bindings.js')
18 COMPILER_OUTPUT = './lib/compiled.js' 18 COMPILER_OUTPUT = './lib/compiled.js'
19 GENERATION_PARAMS = { 19 GENERATION_PARAMS = {
20 'SHELL_FILE': "'%s'" % os.path.abspath(os.path.join(SOURCE_DIR, 20 'SHELL_FILE': "'{}'".format(os.path.abspath(os.path.join(SOURCE_DIR,
Vasily Kuznetsov 2017/03/21 13:49:35 Funnily enough here flake8-abp doesn't complain ab
21 'shell.js')), 21 'shell.js'))),
22 'ASM_JS': 2, # "almost asm" 22 'ASM_JS': 2, # "almost asm"
23 'TOTAL_MEMORY': 16*1024*1024, 23 'TOTAL_MEMORY': 16*1024*1024,
24 'TOTAL_STACK': 1*1024*1024, 24 'TOTAL_STACK': 1*1024*1024,
25 'ALLOW_MEMORY_GROWTH': 1, 25 'ALLOW_MEMORY_GROWTH': 1,
26 'NO_EXIT_RUNTIME': 1, 26 'NO_EXIT_RUNTIME': 1,
27 'NO_DYNAMIC_EXECUTION': 1, 27 'NO_DYNAMIC_EXECUTION': 1,
28 'NO_FILESYSTEM': 1, 28 'NO_FILESYSTEM': 1,
29 'INVOKE_RUN': 0, 29 'INVOKE_RUN': 0,
30 'TEXTDECODER': 0, 30 'TEXTDECODER': 0,
31 'EXPORTED_RUNTIME_METHODS': ['cwrap', 'ccall', 'stringToAscii'], 31 'EXPORTED_RUNTIME_METHODS': ['cwrap', 'ccall', 'stringToAscii'],
32 } 32 }
33 DEFINES = [] 33 DEFINES = []
34 ADDITIONAL_PARAMS = ['-O3', '-m32', '-std=gnu++14', '--memory-init-file', '0', 34 ADDITIONAL_PARAMS = ['-O3', '-m32', '-std=gnu++14', '--memory-init-file', '0',
35 '--emit-symbol-map'] 35 '--emit-symbol-map']
36 36
37 37
38 def getenv(): 38 def getenv():
39 path = [] 39 path = []
40 env = {} 40 env = {}
41 output = subprocess.check_output([ 41 output = subprocess.check_output([
42 '/bin/bash', '-c', os.path.join(EMSCRIPTEN_PATH, 'emsdk_env.sh') 42 '/bin/bash', '-c', os.path.join(EMSCRIPTEN_PATH, 'emsdk_env.sh')
Sebastian Noack 2017/03/21 12:41:01 Unrelated of coding style changes but note that su
Wladimir Palant 2017/03/21 13:33:11 While I generally dislike relying on PATH, this co
43 ]) 43 ])
44 for line in output.splitlines(): 44 for line in output.splitlines():
45 match = re.search(r'^\s*PATH\s*\+=\s*(.*)', line) 45 match = re.search(r'^\s*PATH\s*\+=\s*(.*)', line)
46 if match: 46 if match:
47 path.append(match.group(1)) 47 path.append(match.group(1))
48 match = re.search(r'^\s*(\w+)\s*=\s*(.*)', line) 48 match = re.search(r'^\s*(\w+)\s*=\s*(.*)', line)
49 if match: 49 if match:
50 env[match.group(1)] = match.group(2) 50 env[match.group(1)] = match.group(2)
51 env['PATH'] = os.pathsep.join([os.environ['PATH']] + path) 51 env['PATH'] = os.pathsep.join([os.environ['PATH']] + path)
52 return env 52 return env
(...skipping 14 matching lines...) Expand all
67 67
68 def run_compiler(env): 68 def run_compiler(env):
69 params = [ 69 params = [
70 os.path.join(env['EMSCRIPTEN'], 'emcc'), 70 os.path.join(env['EMSCRIPTEN'], 'emcc'),
71 '-o', COMPILER_OUTPUT, 71 '-o', COMPILER_OUTPUT,
72 '--post-js', BINDINGS_OUTPUT, 72 '--post-js', BINDINGS_OUTPUT,
73 ] 73 ]
74 params.extend(SOURCE_FILES) 74 params.extend(SOURCE_FILES)
75 params.extend('-D' + flag for flag in DEFINES) 75 params.extend('-D' + flag for flag in DEFINES)
76 for key, value in GENERATION_PARAMS.iteritems(): 76 for key, value in GENERATION_PARAMS.iteritems():
77 params.extend(['-s', '%s=%s' % (key, str(value))]) 77 params.extend(['-s', '{}={}'.format(key, str(value))])
Sebastian Noack 2017/03/21 12:41:01 Please use format instead of % when for string for
Wladimir Palant 2017/03/21 13:33:11 Done.
Vasily Kuznetsov 2017/03/21 13:49:35 I have done it and it only gives A107 on this line
78 params.extend(ADDITIONAL_PARAMS) 78 params.extend(ADDITIONAL_PARAMS)
79 subprocess.check_call(params, env=env) 79 subprocess.check_call(params, env=env)
80 80
81 81
82 if __name__ == '__main__': 82 if __name__ == '__main__':
83 env = getenv() 83 env = getenv()
84 generate_bindings(env) 84 generate_bindings(env)
85 run_compiler(env) 85 run_compiler(env)
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