support -o with multiple bitcode inputs in emcc
This commit is contained in:
Родитель
193a0cc9d2
Коммит
4d97e261fc
21
emcc
21
emcc
|
@ -172,6 +172,8 @@ if EMMAKEN_CFLAGS: CC_ADDITIONAL_ARGS += EMMAKEN_CFLAGS.split(' ')
|
|||
|
||||
# ---------------- Utilities ---------------
|
||||
|
||||
SOURCE_SUFFIXES = ('.c', '.cpp', '.cxx')
|
||||
|
||||
def unsuffixed(name):
|
||||
return '.'.join(name.split('.')[:-1])
|
||||
|
||||
|
@ -257,12 +259,15 @@ try:
|
|||
newargs = [ arg for arg in newargs if arg is not '' ]
|
||||
|
||||
input_files = []
|
||||
has_source_inputs = False
|
||||
for i in range(len(newargs)): # find input files XXX this a simple heuristic. we should really analyze based on a full understanding of gcc params,
|
||||
# right now we just assume that what is left contains no more |-x OPT| things
|
||||
arg = newargs[i]
|
||||
if arg.endswith(('.c', '.cpp', '.cxx', '.bc', '.o')): # we already removed -o <target>, so all these should be inputs
|
||||
if arg.endswith(SOURCE_SUFFIXES + ('.bc', '.o')): # we already removed -o <target>, so all these should be inputs
|
||||
input_files.append(arg)
|
||||
newargs[i] = ''
|
||||
if arg.endswith(SOURCE_SUFFIXES):
|
||||
has_source_inputs = True
|
||||
newargs = [ arg for arg in newargs if arg is not '' ]
|
||||
|
||||
assert len(input_files) > 0, 'emcc: no input files specified'
|
||||
|
@ -274,7 +279,10 @@ try:
|
|||
|
||||
target_basename = unsuffixed_basename(target)
|
||||
|
||||
if '-c' in newargs: # -c means do not link in gcc, and for us, the parallel is to not go all the way to JS, but stop at bitcode
|
||||
# -c means do not link in gcc, and for us, the parallel is to not go all the way to JS, but stop at bitcode
|
||||
has_dash_c = '-c' in newargs
|
||||
if has_dash_c:
|
||||
assert has_source_inputs, 'Must have source code inputs to use -c'
|
||||
target = target_basename + '.o'
|
||||
|
||||
final_suffix = target.split('.')[-1]
|
||||
|
@ -321,8 +329,13 @@ try:
|
|||
for input_file in input_files:
|
||||
shutil.move(in_temp(unsuffixed_basename(input_file) + '.o'), unsuffixed_basename(input_file) + '.' + final_suffix)
|
||||
else:
|
||||
assert len(input_files) == 1, 'fatal error: cannot specify -o with -c with multiple files'
|
||||
shutil.move(in_temp(unsuffixed_basename(input_files[0]) + '.o'), specified_target)
|
||||
if len(input_files) == 1:
|
||||
shutil.move(in_temp(unsuffixed_basename(input_files[0]) + '.o'), specified_target)
|
||||
else:
|
||||
assert not has_dash_c, 'fatal error: cannot specify -o with -c with multiple files'
|
||||
# We have a specified target (-o <target>), which is not JavaScript or HTML, and
|
||||
# we have multiple files: Link them. TODO: Pass complex linker args along
|
||||
shared.Building.link(map(lambda input_file: in_temp(unsuffixed_basename(input_file) + '.o'), input_files), specified_target)
|
||||
|
||||
exit(0)
|
||||
|
||||
|
|
|
@ -5015,6 +5015,14 @@ Options that are modified or new in %s include:
|
|||
assert os.path.exists(target), '\n'.join(output)
|
||||
self.assertContained('side got: hello from main, over', run_js(target))
|
||||
|
||||
# Combining bc files into another bc should also work
|
||||
try_delete(target)
|
||||
assert not os.path.exists(target)
|
||||
output = Popen([compiler, 'twopart_main.o', 'twopart_side.o', '-o', 'combined.bc'] + args, stdout=PIPE, stderr=PIPE).communicate()
|
||||
assert os.path.exists('combined.bc'), '\n'.join(output)
|
||||
self.assertContained('side got: hello from main, over', self.run_llvm_interpreter(['combined.bc']))
|
||||
|
||||
|
||||
# TODO: test normal project linking, static and dynamic: get_library should not need to be told what to link!
|
||||
# TODO: when ready, switch tools/shared building to use emcc over emmaken
|
||||
# TODO: when this is done, more test runner to test these (i.e., test all -Ox thoroughly)
|
||||
|
|
Загрузка…
Ссылка в новой задаче