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

Unified Diff: compile

Issue 29390650: Issue 5020 - Part 1: Make compile script PEP8-compliant (Closed) Base URL: https://hg.adblockplus.org/adblockpluscore
Patch Set: Fixed string formatting Created March 21, 2017, 1:32 p.m.
Use n/p to move between diff chunks; N/P to move between comments.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: compile
===================================================================
--- a/compile
+++ b/compile
@@ -1,80 +1,85 @@
#!/usr/bin/env python
-import json
import os
import re
import subprocess
-import warnings
EMSCRIPTEN_PATH = '../emscripten'
SOURCE_DIR = './compiled'
SOURCE_FILES = [
- os.path.join(path, f)
- for (path, dirs, files) in os.walk(SOURCE_DIR)
- for f in files
- if f.endswith('.cpp')
+ os.path.join(path, f)
+ for (path, dirs, files) in os.walk(SOURCE_DIR)
+ for f in files
+ if f.endswith('.cpp')
]
BINDINGS_FILE = os.path.join(SOURCE_DIR, 'bindings.cpp')
BINDINGS_GENERATOR = os.path.join(SOURCE_DIR, 'bindings.cpp.js')
BINDINGS_OUTPUT = os.path.join(SOURCE_DIR, 'bindings.js')
COMPILER_OUTPUT = './lib/compiled.js'
GENERATION_PARAMS = {
- 'SHELL_FILE': "'%s'" % os.path.abspath(os.path.join(SOURCE_DIR, 'shell.js')),
- 'ASM_JS': 2, # "almost asm"
- 'TOTAL_MEMORY': 16*1024*1024,
- 'TOTAL_STACK': 1*1024*1024,
- 'ALLOW_MEMORY_GROWTH': 1,
- 'NO_EXIT_RUNTIME': 1,
- 'NO_DYNAMIC_EXECUTION': 1,
- 'NO_FILESYSTEM': 1,
- 'INVOKE_RUN': 0,
- 'TEXTDECODER': 0,
- 'EXPORTED_RUNTIME_METHODS': ['cwrap', 'ccall', 'stringToAscii'],
+ 'SHELL_FILE': "'{}'".format(os.path.abspath(os.path.join(SOURCE_DIR,
+ 'shell.js'))),
+ 'ASM_JS': 2, # "almost asm"
+ 'TOTAL_MEMORY': 16*1024*1024,
+ 'TOTAL_STACK': 1*1024*1024,
+ 'ALLOW_MEMORY_GROWTH': 1,
+ 'NO_EXIT_RUNTIME': 1,
+ 'NO_DYNAMIC_EXECUTION': 1,
+ 'NO_FILESYSTEM': 1,
+ 'INVOKE_RUN': 0,
+ 'TEXTDECODER': 0,
+ 'EXPORTED_RUNTIME_METHODS': ['cwrap', 'ccall', 'stringToAscii'],
}
DEFINES = []
ADDITIONAL_PARAMS = ['-O3', '-m32', '-std=gnu++14', '--memory-init-file', '0',
- '--emit-symbol-map']
+ '--emit-symbol-map']
+
def getenv():
- path = []
- env = {}
- output = subprocess.check_output([
- '/bin/bash', '-c', os.path.join(EMSCRIPTEN_PATH, 'emsdk_env.sh')])
- for line in output.splitlines():
- match = re.search(r'^\s*PATH\s*\+=\s*(.*)', line)
- if match:
- path.append(match.group(1))
- match = re.search(r'^\s*(\w+)\s*=\s*(.*)', line)
- if match:
- env[match.group(1)] = match.group(2)
- env['PATH'] = os.pathsep.join([os.environ['PATH']] + path)
- return env
+ path = []
+ env = {}
+ output = subprocess.check_output([
+ '/bin/bash', '-c', os.path.join(EMSCRIPTEN_PATH, 'emsdk_env.sh')
+ ])
+ for line in output.splitlines():
+ match = re.search(r'^\s*PATH\s*\+=\s*(.*)', line)
+ if match:
+ path.append(match.group(1))
+ match = re.search(r'^\s*(\w+)\s*=\s*(.*)', line)
+ if match:
+ env[match.group(1)] = match.group(2)
+ env['PATH'] = os.pathsep.join([os.environ['PATH']] + path)
+ return env
+
def generate_bindings(env):
- params = [os.path.join(env['EMSCRIPTEN'], 'emcc'), BINDINGS_FILE,
- '-o', BINDINGS_GENERATOR, '-std=gnu++14', '-DPRINT_BINDINGS',
- '-s', 'WARN_ON_UNDEFINED_SYMBOLS=0',
- ]
- subprocess.check_call(params, env=env)
+ params = [
+ os.path.join(env['EMSCRIPTEN'], 'emcc'), BINDINGS_FILE,
+ '-o', BINDINGS_GENERATOR, '-std=gnu++14', '-DPRINT_BINDINGS',
+ '-s', 'WARN_ON_UNDEFINED_SYMBOLS=0',
+ ]
+ subprocess.check_call(params, env=env)
- node = subprocess.check_output('which node', env=env, shell=True).strip();
- with open(BINDINGS_OUTPUT, 'w') as file:
- subprocess.check_call([node, BINDINGS_GENERATOR], env=env, stdout=file)
+ node = subprocess.check_output('which node', env=env, shell=True).strip()
+ with open(BINDINGS_OUTPUT, 'w') as file:
+ subprocess.check_call([node, BINDINGS_GENERATOR], env=env, stdout=file)
+
def run_compiler(env):
- params = [
- os.path.join(env['EMSCRIPTEN'], 'emcc'),
- '-o', COMPILER_OUTPUT,
- '--post-js', BINDINGS_OUTPUT,
- ]
- params.extend(SOURCE_FILES)
- params.extend('-D' + flag for flag in DEFINES)
- for key, value in GENERATION_PARAMS.iteritems():
- params.extend(['-s', '%s=%s' % (key, str(value))])
- params.extend(ADDITIONAL_PARAMS)
- subprocess.check_call(params, env=env)
+ params = [
+ os.path.join(env['EMSCRIPTEN'], 'emcc'),
+ '-o', COMPILER_OUTPUT,
+ '--post-js', BINDINGS_OUTPUT,
+ ]
+ params.extend(SOURCE_FILES)
+ params.extend('-D' + flag for flag in DEFINES)
+ for key, value in GENERATION_PARAMS.iteritems():
+ params.extend(['-s', '{}={}'.format(key, str(value))])
+ params.extend(ADDITIONAL_PARAMS)
+ subprocess.check_call(params, env=env)
+
if __name__ == '__main__':
- env = getenv()
- generate_bindings(env)
- run_compiler(env)
+ env = getenv()
+ generate_bindings(env)
+ run_compiler(env)
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld