Skip to content

Commit db18594

Browse files
committed
support -include-pch flag #4086
1 parent fa2729d commit db18594

File tree

2 files changed

+34
-23
lines changed

2 files changed

+34
-23
lines changed

emcc.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -771,7 +771,7 @@ def validate_arg_level(level_string, max_level, err_msg):
771771

772772
if i > 0:
773773
prev = newargs[i-1]
774-
if prev in ['-MT', '-MF', '-MQ', '-D', '-U', '-o', '-x', '-Xpreprocessor', '-include', '-imacros', '-idirafter', '-iprefix', '-iwithprefix', '-iwithprefixbefore', '-isysroot', '-imultilib', '-A', '-isystem', '-iquote', '-install_name', '-compatibility_version', '-current_version', '-I', '-L']: continue # ignore this gcc-style argument
774+
if prev in ['-MT', '-MF', '-MQ', '-D', '-U', '-o', '-x', '-Xpreprocessor', '-include', '-imacros', '-idirafter', '-iprefix', '-iwithprefix', '-iwithprefixbefore', '-isysroot', '-imultilib', '-A', '-isystem', '-iquote', '-install_name', '-compatibility_version', '-current_version', '-I', '-L', '-include-pch']: continue # ignore this gcc-style argument
775775

776776
if os.path.islink(arg) and os.path.realpath(arg).endswith(SOURCE_ENDINGS + BITCODE_ENDINGS + DYNAMICLIB_ENDINGS + ASSEMBLY_ENDINGS + HEADER_ENDINGS):
777777
arg = os.path.realpath(arg)

tests/test_other.py

+33-22
Original file line numberDiff line numberDiff line change
@@ -2540,36 +2540,47 @@ def test_module_print(self):
25402540
assert r'<{(123456789)}>' in output, output
25412541

25422542
def test_precompiled_headers(self):
2543-
self.clear()
2543+
for suffix in ['gch', 'pch']:
2544+
print suffix
2545+
self.clear()
25442546

2545-
open('header.h', 'w').write('#define X 5\n')
2546-
Popen([PYTHON, EMCC, '-xc++-header', 'header.h', '-c']).communicate()
2547-
assert os.path.exists('header.h.gch')
2547+
open('header.h', 'w').write('#define X 5\n')
2548+
Popen([PYTHON, EMCC, '-xc++-header', 'header.h', '-c']).communicate()
2549+
assert os.path.exists('header.h.gch') # default output is gch
2550+
if suffix != 'gch':
2551+
Popen([PYTHON, EMCC, '-xc++-header', 'header.h', '-o', 'header.h.' + suffix]).communicate()
2552+
assert open('header.h.gch').read() == open('header.h.' + suffix).read()
25482553

2549-
open('src.cpp', 'w').write(r'''
2554+
open('src.cpp', 'w').write(r'''
25502555
#include <stdio.h>
25512556
int main() {
25522557
printf("|%d|\n", X);
25532558
return 0;
25542559
}
25552560
''')
2556-
Popen([PYTHON, EMCC, 'src.cpp', '-include', 'header.h']).communicate()
2557-
2558-
output = run_js(self.in_dir('a.out.js'), stderr=PIPE, full_output=True, engine=NODE_JS)
2559-
assert '|5|' in output, output
2560-
2561-
# also verify that the gch is actually used
2562-
err = Popen([PYTHON, EMCC, 'src.cpp', '-include', 'header.h', '-Xclang', '-print-stats'], stderr=PIPE).communicate()
2563-
self.assertTextDataContained('*** PCH/Modules Loaded:\nModule: header.h.gch', err[1])
2564-
# and sanity check it is not mentioned when not
2565-
try_delete('header.h.gch')
2566-
err = Popen([PYTHON, EMCC, 'src.cpp', '-include', 'header.h', '-Xclang', '-print-stats'], stderr=PIPE).communicate()
2567-
assert '*** PCH/Modules Loaded:\nModule: header.h.gch' not in err[1].replace('\r\n', '\n'), err[1]
2568-
2569-
# with specified target via -o
2570-
try_delete('header.h.gch')
2571-
Popen([PYTHON, EMCC, '-xc++-header', 'header.h', '-o', 'my.gch']).communicate()
2572-
assert os.path.exists('my.gch')
2561+
Popen([PYTHON, EMCC, 'src.cpp', '-include', 'header.h']).communicate()
2562+
2563+
output = run_js(self.in_dir('a.out.js'), stderr=PIPE, full_output=True, engine=NODE_JS)
2564+
assert '|5|' in output, output
2565+
2566+
# also verify that the gch is actually used
2567+
err = Popen([PYTHON, EMCC, 'src.cpp', '-include', 'header.h', '-Xclang', '-print-stats'], stderr=PIPE).communicate()
2568+
self.assertTextDataContained('*** PCH/Modules Loaded:\nModule: header.h.' + suffix, err[1])
2569+
# and sanity check it is not mentioned when not
2570+
try_delete('header.h.' + suffix)
2571+
err = Popen([PYTHON, EMCC, 'src.cpp', '-include', 'header.h', '-Xclang', '-print-stats'], stderr=PIPE).communicate()
2572+
assert '*** PCH/Modules Loaded:\nModule: header.h.' + suffix not in err[1].replace('\r\n', '\n'), err[1]
2573+
2574+
# with specified target via -o
2575+
try_delete('header.h.' + suffix)
2576+
Popen([PYTHON, EMCC, '-xc++-header', 'header.h', '-o', 'my.' + suffix]).communicate()
2577+
assert os.path.exists('my.' + suffix)
2578+
2579+
# -include-pch flag
2580+
Popen([PYTHON, EMCC, '-xc++-header', 'header.h', '-o', 'header.h.' + suffix]).communicate()
2581+
check_execute([PYTHON, EMCC, 'src.cpp', '-include-pch', 'header.h.' + suffix])
2582+
output = run_js('a.out.js')
2583+
assert '|5|' in output, output
25732584

25742585
def test_warn_unaligned(self):
25752586
open('src.cpp', 'w').write(r'''

0 commit comments

Comments
 (0)