Skip to content

Commit e57fd75

Browse files
authored
Add more error checking in nativize_llvm.py and its test code (emscripten-core#6408)
This test doesn't on my linux box, but these changes at least make it fail earlier so its more clear what is happening.
1 parent 120602f commit e57fd75

2 files changed

Lines changed: 10 additions & 11 deletions

File tree

tests/test_other.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2151,7 +2151,7 @@ def test_llvm_nativizer(self):
21512151
open(os.path.join(self.get_dir(), 'test.file'), 'w').write('''ay file..............,,,,,,,,,,,,,,''')
21522152
open(os.path.join(self.get_dir(), 'stdin'), 'w').write('''inter-active''')
21532153
subprocess.check_call([PYTHON, EMCC, os.path.join(self.get_dir(), 'files.cpp'), '-c'])
2154-
run_process([PYTHON, path_from_root('tools', 'nativize_llvm.py'), os.path.join(self.get_dir(), 'files.o')], stdout=PIPE)
2154+
subprocess.check_call([PYTHON, path_from_root('tools', 'nativize_llvm.py'), os.path.join(self.get_dir(), 'files.o')])
21552155
output = run_process([os.path.join(self.get_dir(), 'files.o.run')], stdin=open(os.path.join(self.get_dir(), 'stdin')), stdout=PIPE, stderr=PIPE)
21562156
self.assertContained('''size: 37
21572157
data: 119,97,107,97,32,119,97,107,97,35,35,35,35,35,35,35,35,35,35,35,35,35,35,35,35,35,35,35,35,35,35,35,35,35,35,35,35

tools/nativize_llvm.py

Lines changed: 9 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,15 @@
11
#!/usr/bin/env python2
2-
3-
'''
4-
Small utility to build some llvm bitcode into native code. Useful when lli (called
5-
from exec_llvm) fails for some reason.
2+
"""Small utility to build some llvm bitcode into native code. Useful when lli
3+
(called from exec_llvm) fails for some reason.
64
75
* Use llc to generate x86 asm
86
* Use as to generate an object file
97
* Use g++ to link it to an executable
10-
'''
8+
"""
119

1210
from __future__ import print_function
1311
import os, sys
14-
from subprocess import Popen, PIPE, STDOUT
12+
from subprocess import call, check_call, PIPE, STDOUT
1513

1614
sys.path.insert(1, os.path.dirname(os.path.dirname(os.path.abspath(__file__))))
1715

@@ -25,14 +23,14 @@ def path_from_root(*pathelems):
2523
libs = sys.argv[2:] # e.g.: dl for dlopen/dlclose, util for openpty/forkpty
2624

2725
print('bc => clean bc')
28-
Popen([LLVM_OPT, filename, '-strip-debug', '-o', filename + '.clean.bc']).communicate()[0]
26+
check_call([LLVM_OPT, filename, '-strip-debug', '-o', filename + '.clean.bc'])
2927
print('bc => s')
3028
for params in [['-march=x86'], ['-march=x86-64']]: # try x86, then x86-64 FIXME
3129
print('params', params)
3230
for triple in [['-mtriple=i386-pc-linux-gnu'], []]:
33-
Popen([LLVM_COMPILER] + params + triple + [filename + '.clean.bc', '-o', filename + '.s']).communicate()[0]
31+
call([LLVM_COMPILER] + params + triple + [filename + '.clean.bc', '-o', filename + '.s'])
3432
print('s => o')
35-
Popen(['as', filename + '.s', '-o', filename + '.o']).communicate()[0]
33+
call(['as', filename + '.s', '-o', filename + '.o'])
3634
if os.path.exists(filename + '.o'): break
3735
if os.path.exists(filename + '.o'): break
3836

@@ -41,5 +39,6 @@ def path_from_root(*pathelems):
4139
sys.exit(1)
4240

4341
print('o => runnable')
44-
Popen(['g++', path_from_root('system', 'lib', 'debugging.cpp'), filename + '.o', '-o', filename + '.run'] + ['-l' + lib for lib in libs]).communicate()[0]
42+
check_call(['g++', path_from_root('system', 'lib', 'debugging.cpp'), filename + '.o', '-o', filename + '.run'] + ['-l' + lib for lib in libs])
4543

44+
sys.exit(0)

0 commit comments

Comments
 (0)