Skip to content

Commit c5b50fe

Browse files
authored
Fix run_gcc_tests with out-of-tree builds (#2152)
1 parent fc54b7c commit c5b50fe

1 file changed

Lines changed: 46 additions & 48 deletions

File tree

check.py

Lines changed: 46 additions & 48 deletions
Original file line numberDiff line numberDiff line change
@@ -504,55 +504,53 @@ def run_gcc_tests():
504504
print '\n[ checking native gcc testcases...]\n'
505505
if not NATIVECC or not NATIVEXX:
506506
fail_with_error('Native compiler (e.g. gcc/g++) was not found in PATH!')
507-
else:
508-
for t in sorted(os.listdir(os.path.join(options.binaryen_test, 'example'))):
509-
output_file = os.path.join(options.binaryen_bin, 'example')
510-
cmd = ['-I' + os.path.join(options.binaryen_root, 'src'), '-g', '-pthread', '-o', output_file]
511-
if t.endswith('.txt'):
512-
# check if there is a trace in the file, if so, we should build it
513-
out = subprocess.Popen([os.path.join('scripts', 'clean_c_api_trace.py'), os.path.join(options.binaryen_test, 'example', t)], stdout=subprocess.PIPE).communicate()[0]
514-
if len(out) == 0:
515-
print ' (no trace in ', t, ')'
516-
continue
517-
print ' (will check trace in ', t, ')'
518-
src = 'trace.cpp'
519-
with open(src, 'w') as o:
520-
o.write(out)
521-
expected = os.path.join(options.binaryen_test, 'example', t + '.txt')
522-
else:
523-
src = os.path.join(options.binaryen_test, 'example', t)
524-
expected = os.path.join(options.binaryen_test, 'example', '.'.join(t.split('.')[:-1]) + '.txt')
525-
if src.endswith(('.c', '.cpp')):
526-
# build the C file separately
527-
extra = [NATIVECC, src, '-c', '-o', 'example.o',
528-
'-I' + os.path.join(options.binaryen_root, 'src'), '-g', '-L' + os.path.join(options.binaryen_bin, '..', 'lib'), '-pthread']
529-
if src.endswith('.cpp'):
530-
extra += ['-std=c++11']
531-
print 'build: ', ' '.join(extra)
532-
subprocess.check_call(extra)
533-
# Link against the binaryen C library DSO, using an executable-relative rpath
534-
cmd = ['example.o', '-L' + os.path.join(options.binaryen_bin, '..', 'lib'), '-lbinaryen'] + cmd + ['-Wl,-rpath,$ORIGIN/../lib']
535-
else:
507+
return
508+
509+
for t in sorted(os.listdir(os.path.join(options.binaryen_test, 'example'))):
510+
output_file = 'example'
511+
cmd = ['-I' + os.path.join(options.binaryen_root, 'src'), '-g', '-pthread', '-o', output_file]
512+
if t.endswith('.txt'):
513+
# check if there is a trace in the file, if so, we should build it
514+
out = subprocess.Popen([os.path.join('scripts', 'clean_c_api_trace.py'), os.path.join(options.binaryen_test, 'example', t)], stdout=subprocess.PIPE).communicate()[0]
515+
if len(out) == 0:
516+
print ' (no trace in ', t, ')'
536517
continue
537-
print ' ', t, src, expected
538-
if os.environ.get('COMPILER_FLAGS'):
539-
for f in os.environ.get('COMPILER_FLAGS').split(' '):
540-
cmd.append(f)
541-
cmd = [NATIVEXX, '-std=c++11'] + cmd
542-
try:
543-
print 'link: ', ' '.join(cmd)
544-
subprocess.check_call(cmd)
545-
print 'run...', output_file
546-
proc = subprocess.Popen([output_file], stdout=subprocess.PIPE, stderr=subprocess.PIPE)
547-
actual, err = proc.communicate()
548-
assert proc.returncode == 0, [proc.returncode, actual, err]
549-
finally:
550-
os.remove(output_file)
551-
if sys.platform == 'darwin':
552-
# Also removes debug directory produced on Mac OS
553-
shutil.rmtree(output_file + '.dSYM')
554-
555-
fail_if_not_identical_to_file(actual, expected)
518+
print ' (will check trace in ', t, ')'
519+
src = 'trace.cpp'
520+
with open(src, 'w') as o:
521+
o.write(out)
522+
expected = os.path.join(options.binaryen_test, 'example', t + '.txt')
523+
else:
524+
src = os.path.join(options.binaryen_test, 'example', t)
525+
expected = os.path.join(options.binaryen_test, 'example', '.'.join(t.split('.')[:-1]) + '.txt')
526+
if src.endswith(('.c', '.cpp')):
527+
# build the C file separately
528+
libpath = os.path.join(os.path.dirname(options.binaryen_bin), 'lib')
529+
extra = [NATIVECC, src, '-c', '-o', 'example.o',
530+
'-I' + os.path.join(options.binaryen_root, 'src'), '-g', '-L' + libpath, '-pthread']
531+
if src.endswith('.cpp'):
532+
extra += ['-std=c++11']
533+
print 'build: ', ' '.join(extra)
534+
subprocess.check_call(extra)
535+
# Link against the binaryen C library DSO, using an executable-relative rpath
536+
cmd = ['example.o', '-L' + libpath, '-lbinaryen'] + cmd + ['-Wl,-rpath,' + libpath]
537+
else:
538+
continue
539+
print ' ', t, src, expected
540+
if os.environ.get('COMPILER_FLAGS'):
541+
for f in os.environ.get('COMPILER_FLAGS').split(' '):
542+
cmd.append(f)
543+
cmd = [NATIVEXX, '-std=c++11'] + cmd
544+
print 'link: ', ' '.join(cmd)
545+
subprocess.check_call(cmd)
546+
print 'run...', output_file
547+
actual = subprocess.check_output([os.path.abspath(output_file)])
548+
os.remove(output_file)
549+
if sys.platform == 'darwin':
550+
# Also removes debug directory produced on Mac OS
551+
shutil.rmtree(output_file + '.dSYM')
552+
553+
fail_if_not_identical_to_file(actual, expected)
556554

557555

558556
def run_unittest():

0 commit comments

Comments
 (0)