Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Python 3 compatibility: Use print() function #5610

Merged
merged 1 commit into from
Oct 16, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions em-config
Original file line number Diff line number Diff line change
Expand Up @@ -11,14 +11,15 @@ This tool prints the value of the variable to stdout if one
is found, or exits with 1 if the variable does not exist.
'''

from __future__ import print_function
import os, sys, re
from tools import shared

if len(sys.argv) != 2 or \
not re.match(r"^[\w\W_][\w\W_\d]*$", sys.argv[1]) or \
not (sys.argv[1] in dir(shared)):
print 'Usage: em-config VAR_NAME'
print('Usage: em-config VAR_NAME')
exit(1)

print eval('shared.' + sys.argv[1])
print(eval('shared.' + sys.argv[1]))

3 changes: 2 additions & 1 deletion emar.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
This script acts as a frontend replacement for ar. See emcc.
'''

from __future__ import print_function
from tools.toolchain_profiler import ToolchainProfiler
if __name__ == '__main__':
ToolchainProfiler.record_process_start()
Expand All @@ -25,7 +26,7 @@ def run():
newargs = [shared.LLVM_AR] + sys.argv[1:]

if DEBUG:
print >> sys.stderr, 'emar:', sys.argv, ' ==> ', newargs
print('emar:', sys.argv, ' ==> ', newargs, file=sys.stderr)

