diff options
author | Alon Zakai <alonzakai@gmail.com> | 2011-12-14 17:01:16 -0800 |
---|---|---|
committer | Alon Zakai <alonzakai@gmail.com> | 2011-12-14 17:01:16 -0800 |
commit | df41a405914e60d21262b3fb9ab81a5832bb4405 (patch) | |
tree | da6c6aa4f3682cbbb7d0675fd48ac6510dbeeba3 | |
parent | 8e7d56453f584c3be3b1aca0f642a94278afc466 (diff) |
generate .o by default, not .bc. fixes test_zlib
-rwxr-xr-x | emar | 16 | ||||
-rwxr-xr-x | emcc | 20 | ||||
-rwxr-xr-x | emld | 28 | ||||
-rw-r--r-- | tests/runner.py | 13 |
4 files changed, 55 insertions, 22 deletions
@@ -1,13 +1,21 @@ #!/usr/bin/env python ''' -emcc - ar helper script +emar - ar helper script ======================= This script acts as a frontend replacement for ar. See emcc. ''' -if set(sys.argv[1]).issubset(set('-cruqs')): # ar - sys.argv = sys.argv[:1] + sys.argv[3:] + ['-o='+sys.argv[2]] - assert use_linker, 'Linker should be used in this case' +import os, sys +from tools import shared + +DEBUG = os.environ.get('EMCC_DEBUG') + +newargs = [shared.EMLD] + sys.argv[3:] + ['-o='+sys.argv[2]] + +if DEBUG: + print >> sys.stderr, 'emar:', sys.argv, ' ==> ', newargs + +os.execvp(shared.EMLD, newargs) @@ -82,7 +82,6 @@ SAVE_FILES = os.environ.get('EMCC_SAVE_FILES') # saves some of the intermediate ################### XXX print >> sys.stderr, '\n***This is a WORK IN PROGRESS***' -print >> sys.stderr, '***[%s]***\n' % str(sys.argv) ################### XXX if DEBUG: print >> sys.stderr, 'emcc: ', ' '.join(sys.argv) @@ -150,7 +149,7 @@ CONFIGURE_CONFIG = os.environ.get('EMMAKEN_JUST_CONFIGURE') CMAKE_CONFIG = 'CMakeFiles/cmTryCompileExec.dir' in ' '.join(sys.argv)# or 'CMakeCCompilerId' in ' '.join(sys.argv) if CONFIGURE_CONFIG or CMAKE_CONFIG: compiler = 'g++' if 'CXXCompiler' in ' '.join(sys.argv) or os.environ.get('EMMAKEN_CXX') else 'gcc' - cmd = [compiler] + EMSDK_OPTS + sys.argv[1:] + cmd = [compiler] + shared.EMSDK_OPTS + sys.argv[1:] if DEBUG: print >> sys.stderr, 'emcc, just configuring: ', cmd exit(os.execvp(compiler, cmd)) @@ -266,7 +265,7 @@ if not header: 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 - target = target_basename + '.bc' + target = target_basename + '.o' final_suffix = target.split('.')[-1] @@ -295,22 +294,29 @@ if not header: if DEBUG: print >> sys.stderr, "Running:", call, ' '.join(newargs) Popen([call] + newargs + [input_file]).communicate() else: - shutil.copyfile(input_file, unsuffixed_basename(input_file) + '.o') + if input_file != unsuffixed_basename(input_file) + '.o': + shutil.copyfile(input_file, unsuffixed_basename(input_file) + '.o') # Optimize, if asked to if llvm_opt_level > 0: for input_file in input_files: shared.Building.llvm_opt(unsuffixed_basename(input_file) + '.o', 2, safe=llvm_opt_level < 2) + def careful_move(source, dest): # move a file, but just copy if it was a original input file + if source not in input_files: + shutil.move(source, dest) + else: + shutil.copyfile(source, dest) + # If we were just asked to generate bitcode, stop there if final_suffix in ['o', 'bc']: if final_suffix == 'bc': for input_file in input_files: - shutil.move(unsuffixed_basename(input_file) + '.o', unsuffixed_basename(input_file) + '.bc') + careful_move(unsuffixed_basename(input_file) + '.o', unsuffixed_basename(input_file) + '.bc') if specified_target: assert len(input_files) == 1, 'fatal error: cannot specify -o with -c with multiple files' - shutil.move(unsuffixed_basename(input_files[0]) + '.' + final_suffix, unsuffixed_basename(specified_target) + '.' + final_suffix) + careful_move(unsuffixed_basename(input_files[0]) + '.' + final_suffix, unsuffixed_basename(specified_target) + '.' + final_suffix) exit(0) @@ -320,7 +326,7 @@ if not header: if len(input_files) > 1: shared.Building.link(map(lambda input_file: unsuffixed_basename(input_file) + '.o', input_files), target_basename + '.bc') else: - shutil.move(unsuffixed_basename(input_files[0]) + '.o', target_basename + '.bc') + careful_move(unsuffixed_basename(input_files[0]) + '.o', target_basename + '.bc') # Apply -s settings in newargs here (after -Ox, so they can override it) @@ -1,19 +1,37 @@ #!/usr/bin/env python ''' -emcc - linker helper script +emld - linker helper script =========================== This script acts as a frontend replacement for the ld linker. See emcc. + +We could use the compiler code for this, but here we want to be careful to use all the linker flags we have been passed, sending them to ld. ''' +import os, sys +from tools import shared + +DEBUG = os.environ.get('EMCC_DEBUG') + +if DEBUG: + print >> sys.stderr, 'emld:', sys.argv + ALLOWED_LINK_ARGS = ['-f', '-help', '-o', '-print-after', '-print-after-all', '-print-before', '-print-before-all', '-time-passes', '-v', '-verify-dom-info', '-version' ] TWO_PART_DISALLOWED_LINK_ARGS = ['-L'] # Ignore thingsl like |-L .| -# +# Check for specified target +target = None +for i in range(len(sys.argv)-1): + if sys.argv[i].startswith('-o='): + raise Exception('Invalid syntax: do not use -o=X, use -o X') + + if sys.argv[i] == '-o': + target = sys.argv[i+1] + sys.argv = sys.argv[:i] + sys.argv[i+2:] + break -# We could use the compiler code for this, but here we want to be careful to use all the linker flags we have been passed, sending them to ld call = shared.LLVM_LD newargs = ['-disable-opt'] i = 0 @@ -37,6 +55,6 @@ if target: actual_target = unsuffixed(target) + '.bc' newargs.append('-o=' + actual_target) -if DEBUG: print >> sys.stderr, "Running:", call, ' '.join(newargs) -Popen([call] + newargs).communicate() +if DEBUG: print >> sys.stderr, "emld running:", call, ' '.join(newargs) +os.execvp(call, [call] + newargs) diff --git a/tests/runner.py b/tests/runner.py index ccca1e50..ed3c17a0 100644 --- a/tests/runner.py +++ b/tests/runner.py @@ -4872,7 +4872,8 @@ TT = %s class other(RunnerCore): def test_reminder(self): raise Exception('''Fix emmaken.py and emconfiguren.py, they should work but mention they are deprecated - Test emconfigure.''') + Test emconfigure + configure in test_zlib looks broken''') def test_emcc(self): def clear(): @@ -4912,7 +4913,7 @@ Options that are modified or new in %s include: # emcc src.cpp -c and emcc src.cpp -o src.[o|bc] ==> should give a .bc file for args in [['-c'], ['-o', 'src.o'], ['-o', 'src.bc']]: - target = args[1] if len(args) == 2 else 'hello_world.bc' + target = args[1] if len(args) == 2 else 'hello_world.o' clear() output = Popen([compiler, path_from_root('tests', 'hello_world' + suffix)] + args, stdout=PIPE, stderr=PIPE).communicate() assert len(output[0]) == 0, output[0] @@ -4998,19 +4999,19 @@ Options that are modified or new in %s include: assert 'fatal error' in output[1], output[1] continue - assert os.path.exists('twopart_main.bc'), '\n'.join(output) - assert os.path.exists('twopart_side.bc'), '\n'.join(output) + assert os.path.exists('twopart_main.o'), '\n'.join(output) + assert os.path.exists('twopart_side.o'), '\n'.join(output) assert not os.path.exists(target), 'We should only have created bitcode here: ' + '\n'.join(output) # Compiling one of them alone is expected to fail - output = Popen([compiler, 'twopart_main.bc'] + args, stdout=PIPE, stderr=PIPE).communicate() + output = Popen([compiler, 'twopart_main.o'] + args, stdout=PIPE, stderr=PIPE).communicate() assert os.path.exists(target), '\n'.join(output) #print '\n'.join(output) self.assertContained('is not a function', run_js(target, stderr=STDOUT)) try_delete(target) # Combining those bc files into js should work - output = Popen([compiler, 'twopart_main.bc', 'twopart_side.bc'] + args, stdout=PIPE, stderr=PIPE).communicate() + output = Popen([compiler, 'twopart_main.o', 'twopart_side.o'] + args, stdout=PIPE, stderr=PIPE).communicate() assert os.path.exists(target), '\n'.join(output) self.assertContained('side got: hello from main, over', run_js(target)) |