Skip to content

Commit f043f19

Browse files
saschanazkripken
authored andcommitted
use print function (#5610)
a step towards python 3 compatibility
1 parent 331bf95 commit f043f19

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

54 files changed

+386
-332
lines changed

em-config

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,14 +11,15 @@ This tool prints the value of the variable to stdout if one
1111
is found, or exits with 1 if the variable does not exist.
1212
'''
1313

14+
from __future__ import print_function
1415
import os, sys, re
1516
from tools import shared
1617

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

23-
print eval('shared.' + sys.argv[1])
24+
print(eval('shared.' + sys.argv[1]))
2425

emar.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
This script acts as a frontend replacement for ar. See emcc.
88
'''
99

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

2728
if DEBUG:
28-
print >> sys.stderr, 'emar:', sys.argv, ' ==> ', newargs
29+
print('emar:', sys.argv, ' ==> ', newargs, file=sys.stderr)
2930

3031
if len(newargs) > 2:
3132
to_delete = []

embuilder.py

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,12 @@
44
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
55
'''
66

7+
from __future__ import print_function
78
import os, sys
89
import tools.shared as shared
910

1011
if len(sys.argv) < 2 or sys.argv[1] in ['-v', '-help', '--help', '-?', '?']:
11-
print '''
12+
print('''
1213
Emscripten System Builder Tool
1314
==============================
1415
@@ -60,7 +61,7 @@
6061
6162
and set up the location to the native optimizer in ~/.emscripten
6263
63-
'''
64+
''')
6465
sys.exit(0)
6566

6667
C_BARE = '''
@@ -127,12 +128,12 @@ def build_port(port_name, lib_name, params):
127128
tasks = [x for x in tasks if x not in skip_tasks]
128129
else:
129130
if os.environ.get('EMSCRIPTEN_NATIVE_OPTIMIZER'):
130-
print 'Skipping building of native-optimizer since environment variable EMSCRIPTEN_NATIVE_OPTIMIZER is present and set to point to a prebuilt native optimizer path.'
131+
print('Skipping building of native-optimizer since environment variable EMSCRIPTEN_NATIVE_OPTIMIZER is present and set to point to a prebuilt native optimizer path.')
131132
elif hasattr(shared, 'EMSCRIPTEN_NATIVE_OPTIMIZER'):
132-
print 'Skipping building of native-optimizer since .emscripten config file has set EMSCRIPTEN_NATIVE_OPTIMIZER to point to a prebuilt native optimizer path.'
133+
print('Skipping building of native-optimizer since .emscripten config file has set EMSCRIPTEN_NATIVE_OPTIMIZER to point to a prebuilt native optimizer path.')
133134
else:
134135
tasks += ['native_optimizer']
135-
print 'Building targets: %s' % ' '.join (tasks)
136+
print('Building targets: %s' % ' '.join(tasks))
136137
for what in tasks:
137138
shared.logging.info('building and verifying ' + what)
138139
if what == 'compiler-rt':

emcc.py

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323
EMMAKEN_COMPILER - The compiler to be used, if you don't want the default clang.
2424
'''
2525

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

331-
print '''%s
332+
print('''%s
332333
333334
------------------------------------------------------------------
334335
335336
emcc: supported targets: llvm bitcode, javascript, NOT elf
336337
(autoconf likes to see elf above to enable shared object support)
337-
''' % (open(shared.path_from_root('site', 'build', 'text', 'docs', 'tools_reference', 'emcc.txt')).read())
338+
''' % (open(shared.path_from_root('site', 'build', 'text', 'docs', 'tools_reference', 'emcc.txt')).read()))
338339
exit(0)
339340

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

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

364365
elif '-dumpmachine' in sys.argv:
365-
print shared.get_llvm_target()
366+
print(shared.get_llvm_target())
366367
exit(0)
367368

368369
elif '--cflags' in sys.argv:
@@ -377,7 +378,7 @@ def run():
377378
line = re.search('running: (.*)', lines[0]).group(1)
378379
parts = shlex.split(line.replace('\\', '\\\\'))
379380
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)
380-
print ' '.join(shared.Building.doublequote_spaces(parts[1:]))
381+
print(' '.join(shared.Building.doublequote_spaces(parts[1:])))
381382
exit(0)
382383

383384
def is_minus_s_for_emcc(newargs, i):
@@ -879,7 +880,7 @@ def check(input_file):
879880
value = '"' + value + '"'
880881
else:
881882
value = value.replace('\\', '\\\\')
882-
exec 'shared.Settings.' + key + ' = ' + value in globals(), locals()
883+
exec('shared.Settings.' + key + ' = ' + value, globals(), locals())
883884
if key == 'EXPORTED_FUNCTIONS':
884885
# used for warnings in emscripten.py
885886
shared.Settings.ORIGINAL_EXPORTED_FUNCTIONS = original_exported_response or shared.Settings.EXPORTED_FUNCTIONS[:]
@@ -2189,7 +2190,7 @@ def separate_asm_js(final, asm_target):
21892190
# extra only-my-code logic
21902191
if shared.Settings.ONLY_MY_CODE:
21912192
temp = asm_target + '.only.js'
2192-
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'))
2193+
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')))
21932194
shutil.move(temp, asm_target)
21942195

21952196

emconfigure.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
CONFIGURE_CC - see emcc
1818
'''
1919

20+
from __future__ import print_function
2021
import os, sys
2122
from tools import shared
2223
from subprocess import CalledProcessError
@@ -26,15 +27,15 @@
2627
#
2728
def run():
2829
if len(sys.argv) < 2 or ('configure' not in sys.argv[1] and 'cmake' not in sys.argv[1]):
29-
print >> sys.stderr, '''
30+
print('''
3031
emconfigure is a helper for configure, setting various environment
3132
variables so that emcc etc. are used. Typical usage:
3233
3334
emconfigure ./configure [FLAGS]
3435
3536
(but you can run any command instead of configure)
3637
37-
'''
38+
''', file=sys.stderr)
3839
elif 'cmake' in sys.argv[1]:
3940
node_js = shared.NODE_JS
4041
if type(node_js) is list: node_js = node_js[0]

emlink.py

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
See https://github.com/kripken/emscripten/wiki/Linking
77
'''
88

9+
from __future__ import print_function
910
import sys
1011
from tools import shared
1112
from tools.asm_module import AsmModule
@@ -14,12 +15,12 @@ def run():
1415
try:
1516
me, main, side, out = sys.argv[:4]
1617
except:
17-
print >> sys.stderr, 'usage: emlink.py [main module] [side module] [output name]'
18+
print('usage: emlink.py [main module] [side module] [output name]', file=sys.stderr)
1819
sys.exit(1)
1920

20-
print 'Main module:', main
21-
print 'Side module:', side
22-
print 'Output:', out
21+
print('Main module:', main)
22+
print('Side module:', side)
23+
print('Output:', out)
2324

2425
shared.try_delete(out)
2526

emmake.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
generate JavaScript.
1919
'''
2020

21+
from __future__ import print_function
2122
import os, sys
2223
from tools import shared
2324
from subprocess import CalledProcessError
@@ -27,15 +28,15 @@
2728
#
2829
def run():
2930
if len(sys.argv) < 2 or sys.argv[1] != 'make':
30-
print >> sys.stderr, '''
31+
print('''
3132
emmake is a helper for make, setting various environment
3233
variables so that emcc etc. are used. Typical usage:
3334
3435
emmake make [FLAGS]
3536
3637
(but you can run any command instead of make)
3738
38-
'''
39+
''', file=sys.stderr)
3940

4041
try:
4142
shared.Building.make(sys.argv[1:])

tools/asm_module.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11

2+
from __future__ import print_function
23
import sys, re, itertools
34

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

tools/autodebugger.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
there may be weird errors.
99
'''
1010

11+
from __future__ import print_function
1112
import os, sys, re
1213

1314
ALLOW_POINTERS = True
@@ -264,5 +265,5 @@
264265
f.write(ll[:meta_start] + '\n' + POSTAMBLE + '\n' + ll[meta_start:])
265266
f.close()
266267

267-
print 'Success.'
268+
print('Success.')
268269

tools/autodebugger_c.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,11 +5,12 @@
55
overwrite the files it is given!
66
'''
77

8+
from __future__ import print_function
89
import os, sys, re
910

1011
filenames = sys.argv[1:]
1112
for filename in filenames:
12-
print '..%s..' % filename
13+
print('..%s..' % filename)
1314

1415
f = open(filename, 'r')
1516
data = f.read()
@@ -33,5 +34,5 @@
3334
f.write('\n'.join(lines))
3435
f.close()
3536

36-
print 'Success.'
37+
print('Success.')
3738

tools/autodebugger_indenter.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
This script will indent the output nicely
44
'''
55

6+
from __future__ import print_function
67
import os, sys
78

89
lines = sys.stdin.read().split('\n')
@@ -12,7 +13,7 @@
1213
line = lines[i]
1314
if line.startswith('AD:-2,'):
1415
depth -= 1
15-
print str(depth) + '|' + line
16+
print(str(depth) + '|' + line)
1617
if line.startswith('AD:-1,'):
1718
depth += 1
1819

tools/autodebugger_js.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
Similar to autodebugger.py, but runs on .js files.
55
'''
66

7+
from __future__ import print_function
78
import os, sys, re
89

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

44-
print '\n'.join(lines)
45+
print('\n'.join(lines))
4546

46-
print >> sys.stderr, 'Success.'
47+
print('Success.', file=sys.stderr)
4748

tools/autodediffer.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
Run it with filenames of two autodebugger logs as parameters
55
'''
66

7+
from __future__ import print_function
78
import os, sys
89

910

@@ -54,7 +55,7 @@ def process_line(line):
5455
assert av[0] == bv[0]
5556
diff = abs(av[1] - bv[1])
5657
if diff > MIN:
57-
print '<<%d %d>> %d : %.5f' % (ai, bi, av[0], diff)
58+
print('<<%d %d>> %d : %.5f' % (ai, bi, av[0], diff))
5859
ai += 1
5960
bi += 1
6061

0 commit comments

Comments
 (0)