if len(newargs) > 2:
to_delete = []
Expand Down
11 changes: 6 additions & 5 deletions embuilder.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,12 @@
Tool to manage building of various useful things, such as libc, libc++, native optimizer, as well as fetch and build ports like zlib and sdl2
'''

from __future__ import print_function
import os, sys
import tools.shared as shared

if len(sys.argv) < 2 or sys.argv[1] in ['-v', '-help', '--help', '-?', '?']:
print '''
print('''
Emscripten System Builder Tool
==============================

Expand Down Expand Up @@ -60,7 +61,7 @@

and set up the location to the native optimizer in ~/.emscripten

'''
''')
sys.exit(0)

C_BARE = '''
Expand Down Expand Up @@ -127,12 +128,12 @@ def build_port(port_name, lib_name, params):
tasks = [x for x in tasks if x not in skip_tasks]
else:
if os.environ.get('EMSCRIPTEN_NATIVE_OPTIMIZER'):
print 'Skipping building of native-optimizer since environment variable EMSCRIPTEN_NATIVE_OPTIMIZER is present and set to point to a prebuilt native optimizer path.'
print('Skipping building of native-optimizer since environment variable EMSCRIPTEN_NATIVE_OPTIMIZER is present and set to point to a prebuilt native optimizer path.')
elif hasattr(shared, 'EMSCRIPTEN_NATIVE_OPTIMIZER'):
print 'Skipping building of native-optimizer since .emscripten config file has set EMSCRIPTEN_NATIVE_OPTIMIZER to point to a prebuilt native optimizer path.'
print('Skipping building of native-optimizer since .emscripten config file has set EMSCRIPTEN_NATIVE_OPTIMIZER to point to a prebuilt native optimizer path.')
else:
tasks += ['native_optimizer']
print 'Building targets: %s' % ' '.join (tasks)
print('Building targets: %s' % ' '.join(tasks))
for what in tasks:
shared.logging.info('building and verifying ' + what)
if what == 'compiler-rt':
Expand Down
19 changes: 10 additions & 9 deletions emcc.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
EMMAKEN_COMPILER - The compiler to be used, if you don't want the default clang.
'''

from __future__ import print_function
from tools.toolchain_profiler import ToolchainProfiler, exit
if __name__ == '__main__':
ToolchainProfiler.record_process_start()
Expand Down Expand Up @@ -328,13 +329,13 @@ def run():
# An online HTML version (which may be of a different version of Emscripten)
# is up at http://kripken.github.io/emscripten-site/docs/tools_reference/emcc.html

print '''%s
print('''%s

------------------------------------------------------------------

emcc: supported targets: llvm bitcode, javascript, NOT elf
(autoconf likes to see elf above to enable shared object support)
''' % (open(shared.path_from_root('site', 'build', 'text', 'docs', 'tools_reference', 'emcc.txt')).read())
''' % (open(shared.path_from_root('site', 'build', 'text', 'docs', 'tools_reference', 'emcc.txt')).read()))
exit(0)

elif sys.argv[1] == '--version':
Expand All @@ -347,22 +348,22 @@ def run():
pass
finally:
os.chdir(here)
print '''emcc (Emscripten gcc/clang-like replacement) %s (%s)
print('''emcc (Emscripten gcc/clang-like replacement) %s (%s)
Copyright (C) 2014 the Emscripten authors (see AUTHORS.txt)
This is free and open source software under the MIT license.
There is NO warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
''' % (shared.EMSCRIPTEN_VERSION, revision)
''' % (shared.EMSCRIPTEN_VERSION, revision))
exit(0)

elif len(sys.argv) == 2 and sys.argv[1] == '-v': # -v with no inputs
# autoconf likes to see 'GNU' in the output to enable shared object support
print 'emcc (Emscripten gcc/clang-like replacement + linker emulating GNU ld) %s' % shared.EMSCRIPTEN_VERSION
print('emcc (Emscripten gcc/clang-like replacement + linker emulating GNU ld) %s' % shared.EMSCRIPTEN_VERSION)
code = subprocess.call([shared.CLANG, '-v'])
shared.check_sanity(force=True)
exit(code)

elif '-dumpmachine' in sys.argv:
print shared.get_llvm_target()
print(shared.get_llvm_target())
exit(0)

elif '--cflags' in sys.argv:
Expand All @@ -377,7 +378,7 @@ def run():
line = re.search('running: (.*)', lines[0]).group(1)
parts = shlex.split(line.replace('\\', '\\\\'))
parts = filter(lambda x: x != '-c' and x != '-o' and input_file not in x and temp_target not in x and '-emit-llvm' not in x, parts)
print ' '.join(shared.Building.doublequote_spaces(parts[1:]))
print(' '.join(shared.Building.doublequote_spaces(parts[1:])))
exit(0)

def is_minus_s_for_emcc(newargs, i):
Expand Down Expand Up @@ -879,7 +880,7 @@ def check(input_file):
value = '"' + value + '"'
else:
value = value.replace('\\', '\\\\')
exec 'shared.Settings.' + key + ' = ' + value in globals(), locals()
exec('shared.Settings.' + key + ' = ' + value, globals(), locals())
if key == 'EXPORTED_FUNCTIONS':
# used for warnings in emscripten.py
shared.Settings.ORIGINAL_EXPORTED_FUNCTIONS = original_exported_response or shared.Settings.EXPORTED_FUNCTIONS[:]
Expand Down Expand Up @@ -2189,7 +2190,7 @@ def separate_asm_js(final, asm_target):
# extra only-my-code logic
if shared.Settings.ONLY_MY_CODE:
temp = asm_target + '.only.js'
print jsrun.run_js(shared.path_from_root('tools', 'js-optimizer.js'), shared.NODE_JS, args=[asm_target, 'eliminateDeadGlobals', 'last', 'asm'], stdout=open(temp, 'w'))
print(jsrun.run_js(shared.path_from_root('tools', 'js-optimizer.js'), shared.NODE_JS, args=[asm_target, 'eliminateDeadGlobals', 'last', 'asm'], stdout=open(temp, 'w')))
shutil.move(temp, asm_target)


Expand Down
5 changes: 3 additions & 2 deletions emconfigure.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
CONFIGURE_CC - see emcc
'''

from __future__ import print_function
import os, sys
from tools import shared
from subprocess import CalledProcessError
Expand All @@ -26,15 +27,15 @@
#
def run():
if len(sys.argv) < 2 or ('configure' not in sys.argv[1] and 'cmake' not in sys.argv[1]):
print >> sys.stderr, '''
print('''
emconfigure is a helper for configure, setting various environment
variables so that emcc etc. are used. Typical usage:

emconfigure ./configure [FLAGS]

(but you can run any command instead of configure)

'''
''', file=sys.stderr)
elif 'cmake' in sys.argv[1]:
node_js = shared.NODE_JS
if type(node_js) is list: node_js = node_js[0]
Expand Down
9 changes: 5 additions & 4 deletions emlink.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
See https://github.com/kripken/emscripten/wiki/Linking
'''

from __future__ import print_function
import sys
from tools import shared
from tools.asm_module import AsmModule
Expand All @@ -14,12 +15,12 @@ def run():
try:
me, main, side, out = sys.argv[:4]
except:
print >> sys.stderr, 'usage: emlink.py [main module] [side module] [output name]'
print('usage: emlink.py [main module] [side module] [output name]', file=sys.stderr)
sys.exit(1)

print 'Main module:', main
print 'Side module:', side
print 'Output:', out
print('Main module:', main)
print('Side module:', side)
print('Output:', out)

shared.try_delete(out)

Expand Down
5 changes: 3 additions & 2 deletions emmake.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
generate JavaScript.
'''

from __future__ import print_function
import os, sys
from tools import shared
from subprocess import CalledProcessError
Expand All @@ -27,15 +28,15 @@
#
def run():
if len(sys.argv) < 2 or sys.argv[1] != 'make':
print >> sys.stderr, '''
print('''
emmake is a helper for make, setting various environment
variables so that emcc etc. are used. Typical usage:

emmake make [FLAGS]

(but you can run any command instead of make)

'''
''', file=sys.stderr)

try:
shared.Building.make(sys.argv[1:])
Expand Down
3 changes: 2 additions & 1 deletion tools/asm_module.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@

from __future__ import print_function
import sys, re, itertools

import shared, js_optimizer
Expand Down Expand Up @@ -138,7 +139,7 @@ def relocate_into(self, main):
def check_import(key, value):
if value.startswith('+') or value.endswith('|0'): # ignore functions
if key not in all_sendings:
print >> sys.stderr, 'warning: external variable %s is still not defined after linking' % key
print('warning: external variable %s is still not defined after linking' % key, file=sys.stderr)
all_sendings[key] = '0'
for key, value in all_imports.iteritems(): check_import(key, value)

Expand Down
3 changes: 2 additions & 1 deletion tools/autodebugger.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
there may be weird errors.
'''

from __future__ import print_function
import os, sys, re

ALLOW_POINTERS = True
Expand Down Expand Up @@ -264,5 +265,5 @@
f.write(ll[:meta_start] + '\n' + POSTAMBLE + '\n' + ll[meta_start:])
f.close()

print 'Success.'
print('Success.')

5 changes: 3 additions & 2 deletions tools/autodebugger_c.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,12 @@
overwrite the files it is given!
'''

from __future__ import print_function
import os, sys, re

filenames = sys.argv[1:]
for filename in filenames:
print '..%s..' % filename
print('..%s..' % filename)

f = open(filename, 'r')
data = f.read()
Expand All @@ -33,5 +34,5 @@
f.write('\n'.join(lines))
f.close()

print 'Success.'
print('Success.')

3 changes: 2 additions & 1 deletion tools/autodebugger_indenter.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
This script will indent the output nicely
'''

from __future__ import print_function
import os, sys

lines = sys.stdin.read().split('\n')
Expand All @@ -12,7 +13,7 @@
line = lines[i]
if line.startswith('AD:-2,'):
depth -= 1
print str(depth) + '|' + line
print(str(depth) + '|' + line)
if line.startswith('AD:-1,'):
depth += 1

5 changes: 3 additions & 2 deletions tools/autodebugger_js.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
Similar to autodebugger.py, but runs on .js files.
'''

from __future__ import print_function
import os, sys, re

filename = sys.argv[1]
Expand Down Expand Up @@ -41,7 +42,7 @@
left, right = lines[i].split(' = ')
lines[i] += ''' print("%s = " + %s);''' % (left, left)

print '\n'.join(lines)
print('\n'.join(lines))

print >> sys.stderr, 'Success.'
print('Success.', file=sys.stderr)

3 changes: 2 additions & 1 deletion tools/autodediffer.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
Run it with filenames of two autodebugger logs as parameters
'''

from __future__ import print_function
import os, sys


Expand Down Expand Up @@ -54,7 +55,7 @@ def process_line(line):
assert av[0] == bv[0]
diff = abs(av[1] - bv[1])
if diff > MIN:
print '<<%d %d>> %d : %.5f' % (ai, bi, av[0], diff)
print('<<%d %d>> %d : %.5f' % (ai, bi, av[0], diff))
ai += 1
bi += 1

Loading