Handle '-M' and '-MM' compiler flags similar to '-E'.
This commit is contained in:
Родитель
90fc015941
Коммит
b294035510
17
emcc
17
emcc
|
@ -221,7 +221,7 @@ if CONFIGURE_CONFIG or CMAKE_CONFIG:
|
|||
elif arg.endswith('.s'):
|
||||
if debug_configure: open(tempout, 'a').write('(compiling .s assembly, must use clang\n')
|
||||
if use_js == 1: use_js = 0
|
||||
elif arg == '-E':
|
||||
elif arg == '-E' or arg == '-M' or arg == '-MM':
|
||||
if use_js == 1: use_js = 0
|
||||
|
||||
if src:
|
||||
|
@ -330,12 +330,6 @@ for i in range(1, len(sys.argv)):
|
|||
if arg.endswith(C_ENDINGS + OBJC_ENDINGS):
|
||||
use_cxx = False
|
||||
|
||||
if '-M' in sys.argv or '-MM' in sys.argv:
|
||||
# Just output dependencies, do not compile. Warning: clang and gcc behave differently with -MF! (clang seems to not recognize it)
|
||||
cmd = [CC] + shared.COMPILER_OPTS + sys.argv[1:]
|
||||
logging.debug('just dependencies: ' + ' '.join(cmd))
|
||||
exit(subprocess.call(cmd))
|
||||
|
||||
# Check if a target is specified
|
||||
target = None
|
||||
for i in range(len(sys.argv)-1):
|
||||
|
@ -819,7 +813,9 @@ try:
|
|||
target = target_basename + '.o'
|
||||
final_suffix = 'o'
|
||||
if '-E' in newargs:
|
||||
final_suffix = 'eout' # not bitcode, not js; something else
|
||||
final_suffix = 'eout' # not bitcode, not js; but just result from preprocessing stage of the input file
|
||||
if '-M' in newargs or '-MM' in newargs:
|
||||
final_suffix = 'mout' # not bitcode, not js; but just dependency rule of the input file
|
||||
final_ending = ('.' + final_suffix) if len(final_suffix) > 0 else ''
|
||||
|
||||
# Find library files
|
||||
|
@ -1077,12 +1073,13 @@ try:
|
|||
return args
|
||||
|
||||
# -E preprocessor-only support
|
||||
if '-E' in newargs:
|
||||
if '-E' in newargs or '-M' in newargs or '-MM' in newargs:
|
||||
input_files = map(lambda x: x[1], input_files)
|
||||
cmd = get_bitcode_args(input_files)
|
||||
if specified_target:
|
||||
cmd += ['-o', specified_target]
|
||||
logging.debug('just preprocessor ' + ' '.join(cmd))
|
||||
# Do not compile, but just output the result from preprocessing stage or output the dependency rule. Warning: clang and gcc behave differently with -MF! (clang seems to not recognize it)
|
||||
logging.debug(('just preprocessor ' if '-E' in newargs else 'just dependencies: ') + ' '.join(cmd))
|
||||
exit(subprocess.call(cmd))
|
||||
|
||||
# First, generate LLVM bitcode. For each input file, we get base.o with bitcode
|
||||
|
|
|
@ -3323,6 +3323,28 @@ EMSCRIPTEN_KEEPALIVE __EMSCRIPTEN_major__ __EMSCRIPTEN_minor__ __EMSCRIPTEN_tiny
|
|||
assert len(with_dash_o) == 0
|
||||
assert len(without_dash_o) != 0
|
||||
|
||||
def test_dashM(self):
|
||||
out = Popen([PYTHON, EMXX, path_from_root('tests', 'hello_world.cpp'), '-M'], stdout=PIPE).communicate()[0]
|
||||
self.assertContained('hello_world.o:', out) # Verify output is just a dependency rule instead of bitcode or js
|
||||
|
||||
def test_dashM_consistent(self):
|
||||
normal = Popen([PYTHON, EMXX, '-v', '-Wno-warn-absolute-paths', path_from_root('tests', 'hello_world.cpp'), '-c'], stdout=PIPE, stderr=PIPE).communicate()[1]
|
||||
dash_m = Popen([PYTHON, EMXX, '-v', '-Wno-warn-absolute-paths', path_from_root('tests', 'hello_world.cpp'), '-M'], stdout=PIPE, stderr=PIPE).communicate()[1]
|
||||
|
||||
import difflib
|
||||
diff = [a.rstrip()+'\n' for a in difflib.unified_diff(normal.split('\n'), dash_m.split('\n'), fromfile='normal', tofile='dash_m')]
|
||||
left_std = filter(lambda x: x.startswith('-') and '-std=' in x, diff)
|
||||
right_std = filter(lambda x: x.startswith('+') and '-std=' in x, diff)
|
||||
assert len(left_std) == len(right_std) == 1, '\n\n'.join(diff)
|
||||
bad = filter(lambda x: '-Wno-warn-absolute-paths' in x, diff)
|
||||
assert len(bad) == 0, '\n\n'.join(diff)
|
||||
|
||||
def test_dashM_respect_dashO(self):
|
||||
with_dash_o = Popen([PYTHON, EMXX, path_from_root('tests', 'hello_world.cpp'), '-M', '-o', '/dev/null'], stdout=PIPE, stderr=PIPE).communicate()[0]
|
||||
without_dash_o = Popen([PYTHON, EMXX, path_from_root('tests', 'hello_world.cpp'), '-M'], stdout=PIPE, stderr=PIPE).communicate()[0]
|
||||
assert len(with_dash_o) == 0
|
||||
assert len(without_dash_o) != 0
|
||||
|
||||
def test_malloc_implicit(self):
|
||||
open('src.cpp', 'w').write(r'''
|
||||
#include <stdlib.h>
|
||||
|
|
Загрузка…
Ссылка в новой задаче